plcpeople / nodepccc

Library for node.js to communicate with some Allen-Bradley programmable controllers (PLCs)
MIT License
81 stars 24 forks source link

CompactLogicx issue when write array #8

Closed meron1122 closed 7 years ago

meron1122 commented 8 years ago

Array 3 items

conn.initiateConnection({port: 44818, host: '192.168.1.10' , routing: [0x01 ,0x00,0x01,0x00 ]}, connected);
//works fine
conn.writeItems('N7:0', [66], valuesWritten);  // You can write a single array item too.
//this works fine too
conn.writeItems('N7:1,2', [256,44], valuesWritten);  
//but this throw error
 conn.writeItems('N7:0,1,2', [15,66,26], valuesWritten);

All log

[17229,512552929] Initiate Called - Connecting to PLC with address and parameters:
[17229,514342543] { port: 44818, host: '192.168.1.10', routing: [ 1, 0, 1, 0 ] }
[17229,516549778] Connection cleanup is happening
[17229,517895964 192.168.1.10] Attempting to connect to host...
[17229,520609974 192.168.1.10] TCP Connection Established to 192.168.1.10 on port 44818 - Will attempt EIP Connection
[17229,526448776 192.168.1.10] EIP Register Session Response Received - connection confirmed
[17229,527033550 192.168.1.10] Session Handle is 0xF024D00
[17229,527443668 192.168.1.10] Preparing to WRITE N7:0,1,2

buffer.js:784
    throw TypeError('value is out of bounds');
          ^
TypeError: value is out of bounds
    at TypeError (<anonymous>)
    at checkInt (buffer.js:784:11)
    at Buffer.writeInt16LE (buffer.js:900:5)
    at bufferizePCCCItem (/media/mer/sshd/Projekty/RFID/src/node_modules/nodepccc/nodePCCC.js:1841:25)
    at NodePCCC.prepareWritePacket (/media/mer/sshd/Projekty/RFID/src/node_modules/nodepccc/nodePCCC.js:542:3)
    at NodePCCC.writeItems (/media/mer/sshd/Projekty/RFID/src/node_modules/nodepccc/nodePCCC.js:328:7)
    at NodePCCC.connected [as connectCallback] (/media/mer/sshd/Projekty/RFID/src/bradleyTest/test.js:24:10)
    at NodePCCC.onEIPConnectReply (/media/mer/sshd/Projekty/RFID/src/node_modules/nodepccc/nodePCCC.js:280:8)
    at Socket.<anonymous> (/media/mer/sshd/Projekty/RFID/src/node_modules/nodepccc/nodePCCC.js:225:26)
    at Socket.EventEmitter.emit (events.js:95:17)

This looks like register 0 is not accessible via write array. Am I doing something wrong?

plcpeople commented 8 years ago

I think it is just the syntax you are using, and I will leave the issue open as it should have logged an error instead of crashing, and I will fix that eventually, but..

If you want to write an array of 3 integers starting at N7:0, try writing using: ... conn.writeItems('N7:0,3', [15,66,26], valuesWritten); ...

N7:0 is the start address and 3 is the array length. You don't need to specify the middle elements. Just like a much longer array would be N7:0,100.

Please try this and let me know.

plcpeople commented 7 years ago

I am closing as I believe this works.