Unable to reset Modbus Status variable using Python

Moderator: RevPiModIO

Post Reply
in06khattab
Posts: 44
Joined: 24 Jan 2024, 19:07

Unable to reset Modbus Status variable using Python

Post by in06khattab »

Hi,

I noticed I was getting a Status code of 110 on some of the Modbus values. This means a timeout according to this link: https://revolutionpi.com/tutorials/modb ... r-turorial
Currently the action interval is set to 1000ms.

I tried to do this to reset the code:
rpi.io["FAN_P_STATUS_RESET"].value = True

But it does not change.
I have been able to reset the code using piTest with
piTest -w FAN_P_STATUS_RESET,1

Status byte is read back with:
piTest -r FAN_P_STATUS

I have two questions:
1. How do I sort out the Python issue of not being able to reset the Status byte?
2. Any advice on sorting out this timeout?
The hardware it is timing out with is this: https://cdn.shopify.com/s/files/1/0558/ ... 1659968620
They suggest a max of 60ms timeout.
2024-01-26_15-39.png
User avatar
RevPiModIO
KUNBUS
Posts: 325
Joined: 20 Jan 2017, 08:44
Contact:

Re: Unable to reset Modbus Status variable using Python

Post by RevPiModIO »

Hi

You can reset the status code within your Python Program with rpi.io["FAN_P_STATUS_RESET"].value = True. The thing is, you have to hold the value on True and reset it to False after the status code changed to 0.
Make sure, that you use autorefresh=True than you have to wait alt least the cycle time before reset it to False.

The problem here is that Python always keeps the value of an output on the value set in Python. Since the subsystem of Modbus itself sets the output to False, Python does not notice this and would immediately set it back to True. The control program (Python) always ensures that the values that were set in the program are also set in the process image.

You can disable this by adding shared_procimg=True in your RevPiModIO(autorefresh=True, shared_procimg=True) call. But you have to remember, that autorefresh will sync the process image every 20 ms. So a script like

rpi.io["FAN_P_STATUS_RESET"].value = True
rpi.io["FAN_P_STATUS_RESET"].value = False

will fail most times.

Best practice is to set rpi.io["FAN_P_STATUS_RESET"].value = True and wait until the FAN_P_STATUS changed and set FAN_P_STATUS_RESET = False.
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
in06khattab
Posts: 44
Joined: 24 Jan 2024, 19:07

Re: Unable to reset Modbus Status variable using Python

Post by in06khattab »

Thank you very much. Understanding how to reset the variable in Python has fixed the issue.
Increasing the action timeout to 2200ms has fixed the timeout issue which makes the rtu minimal time to be greater than 60ms. This forum post has helped: viewtopic.php?t=943
Post Reply