13.12.2019, 14:08
Hi
In case somebody want to use script to control canX DALI here are examples.
In case somebody want to use script to control canX DALI here are examples.
Code:
canxdali = require('applibs.canxdali')
canxdali.sendcmds(req)
Sends single or multiple DALI commands to the given gateway.
Returns number of bytes sent or nil plus error message.
This is completely asynchronous function, it adds commands
to gateway queue without waiting for returned results.
req table:
lineid - gateway line ID (number, required)
nodeid - gateway node ID (number, required)
command table:
cmd - command name (string, required)
value - command value (number, required for commands with a value)
address - DALI address (string or number, required)
addrtype - address type (string, required if address is a number)
address format:
address can be a string with following format:
s0..s63 - short address, from 0 to 63
g0..g15 - group, from 0 to 15
b - broadcast
if address is a number then addrtype is required, it can be either:
short
group
broadcast
Examples:
Send arc with value 0 to DALI short address 15 using gateway 0.1:
canxdali = require('applibs.canxdali')
canxdali.sendcmds({
lineid = 0,
nodeid = 1,
cmd = 'arc',
address = 's15',
value = 0,
})
Send multiple arc commands using gateway 1.42:
canxdali = require('applibs.canxdali')
canxdali.sendcmds({
lineid = 1,
nodeid = 42,
cmds = {
{ cmd = 'arc', address = 's0', value = 50 },
{ cmd = 'arc', address = 's4', value = 10 },
}
})
canxdali.syncsendcmds(req)
Similar to canxdali.sendcmds but waits for each command to complete.
On success returns Lua table with each command result, nil plus error
message otherwise.
canxdali.sendqueries(req)
Similar to canxdali.syncsendcmds but checks for each command result,
returns a table of values only for query type commands when all
commands were successful. Useful for querying DALI device statuses.
canxdali.sethandler(type, fn)
Sets a callback to execute on a specific event.
Callback is executed for each command inside data frame separately.
type - event type (string, required):
bus - all commands coming from bus side
busdata - only "bus data" type commands (from other master devices)
all - all commands coming to/from bus
fn - function to execute, or nil to remove callback (function or nil, required)
canxdali.step()
Waits for a frame or timeout, whichever happens first.
Returns frame or nil plus error message on timeout.
Frame can contain multiple commands when sent to bus.
Example (resident script):
if not canxdali then
function callback(frame)
log(frame)
end
canxdali = require('applibs.canxdali')
canxdali.sethandler('bus', callback)
end
canxdali.step()
------------------------------
Ctrl+F5
Ctrl+F5