This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

canX dali commands
#1
Hi
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
Reply
#2
Thank you! 

How to use canxdali.sendqueries(req) correctly?

canxdali.sendcmds(req) works fine.

canxdali.sendqueries(req) returns an error: 
Quote:Library applibs/canxdali:676: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
[C]: in function 'ipairs'
Library applibs/canxdali:676: in function 'sendqueries'

I'm trying to do this (below):

Code:
canxdali = require('applibs.canxdali')

local data = {}

data = canxdali.sendqueries({
  lineid = 0,
  nodeid = 2,
  cmd = "queryactual",
  address = "s20",
    --value = data,
})

log(data)
Reply
#3
In did it doesn't, let us check this.
------------------------------
Ctrl+F5
Reply
#4
sendqueries expects cmds table instead of a single cmd. This is fixed in CANx-DALI app version 20200326. Now the return value will depend on supplied arguments. Single cmd request will return query value on success. When cmds table is passed a table of values will be returned even when cmds table has only one command.

This will work in previous app version:
Code:
data = canxdali.sendqueries({
  lineid = 0,
  nodeid = 2,
  cmds = {
    { cmd = "queryactual", address = "s20" }
  }
})
Reply
#5
(26.03.2020, 15:26)admin Wrote: sendqueries expects cmds table instead of a single cmd. This is fixed in CANx-DALI app version 20200326. Now the return value will depend on supplied arguments. Single cmd request will return query value on success. When cmds table is passed a table of values will be returned even when cmds table has only one command.

This will work in previous app version:
Code:
data = canxdali.sendqueries({
  lineid = 0,
  nodeid = 2,
  cmds = {
    { cmd = "queryactual", address = "s20" }
  }
})

Tried it. Working!!!  Smile

Thank you very much!!!
Reply
#6
Hi,
With CANx DALI gateway by CAN, is it possible to use the commands from the list (https://openrb.com/docs/dali.htm), or just these CANx commmands?
Best regards,
David
Reply
#7
This list works only on the old internal interface or RS485 dali gateway. CANx has is own list.
See also this:
https://openrb.com/docs/canxdali-dali2.htm
------------------------------
Ctrl+F5
Reply
#8
DALI command names are the same between old DALI and CANx-DALI.
Reply


Forum Jump: