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.

Art-Net DMX
#13
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()
Reply


Messages In This Thread
Art-Net DMX - by sjfp - 11.05.2018, 12:33
RE: Art-Net DMX - by edgars - 11.05.2018, 13:08
RE: Art-Net DMX - by sjfp - 11.05.2018, 13:20
RE: Art-Net DMX - by admin - 14.05.2018, 06:28
RE: Art-Net DMX - by Erwin van der Zwart - 14.05.2018, 07:53
RE: Art-Net DMX - by sjfp - 14.05.2018, 10:26
RE: Art-Net DMX - by admin - 14.05.2018, 11:02
RE: Art-Net DMX - by Erwin van der Zwart - 14.05.2018, 19:56
RE: Art-Net DMX - by sjfp - 21.05.2018, 17:16
RE: Art-Net DMX - by admin - 15.05.2018, 06:52
RE: Art-Net DMX - by admin - 22.05.2018, 06:00
RE: Art-Net DMX - by sjfp - 22.05.2018, 17:19
RE: Art-Net DMX - by admin - 23.05.2018, 08:35
RE: Art-Net DMX - by sjfp - 23.05.2018, 09:49
RE: Art-Net DMX - by lcrowhurst - 03.02.2020, 03:20
RE: Art-Net DMX - by admin - 03.02.2020, 11:41
RE: Art-Net DMX - by lcrowhurst - 03.02.2020, 12:15
RE: Art-Net DMX - by admin - 03.02.2020, 12:51
RE: Art-Net DMX - by lcrowhurst - 04.02.2020, 12:56
RE: Art-Net DMX - by admin - 04.02.2020, 13:09
RE: Art-Net DMX - by lcrowhurst - 06.02.2020, 01:21
RE: Art-Net DMX - by lcrowhurst - 07.09.2020, 22:49

Forum Jump: