Posts: 7763
Threads: 42
Joined: Jun 2015
Reputation:
447
If using Modbus profiles there's a built-in device status object functionality. Otherwise in your script you can use os.time() to store the last device response time and compare it with current time. Or just count the number of failed poll requests. This has to be done inside the script that is doing the RS485 communication.
Posts: 87
Threads: 29
Joined: Feb 2022
Reputation:
0
Thank you admin! This time the system is not Modbus, it is RS485 ASCII. so I will use os.time() to store the last device responce and compare it with current time in resident script .
I would also like to have your suggestion about what timeout I should use in the
port:read(bytes, timeout) method.
The condition is, as I wrote in the first thread,
>When sending command from LM to the other device, the other device is suppose to give LM a respond in at most 3 seconds.
> However if the device does not give any responce in 5 min, I need to consider that as an error and indicate an alert.
I am sorry, maybe it's a basic questions but I appreciate if you could help (:
This is the code I have.
```
if not port then
require('serial')
port = serial.open('/dev/RS485-1', {
baudrate = 19200,
databits = 8,
stopbits = 1,
parity = 'none',
duplex = 'half'
})
end
port:flush()
res, err = port:read(27, 3)
--example res = ":00010001130077770010AB"
t = split(res, ":")
for k,v in pairs(t) do
~~
end
```
Posts: 87
Threads: 29
Joined: Feb 2022
Reputation:
0
Thank you !
Yes as you saild, my script will result in an error if there's no response from the port ....(:
If I put your code in a resident script with interval 0, how often does the errors count up?
The count starts every time I try to write to the port?
Posts: 7763
Threads: 42
Joined: Jun 2015
Reputation:
447
Is the device constantly sending data or do you need to poll for it? For polling you should not use 0 sleep time. If you increase the sleep time then the number of errors for the alert should be adjusted accordingly. If the device doesn't respond then each cycle time = sleep time + timeout value. If you poll every 2 seconds with 3 second timeout then the whole cycle is 5 seconds. Then the counter value of 60 equals 5 minutes.