This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

RS485 alarm if the other device does not respond in certain time
Hello  Smile

We are going to control a device with LM RS485.
LM is the master and the other device is the slave.

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.

Is it possible to do such thing (keep observing the signal for 5 min) in resident script or event script?

Thank you for your help in advance!
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.
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
port ='/dev/RS485-1', {
baudrate = 19200,
databits = 8,
stopbits = 1,
parity = 'none',
duplex = 'half'

res, err = port:read(27, 3)

--example res = ":00010001130077770010AB"
t = split(res, ":")

for k,v in pairs(t) do
You don't even need to store the time, you can simply count the number of times the device did not reply. Check the res variable contents because it will be nil on error and trying to manipulate res as a string will result in a script error.

res, err = port:read(27, 3)
if res then
  errors = 0
  -- parse res contents
  errors = (errors or 0) + 1
  if errors == 100 then
    alert('device read timeout')
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?
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.

Forum Jump: