23.05.2018, 08:35
Resident script, sleep time = 0. Might require some change to work with C-BUS objects.
Code:
if not client then
ip = '192.168.2.43'
mapping = { '1/1/1', '1/1/2', '1/1/3', '2/1/1', '2/1/2', '2/1/3' }
universe = 1
physical = 0
udpsock = require('socket').udp()
addrtoid = {}
values = {}
for id, addr in ipairs(mapping) do
obj = grp.find(addr)
addrtoid[ addr ] = id
if obj then
value = obj.value or 0
if obj.datatype == dt.scale then
value = math.floor(value * 2.55)
end
else
value = 0
end
values[ id ] = value
end
function send()
local cmd = string.char(
-- null byte; ARTNET_DMX opcope; protocol version 14, sequence not defined
0, 0, 0x50, 0, 14, 0,
-- physical input port from which DMX512 data was input
bit.band(physical, 0xFF),
-- 15 bit Port-Address (universe)
bit.band(universe, 0xFF), bit.rshift(universe, 8),
-- Length
bit.rshift(#values, 8), bit.band(#values, 0xFF)
)
local req = 'Art-Net' .. cmd .. string.char(unpack(values))
udpsock:sendto(req, ip, 0x1936)
end
function eventhandler(event)
local id = addrtoid[ event.dst ]
if id then
values[ id ] = busdatatype.decode(event.datahex, dt.uint8, event.dstraw)
send()
end
end
client = require('localbus').new()
client:sethandler('groupwrite', eventhandler)
send()
end
client:step()