morkai/h5.modbus

Handling Loss of Connection (Serial)

Closed this issue · 1 comments

I'm having some trouble handling errors from disconnecting to the slave. I seem to have code working for modbus tcp error catching. For example I am using the master.on('error',...) and it seems to be working just fine as well as transaction errors or timeouts. I am only doing reads, and when the error is thrown a custom function is called to stop all scanning; it works well.

Then I tried out serial modbus rtu connection to '/dev/ttyACM0'. Everything works perfectly except for a hard disconnect when pulling the usb cable. The error is "thrown" (err message is "Error Input/Output error calling write()") and the function I created is called to stop scanning. Except that it is called many times (30+ rapidly) and crashes with "Segmentation Fault".

So I looked up segmentation fault and it said it has to do with improper memory writing. My guess is that the device /dev/ttyACM0 no longer exists and the memory associated with it is gone. However h5 modbus might be still trying to write to it causing these errors? Is there anything within this package that when the slave (serial) is disconnected or loss of connection that all communication is stopped and a callback is available.

EDIT:
Hmm.... might have to do with node serialport: serialport/node-serialport#302

Okay, looks like its the version of node-serial port. I think they fixed it in 1.4 something, but I'm using 1.3.1 for compatibility reasons.

Thanks!!

Yep, it's not h5.modbus. The SerialConnection only calls node-serialport's write() and doesn't know what happens under the hood.

Whether I had to use a slave with only a serial connection, I ended up using something like Moxa NPort (hardware solution) or serproxy (software solution). Then, instead of using the SerialConnection, I'd use the TcpConnection with RtuTransport or AsciiTransport.