05.12.2022, 07:51
port:read(17) is a blocking read. It won't return until 17 bytes are read.
For one-way communication you can use UDP for data transport between scripts:
Send commands like this:
For one-way communication you can use UDP for data transport between scripts:
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(1)
port:write(':RR\r\n')
end
Send commands like this:
Code:
data = '123456'
sock = require('socket').udp()
sock:sendto(data, '127.0.0.1', 5485)
sock:close()