lanbox dmx controller

Moderator: leecollings

Post Reply
mhwlng
Posts: 4
Joined: Sunday 21 February 2016 13:28
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

lanbox dmx controller

Post by mhwlng »

some example code, to control 4 DMX RGB panels connected to a Lanbox

requires luasocket library

Code: Select all


local socket = require("socket")

function SendCommand (address,port,commandstring)

  local switchto16bitcommand = "*65ff#"; -- Common16BitMode On
  local step = 0;

  local tcp = assert(socket.tcp())

  tcp:connect(address, port);
  tcp:settimeout(0)
  tcp:setoption("tcp-nodelay",true)
  tcp:setoption("keepalive",true)

  local t1 = os.time()

  while true do -- wait until command done

    if (os.difftime (os.time(),t1) > 5) then
      print ("LanBox Timeout")
      break
    end

    local s, status, partial = tcp:receive()
    if status == "closed" or status == "Socket is not connected" then
      break
    else
      local data = s or partial

      if (data) and (data ~= "") then
        print ("&"..data);
        if string.find (data,"?",1,1) ~= nil then
          print ("LanBox Error Received")
          break
        elseif string.find (data,">",1,1) ~= nil then
          if (step ==0) then
            print (commandstring);
            tcp:send(commandstring);
            step=1;
          elseif (step==1) then
            break
          end
        elseif string.find (data,":",1,1) ~= nil then -- 'enter password :'
          tcp:send('777\r');
        elseif string.find (data,"d",1,1) ~= nil then -- 'connected'
          print (switchto16bitcommand);
          tcp:send(switchto16bitcommand);
        end
      end
    end
  end

  tcp:close()

end

function StartCue (address,port,cuenumber)

  local commandstring = "*5601"..string.format("%04X",cuenumber).."01#"; -- EngineGo Eng# Cuelist cuestep

  SendCommand (address,port,commandstring)
end

function SetRGBColor (address,port,R,G,B)

  local commandstring = ""

  commandstring = "*C901"; -- ChannelSetData Eng# Ch# (R) Chval (R)

  -- 1,14,27,40 control byte for 4 panels
  -- 2 -13 RGB panel #1
  -- 15-26 RGB panel #2
  -- 28-39 RGB panel #3
  -- 41-52 RGB panel #4

  for i = 0,3 do
    commandstring = commandstring..string.format("%04X",i*13+1).."FF";
    for j = 0,3 do
      commandstring = commandstring .. string.format("%04X",i*13+j*3+2) .. string.format("%02X",R);
      commandstring = commandstring .. string.format("%04X",i*13+j*3+3) .. string.format("%02X",G);
      commandstring = commandstring .. string.format("%04X",i*13+j*3+4) .. string.format("%02X",B);
    end
  end

  commandstring = commandstring.."#";

  SendCommand (address,port,commandstring)

end

Code: Select all

SetRGBColor ("192.168.2.77",777,255,0,0)
StartCue ("192.168.2.77",777,40) 
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest