02.03.2020, 16:00
Here's a short example script that can be used to poll slave nr 2. It does not send ack/nack and does not parse the message but can be used a starting point to check the communication. Change serial port name and parameters as needed.
Code:
EOT = string.char(4)
ENQ = string.char(5)
function poll(addr)
port:flush()
port:write(addr .. ENQ)
local buf = {}
while true do
local ch, err = port:read(1, 1)
if ch then
if ch == EOT then
break
else
buf[ #buf + 1 ] = ch
end
else
return nil, err
end
end
return table.concat(buf)
end
port = require('serial').open('/dev/RS232', { baudrate = 9600 })
res, err = poll(2)
loghex(res, err)