22.04.2020, 15:30
(22.04.2020, 14:55)admin Wrote: Event script mapped to binary on/off object:
Result and any errors will be visible in Logs tab. You can remove log() calls if everything is working correctly.Code:value = event.getvalue() and 1 or 0
sock = require('socket').tcp()
cmd = '%1POWR ' .. value .. '\r'
sock:settimeout(1)
res, err = sock:connect('192.168.1.98', 4352)
if res then
res, err = sock:receive(9)
if res and res == 'PJLINK 0\r' then
sock:send(cmd)
res, err = sock:receive(10)
log('receive reply', res, err)
else
log('receive init failed', res, err)
end
else
log('connect failed', err)
end
sock:close()
Thank you Admin. I will try tomorrow.
If I need to send the command ON only when the object has a value 1 (True) then OFF using an other object with value 1 (TRUE) then the code will be like?:
Code:
value = event.getvalue()
sock = require('socket').tcp()
cmd = '%1POWR 1\r' --OR '%1POWR 0\r' for OFF
sock:settimeout(1)
res, err = sock:connect('192.168.1.98', 4352)
if value and res then
res, err = sock:receive(9)
if res and res == 'PJLINK 0\r' then
sock:send(cmd)
res, err = sock:receive(10)
log('receive reply', res, err)
else
log('receive init failed', res, err)
end
else
log('connect failed', err)
end
sock:close()