10.06.2019, 07:12
here is the script for RS485 self-test with either OK or ERROR message in Alerts.
Make sure to adjust port names accordingly (2nd, 3rd lines):
Make sure to adjust port names accordingly (2nd, 3rd lines):
Code:
require('serial')
port1 = serial.open('/dev/RS485-1', { duplex = 'half' })
port2 = serial.open('/dev/RS485-2', { duplex = 'half' })
function test(p1, p2)
errors = 0
p1:flush()
p2:flush()
for i = 1, 100 do
p1:write('1234567890')
res = p2:read(10, 1)
if res and res == '1234567890' then
res = '+'
else
res = '-'
errors = errors + 1
if errors > 5 then
break
end
end
io.write(res)
io.flush()
if i % 50 == 0 then
print()
end
end
end
test(port2, port1)
test(port1, port2)
alert(errors > 0 and 'ERROR' or 'OK')