morkai / h5.modbus

Implementation of the MODBUS IP/ASCII/RTU master and slave over TCP/UDP/Serial for Node.js.
https://miracle.systems/p/h5.modbus
MIT License
28 stars 21 forks source link

RTU over TCP #14

Closed goranach closed 7 years ago

goranach commented 7 years ago

I want to use RTU over TCP, but thare are coalescing packets. It may be 2 or 3 packets in receive buffer in RTUtransport. Can you help me, please?

morkai commented 7 years ago

For RTU, make sure the Master.maxConcurrentTransactions option is set to 1.

If the device sends the response in chunks it will be reassembled by the RtuTransport.

Everytime the RtuTransport receives data from the Connection a timer is started with delay equal to the RtuTransport.eofTimeout option (End Of Frame). The response handling is invoked once the timer fires. For example, the slave:

  1. sends byte A,
  2. waits 30ms,
  3. sends byte B,
  4. waits 30ms,
  5. sends byte C.

To properly handle that frame, the eofTimeout option must be set to 30ms + time to travel through the cable. If the eofTimeout is set to 50ms, the RtuRansport will:

  1. receive byte A and start the 50ms timer,
  2. receive byte B after ~30ms and restart the 50ms timer,
  3. receive byte C after ~30ms and restart the 50ms timer,
  4. wait 50ms... no more data...
  5. reassemble the frame and handle the response.
goranach commented 7 years ago

Thanks!