04.02.2026, 09:33
Attach an event script to a 4-bit object. A different command is sent depending on the input value (stop, up or down).
Code:
value = event.getvalue()
up = bit.band(value, 8) ~= 0
stop = bit.band(value, 7) == 0
if stop then
command = string.char(0x55, 0x01, 0x01, 0x03, 0x03, 0x38, 0xC1)
elseif up then
command = string.char(0x55, 0x01, 0x01, 0x03, 0x02, 0xF9, 0x01)
else
command = string.char(0x55, 0x01, 0x01, 0x03, 0x01, 0xB9, 0x00)
end
require('serial')
port = serial.open('/dev/RS485-1', {
baudrate = 9600,
parity = 'even',
duplex = 'half'
})
port:write(command)