15.02.2021, 08:13
Connect RS485-2 and RS485-3 A/B wires together and run this self test script. It will tell whether the port is working correctly or not:
Code:
require('serial')
port1 = serial.open('/dev/RS485-2', { duplex = 'half' })
port2 = serial.open('/dev/RS485-3', { duplex = 'half' })
str = '1234567890'
ok = true
function test(p1, p2)
p1:flush()
p2:flush()
for i = 1, 100 do
p1:write(str)
local res = p2:read(#str, 1)
ok = ok and res == str
if not ok then
break
end
end
end
test(port2, port1)
test(port1, port2)
alert('RS485 self test ' .. (ok and 'OK' or 'ERROR'))