Cloud-Automation / node-modbus

Modbus TCP Client/Server implementation for Node.JS
465 stars 174 forks source link

not enough data available #211

Closed nathanbussey closed 6 years ago

nathanbussey commented 6 years ago

when I call client.WriteSingleRegister(), it fails the second time that tcp-response.js calls fromBuffer. It works fine the first time, but the second time it generates a RangeError in checkOffset of buffer.js.

I can't figure out why it's calling fromBuffer twice, but it succeeds fine the first time.

stefanpoeter commented 6 years ago

Do you have some code for me to look at?

nathanbussey commented 6 years ago

Your test code exercises this issue. And I don't think it's specifically an issue, but most of the calls seem to be returning null because they are calling that fromBuffer twice. I added in console logs in tcp-response.js so I could see when it was happening. and it happens a lot in the test, but I think it's as intended.

I installed v3.1.0-dev and I was able to write single register and read single register. So I think I'm doing pretty well now.

nathanbussey commented 6 years ago

I'm able to write 0x1234 to address 10 okay, but I'm having trouble writing to high addresses. Is WriteSingleRegister limited? I would have expected to be able to use between 0 and 0x270E.

Sorry, let me be more clear. I try to write to address 40001 and it fails. http://www.simplymodbus.ca/FAQ.htm This site seems to indicate ranges for different types, but not of it seems to match with what I'm experiencing where i can write to address 10 but not 40001 or even 9995

stefanpoeter commented 6 years ago

What server do you use? Modbus uses a full 16bit address space. If you use the SimpleServer Example then initiate the server with a bigger buffer.

nathanbussey commented 6 years ago

I set the alloc to 20000 and it allowed me to use up to 270E as expected, if I'm treating that space correctly.

Thanks for the help.