node-modbus icon indicating copy to clipboard operation
node-modbus copied to clipboard

ModbusRTUClientRequestHandler "close" event

Open kollerDominik opened this issue 3 years ago • 6 comments

Hi, the ModbusTCPClientReqeuestHandler listens for the "close" event of the socket in the constructor and binds the _onClose method: this._socket.on('close', this._onClose.bind(this)) Is there a special reason why this is not the case in the ModbusRTUClientRequestHandler? Because what I'm currently experiencing is that I just get a request timeout error if the serial connection is closed and if the serial connection is reconnected I sometimes still receive request timeout errors before the requests are finished successfully again. If the same line as for the ModbusTCPClientRequestHandler is added, errors like "OutOfSync" or "Offline" are shown (which should be fine) and the requests are successful nearly immediately after the serial connection is restablished. But maybe I'm overlooking something important, so therefore I would ask for some clarification. Thanks.

kollerDominik avatar Mar 26 '21 08:03 kollerDominik

Actually I am not sure why there is no link to the close event on the serialport module. I remember that there was no close event when I implemented that but I am not sure. Just checked the serialport API and there is actually a close event. Does anyone know if the open/close state on an RTU connection is more that an internal state on the serialport module? @alexbuczynsky maybe?

stefanpoeter avatar Mar 26 '21 10:03 stefanpoeter

Hi, is there something new on that issue @stefanpoeter @alexbuczynsky?

kollerDominik avatar May 17 '21 07:05 kollerDominik

Based on the API docs here: https://serialport.io/docs/7.x.x/api-stream#close

The close event is emitted when the port is closed. In the case of a disconnect, it will be called with a Disconnect Error object (err.disconnected == true). In the event of an error while closing (unlikely), an error event is triggered.

alexbuczynsky avatar Jun 21 '21 18:06 alexbuczynsky

@stefanpoeter @alexbuczynsky so there should be a link to the close event?

kollerDominik avatar Jun 22 '21 15:06 kollerDominik

@kollerDominik sorry for the late reply. Do you care about handling this in a pull request?

stefanpoeter avatar Jan 13 '22 13:01 stefanpoeter

Yes we could handle this in a pull request

kollerDominik avatar Feb 08 '22 16:02 kollerDominik