Dear admin,
I am running the code in the site, and I want to add 2 features....could you tell me how I do these?
1. Is there a way to execute port:write(':RR\r\n') every 60 sec even if port:read(17) does not return anything? As you said before, port:read(17) is blocking the script. If there's no response from the slave, the script is not going to be executed anymore
2. I want to alart the system admin if there's no response from the slave(port:read(17)) for 5 min....can I do that in this script?
I am running the code in the site, and I want to add 2 features....could you tell me how I do these?
1. Is there a way to execute port:write(':RR\r\n') every 60 sec even if port:read(17) does not return anything? As you said before, port:read(17) is blocking the script. If there's no response from the slave, the script is not going to be executed anymore
2. I want to alart the system admin if there's no response from the slave(port:read(17)) for 5 min....can I do that in this script?
Code:
if not server then
require('socket')
server = socket.udp()
server:setsockname('127.0.0.1', 5485)
server:settimeout(60)
end
if not port then
require('serial')
port = serial.open('/dev/RS485-1', {
baudrate = 19200,
databits = 8,
stopbits = 1,
parity = 'none',
duplex = 'half'
})
end
data = server:receive()
if data then
port:write(data)
os.sleep(0.5)
end
port:flush()
port:write(':RR\r\n')
data, err = port:read(17, 1) -- read 17 bytes for up to 1 second
if data and #data == 17 then
-- parse data response here
end