Cloud-Automation / node-modbus

Modbus TCP Client/Server implementation for Node.JS
471 stars 175 forks source link

Serial doesn't work in my case #54

Closed biancode closed 7 years ago

biancode commented 8 years ago

Hi,

you have some handling of PDU for TCP but not for Serial. Result of testing ModbusRTU and ASCII: serial doesn't work in my case

The handling with endian isn't ready: there is just ...BE for BIG-Endian in use and there is now way to use the ..LE for Little-Endian

Serial connection type is just RTU? could be ASCII or RTU

ASCII needs a SerialPort parser with line ending '\r\n' or 0x0d 0x0a or (10,13)LE / (13,10)BE

Serial doesn't work for PDU's with UnitID and/or split of PDU:

DEBUG : received data PDU: {"type":"Buffer","data":[1,3,2,0]} DEBUG : received data PDU: {"type":"Buffer","data":[54,56,82]}

Serial-Source: 1,3,2,0,54,56,82 UnitID: 1 FC: 3 16BitBlocksToRead: 2 16BitBlock1-readLE: payload -> 54 16BitBlock2-readLE: CRC

[1,3,2,0] and [54,56,82] should be: [1,3,2,0,54,56,82] [1] and [3,2,0,54,56,82] should be: [1,3,2,0,54,56,82] [1] and [3,2,0,54] and [56,82] should be: [1,3,2,0,54,56,82] [1,3,2] and [0,54] and [56,82] should be: [1,3,2,0,54,56,82] [1,3,2,0,54,56] and [82] should be: [1,3,2,0,54,56,82]

UnitID (1), FC (1), ByteCount, Value (2), CRC (2)

If the serial raise often an exception on read:

2 Oct 22:38:37 - [red] Uncaught Exception: 2 Oct 22:38:37 - RangeError: index out of range -> ReadHoldingRegisters.js - Line 20

stefanpoeter commented 8 years ago

Sounds to me like a feature request to switch litte/big. I will see to it in the next version.

SuperJojo2001 commented 8 years ago

As far as I see the implementation today just Modbus RTU is supported only. ASCII I see nowhere coded. Next to 0x0d 0x0a at the end of an ASCII frame it needs also a semikolon (':', 0x3A) at the start of the frame. We should get Modbus RTU working fine first, then we can add ASCII as well. After issuing pull request #56 Modbus RTU works fine with me now. @biancode Wondering how you receive PDU data correctly without #56?

biancode commented 8 years ago

@SuperJojo2001 I fixed some in my repo branch https://github.com/biancode/node-modbus-1, but didn't do any pull request for now. Testing isn't finished.