CANx-DALI library

CANx-DALI scripting library #

Load the library:

local canxdali = require('applibs.canxdali')

Library functions #

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 can be a string with the 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

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.

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.

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)

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.

Examples #

Send single command #

Event script that sends arc with value 0 to DALI short address 15 using gateway 0.1.

value = event.getvalue()
value = math.round(value * 2.54) -- 0..100 to 0..254

canxdali = require('applibs.canxdali')

canxdali.sendcmds({
  lineid = 0,
  nodeid = 1,
  cmd = 'arc',
  address = 's15',
  value = value,
})

Send multiple commands #

Event script that sends 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 },
  }
})

Bus monitoring #

Resident script with 0 sleep time.

if not canxdali then
  function callback(frame)
    log(frame)
  end

  canxdali = require('applibs.canxdali')
  canxdali.sethandler('bus', callback)
end

canxdali.step()