Page 1 of 1
Modbus Error Variable
Posted: 08 Jul 2020, 14:15
by plima
I am trying to detect a communication failure in a Modbus TCP Master and I am having some issues.
When I reset the driver with the Modbus Slave disconnected, the Modbus_Master_Status has a '255' value, after I start the slave it changes to '0', this is ok but if I disconnect the slave again, the value never changes, it is always '0'.
Is this a bug or should I do something to make this working?
Re: Modbus Error Variable
Posted: 10 Jul 2020, 10:52
by Amar
Modbus_Master_Status does not provide slave communication status.Communication failure in a Modbus TCP Master with corresponding Slaves can be checked with corresponding Modbus_Action_Status_[1… 32] registers.The error codes correspond to the Modbus exception codes as specified in the Modbus specification.The Modbus master can handle up to 32 tasks. For each task there is a register for status and status reset. If an error occurs in a task, the error code is written to the Modbus register “Modbus_Action_Status_[1… 32]”.The error stays in this register until the value “1” is written manually into the Modbus register “Action_Status_Reset_[1… 32]”.
Re: Modbus Error Variable
Posted: 10 Jul 2020, 12:37
by plima
According to Modbus master documentation the "Modbus_Master_Status" should provide the communication status.
quote:
"If a communication error occurs, the error code is written to the Modbus register "Modbus_Master_Status"."
However, even using the "Modbus_Action_Status" I have some problems, after I reset the status, how can I know that the connection is re-established?
I need to know, if the values that I am trying to collect are valid at all times, when the connection is lost I need to set an invalid status and reset it when the connection is established, how can I do this?
Re: Modbus Error Variable
Posted: 13 Jul 2020, 11:39
by Amar
Thank you for the Quote.There is some unclarity in documentation for Modbus_Master_Status which is related to internal errors associated with master.
After you reset with Action_Status_Reset you monitor Modbus_Action_Status again.Modbus error codes (eg 110 CONNECTION TIMED OUT ) are written in this register.Modbus_Action_Status with value 0 also means that communication is established and received data is error free.
More detailed Modbus application logs can be found in system log:
tail -f /var/log/daemon.log
Re: Modbus Error Variable
Posted: 15 Jul 2020, 21:02
by plima
Thank you Amar, I think that's ok, it works for what I want.
Just a little problem, the failure detection is too slow, I have an Action Interval of 1000ms and the failure is only detected after 2 minutes.
Is there a configuration to increase the speed of the failure detection?
Re: Modbus Error Variable
Posted: 21 Jul 2020, 15:51
by Amar
Hi Plima,
The issue occurs for Modbus error CONNECTION RESET BY PEER (Error Code: 104) when the slave connection is abruptly closed.
You will have to try out with our latest Stretch 06/2020 Image.It uses libmodbus 3.1.6 (instead of 3.0.6) .
Download link for Image:
https://revolution.kunbus.de/shop/en/stretch
The issue does not occur in this image which uses newer piModbusMaster (with libmodbus 3.1.6 ).
The error entry will be quickly noticed in system log too.
tail -f /var/log/daemon.log
piModbusMaster[1800]: Modbus TCP action IP: 192.168.168.89, Port: 502 function: 0x06, address: 1 failed -1/104
Also note, if 'n' modbus actions are used i.e Modbus_Action_Status_1 to Modbus_Action_Status_n then
one of them will be set to MODBUS error code: 104 (CONNECTION RESET BY PEER) .This is the precisely the action where the error appeared.So basically you will have to monitor all those 'n' Modbus action status register's inorder to catch this error.
Regards,
Amar