node-drivers
A layered approach to protocol drivers.
Install
npm install node-drivers
Examples
const { TCP, CIP } = require('node-drivers');
const tcpLayer = new TCP('1.2.3.4');
const logix5000 = new CIP.Logix5000(tcpLayer);
console.log(await logix5000.readTag('tagname'));
console.log(await logix5000.readTag('TagThatIs1DArray[0]'));
console.log(await logix5000.readTag('TagThatIs1DArray'));
console.log(await logix5000.readTag('TagThatIs1DArray', 4))
console.log(await logix5000.readTag('TagThatIs1DArray[3]', 5));
console.log(await logix5000.readTag('tag.member[0].anothermember'));
console.log(await logix5000.readTag('TheProgramName'));
console.log(await logix5000.readTag('TheProgramName.tag'));
console.log(await logix5000.readTag(2130));
for await (const tag of logix5000.listTags()) {
console.log(tag);
}
for await (const tag of logix5000.listTags('Program:Alarms')) {
console.log(tag);
}
await tcpLayer.close();
Read/Write a tag from a PLC-5, SLC 5/03, or SLC 5/04 processor using PCCC embedded in CIP:
const { TCP, CIP, PCCC } = require('node-drivers');
const tcpLayer = new TCP('1.2.3.4');
const cipLayer = new CIP(tcpLayer);
const pccc = new PCCC(cipLayer);
console.log(await pccc.typedWrite('N10:47', 1000));
console.log(await pccc.typedRead('N10:47'));
console.log(await pccc.typedWrite('F8:1', 5.5));
await tcpLayer.close();
Find all EtherNet/IP devices in a subnet using the UDP broadcast address or by explicitly pinging each host:
const { UDP, CIP } = require('node-drivers');
const udpLayer = new UDP('1.2.3.255');
const eipLayer = new CIP.EIP(udpLayer);
console.log(await eipLayer.listIdentity());
const hosts = [];
for (let i = 1; i < 255; i++) {
hosts.push(`1.2.3.${i}`);
}
console.log(await eipLayer.listIdentity({ hosts }));
await udpLayer.close();
const { TCP, CIP } = require('node-drivers');
const tcpLayer = new TCP('1.2.3.4');
const eipLayer = new CIP.EIP(tcpLayer);
console.log(await eipLayer.listInterfaces());
console.log(await eipLayer.listServices());
await eipLayer.nop();
await tcpLayer.close();
Communicate with a Modbus device over TCP:
const { TCP, Modbus } = require('node-drivers');
const tcpLayer = new TCP('1.2.3.4');
const modbusLayer = new Modbus(tcpLayer);
console.log(await modbusLayer.readHoldingRegisters(3, 1));
await tcpLayer.close();
Drivers/Protocols
评论