A layered approach to protocol drivers.
npm install node-driversconst{TCP,CIP}=require('node-drivers');consttcpLayer=newTCP('1.2.3.4');constlogix5000=newCIP.Logix5000(tcpLayer);console.log(awaitlogix5000.readTag('tagname'));/** Read an element from a 1-dimensional tag */console.log(awaitlogix5000.readTag('TagThatIs1DArray[0]'));/** Read an entire 1-dimensional tag */console.log(awaitlogix5000.readTag('TagThatIs1DArray'));/** Read the first 4 elements of a 1-dimensional tag */console.log(awaitlogix5000.readTag('TagThatIs1DArray',4))/** * Read a slice of a 1-dimensional tag * example returns an array containing the values of elements 3 through 7 */console.log(awaitlogix5000.readTag('TagThatIs1DArray[3]',5));/** Read an element of a structure member of a tag */console.log(awaitlogix5000.readTag('tag.member[0].anothermember'));/** * Read all tags scoped to a program * returns an object containing all of the scoped tags */console.log(awaitlogix5000.readTag('TheProgramName'));/** Read a program scoped tag */console.log(awaitlogix5000.readTag('TheProgramName.tag'));/** * Read a tag using the symbol instance id * (available in controller version 21 and above) */console.log(awaitlogix5000.readTag(2130));/** List all global tags */forawait(consttagoflogix5000.listTags()){console.log(tag);}/** List all tags scoped to a program */forawait(consttagoflogix5000.listTags('Program:Alarms')){console.log(tag);}awaittcpLayer.close();const{TCP,CIP,PCCC}=require('node-drivers');consttcpLayer=newTCP('1.2.3.4');constcipLayer=newCIP(tcpLayer);constpccc=newPCCC(cipLayer);/** Write an integer */console.log(awaitpccc.typedWrite('N10:47',1000));/** Read an integer */console.log(awaitpccc.typedRead('N10:47'));/** Write a float */console.log(awaitpccc.typedWrite('F8:1',5.5));awaittcpLayer.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');constudpLayer=newUDP('1.2.3.255');consteipLayer=newCIP.EIP(udpLayer);/** Broadcast */console.log(awaiteipLayer.listIdentity());/** Explicitly */consthosts=[];for(leti=1;i<255;i++){hosts.push(`1.2.3.${i}`);}/* hosts overrides whatever host was specified in the Layers.UDP() constructor */console.log(awaiteipLayer.listIdentity({ hosts }));awaitudpLayer.close();const{TCP,CIP}=require('node-drivers');consttcpLayer=newTCP('1.2.3.4');consteipLayer=newCIP.EIP(tcpLayer);console.log(awaiteipLayer.listInterfaces());console.log(awaiteipLayer.listServices());/** no response, used to test underlying transport layer */awaiteipLayer.nop();awaittcpLayer.close();const{TCP, Modbus }=require('node-drivers');consttcpLayer=newTCP('1.2.3.4');constmodbusLayer=newModbus(tcpLayer);// read holding register 40004console.log(awaitmodbusLayer.readHoldingRegisters(3,1));awaittcpLayer.close();- CIP
- EtherNet/IP
- Logix5000
- PCCC
- embedded in CIP
- Modbus
- TCP frame format
- TCP
- UDP