21.06.2022, 07:03
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
```
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
```