Jump to content
C4 Forums | Control4

Help needed with driverworks


Recommended Posts

Hey everybody, new to the forum, but not C4. I'm trying to make a simple IP/232 driverworks driver and I'm stuck. I've been through the SDK documentation, online course, etc. I have all the driver XML and main functions for sending/receiving commands taken care of, but I'm stuck on passing a ranged interger or list item from a command. translating it against a simple command table, inserting the resulting value into a lua funcion, then building the command string based on the table results.

      <command>
        <name>Activate Preset</name>
        <description>Activate Preset: Seat PARAM1 PARAM2 Preset PARAM3 on NAME</description>
        <params>
          <param>
            <name>Seat Number</name>
            <type>LIST</type>
            <items>
             <item>ALL</item>
             <item>1</item>
             <item>2</item>
             <item>3</item>
             <item>4</item>
             <item>5</item>
             <item>6</item>
             <item>7</item>
             <item>8</item>
             <item>9</item>
             <item>10</item>
             <item>11</item>
             <item>12</item>
             <item>13</item>
             <item>14</item>
             <item>15</item>
             <item>16</item>
            </items>
          </param>
          <param>
            <name>Preset Action</name>
            <type>LIST</type>
            <items>
              <item>RECALL</item>
              <item>SAVE</item>
            </items>
          </param>
          <param>
            <name>Preset Number</name>
            <type>RANGED_INTEGER</type>
            <minimum>1</minimum>
            <maximum>10</maximum>
          </param>
        </params>
      </command>

---------------------------------------------------------------------
-- Command Protocol
---------------------------------------------------------------------
-- [0D]Sxx yyyz[0D]
-- xx= The seat ID, yyy = command, z = command parameter

ID_MAP = {}
ID_MAP = { -----------Not sure if the structure and formatting here are correct? The cmd that needs to be sent is "-1" for all, etc
    ['All'] = "-1",
    ['1']   = "00",
    ['2']   = "01",
    ['3']   = "02",
    ['4']   = "03",
    ['5']   = "04",
    ['6']   = "05",
    ['7']   = "06",
    ['8']   = "07",
    ['9']   = "08",
    ['10']  = "09",
    ['11']  = "10",
    ['12']  = "11",
    ['13']  = "12",
    ['14']  = "13",
    ['15']  = "14",
    ['16']  = "15",
    }

PRESET_MAP = {}
PRESET_MAP = {    ------ I'm sure there's an easier way to do this with preset = preset -1 or something, but this keeps things clearer in my head
    ['1']   = "0"
    ['2']   = "1"
    ['3']   = "2"
    ['4']   = "3"
    ['5']   = "4"
    ['6']   = "5"
    ['7']   = "6"
    ['8']   = "7"
    ['9']   = "8"
    ['10']  = "9"
    }

function ExecuteCommand(strCommand, tParams)
print("ExecuteCommand function called with : " .. strCommand)  
for k,v in pairs(tParams) do print(k .. " " .. v) end 

  if (strCommand == "GET_PROPERTIES") then
    -- TODO: What properties should be returned to the proxy / UI on this call?
  end

  if (strCommand == "LUA_ACTION") then
    if tParams ~= nil then
      if (tParams.ACTION == "TEST") then
        local action = "#SYSTEM,1," .. os.date("%H:%M")
        SendCmd("action")
      end
    end
  end

  if (strCommand == "Activate Preset") then  
    local presetAction = tParams["Preset Action"]
    local seatNumber = tParams["Seat Number"]
    local presetNumber = tParams["Preset Number"]
      if (presetAction == "RECALL") then
        cmd = "SET"
      elseif (presetAction == "SAVE") then
        cmd = "SAV"
      end
--------------Here in particular is where I'm stuck. I can't figure out how to format "strtosend" based on the table result of "Seat Number" and "Preset Number"
    strToSend = "\r"  .. "S" .. "xx" .. " " .. "cmd" .. "z" .. "\r"
    SendCmd(strToSend)
-------------Not sure if I should call a separate function to format "strTosend" so it can be called from other functions, not just commands, but I'd be happy to just get commands working for now
    --FormatMsg(tParams["Seat Number"], cmd, tParams["Preset Number"])
  end
end

function SendCmd(strCommand)
  print(os.date("[%x %X]") .. " .......TX$> " .. strCommand)
  if (g_NetworkBound) then
    C4:SendToNetwork(networkBinding, tonumber(PORT), strCommand)
  end
  if (g_SerialBound) then
    C4:SendToSerial(serialBinding, strCommand)
  end
end

--------------received data isn't important for now, just have this in to see any response data

function ReceivedFromNetwork(idBinding, nPort, strData)
  print("ReceivedFromNetwork(), idBinding = " .. tostring(idBinding) .. ", nPort = " .. tostring(nPort) .. ", strData = " .. strData)
end

function ReceivedFromSerial(idBinding, strData)
  print("RECEIVED FROM SERIAL: " .. strData)
end


I'd be willing to pay somebody knowledgeable in this area whatever hourly rate for a 20 or 30 minute teamviewer session to hold my hand and walk me through this and look over my code in the interest of time and comprehension, or any help here would be much appreciated.

Link to comment
Share on other sites


Ugh I'm going to need serious help from a pro on this. I THINK I got the command parsing down, but NOW I can't even get the damn thing to print to the Lua console! Like what could possibly be broken for the "print" command not to work?? The driver loads so the XML structure must be OK? Even just making a new driver with the same XML and only putting just a print line on the executecommand function outputs nothing to the console? Like what??

Ugh I've been tearing my hear out for days AND days on this EVERY night until the early hours of the morning and I know it's gotta be some syntax or something missing on one or two lines of code.

Link to comment
Share on other sites

2 hours ago, Brylliantworks said:

Ugh I'm going to need serious help from a pro on this. I THINK I got the command parsing down, but NOW I can't even get the damn thing to print to the Lua console! Like what could possibly be broken for the "print" command not to work?? The driver loads so the XML structure must be OK? Even just making a new driver with the same XML and only putting just a print line on the executecommand function outputs nothing to the console? Like what??

Ugh I've been tearing my hear out for days AND days on this EVERY night until the early hours of the morning and I know it's gotta be some syntax or something missing on one or two lines of code.

Update your driver to the current version whilst in the Lua tab and see if any error shows up briefly as it updates.

Link to comment
Share on other sites

9 hours ago, Shivam Paw said:

Update your driver to the current version whilst in the Lua tab and see if any error shows up briefly as it updates.

Wow super helpful thanks Shivam! Yeah, 100% what I thought and just a stupid syntax error:

[string "Lua Code"]:83: '}' expected (to close '{' at line 81) near '['

I probably would've spent an entire day figuring that out, tearing the code apart without that simple tip!

Link to comment
Share on other sites

6 minutes ago, Brylliantworks said:

Wow super helpful thanks Shivam! Yeah, 100% what I thought and just a stupid syntax error:


[string "Lua Code"]:83: '}' expected (to close '{' at line 81) near '['

I probably would've spent an entire day figuring that out, tearing the code apart without that simple tip!

No problem and good luck :) 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.