23.09.2016, 06:47
Resident script with sleep time 0, which send whatever data comes from clients and waits for 0.5 sec after each send.
Functiont to send data from event scripts.
Code:
if not server then
-- local UDP server on port 5432
server = require('socket').udp()
server:settimeout(1)
server:setsockname('127.0.0.1', 5432)
-- serial connection
port = require('serial').open('/dev/RS485', {
baudrate = 4800,
parity = 'odd',
duplex = 'half',
databits = 8,
stopbits = 1
})
end
cmd = server:receive()
if cmd then
port:write(cmd)
os.sleep(0.5)
end
Functiont to send data from event scripts.
Code:
function send(cmd)
require('socket').udp():sendto(cmd, '127.0.0.1', 5432)
end