title: Lighting USB OpenDMX FTD2XX DMXking
body: <p>Couple of quick questions. I have a DMX king USB lighting controller that I'm trying to control. </p>
  
  <p>It's based on the Open DMX protocol (from Entec) who make available a c# class.
  I've got the device plugged into an RGB can, and if I test the USB device with their driver, it connects to COM4 and when I switch their software into transmit mode, I can then set individual DMX channels.</p>
  
  <p>Using their OpenDMX class, with a few modifications (the core is the same, i've just added some extra error checking, I can locate the device, query it's information etc.
  When I open the device I get a handle.
  I can write to that device with FT_Write but no matter what I do, no lights actually come on.</p>
  
  <p>Here's a few relevant code snippets:</p>
  
  <pre><code>public static byte[] buffer;
  
  [DllImport("FTD2XX.dll")]
  public static extern FT_STATUS FT_Open(UInt32 uiPort, ref uint ftHandle);
  [DllImport("FTD2XX.dll")]
  public static extern FT_STATUS FT_Write(uint ftHandle, IntPtr lpBuffer, UInt32 dwBytesToRead, ref UInt32 lpdwBytesWritten);
  
  public static void writeData()
  {
      while (!done)
      {
          try
          {
              initOpenDMX();
              status = FT_SetBreakOn(handle);
              status = FT_SetBreakOff(handle);
              bytesWritten = write(handle, buffer, buffer.Length);
              if (bytesWritten == 0)
              {
                  break;
              }
  
              System.Threading.Thread.Sleep(25);
          }
          catch (Exception)
          {
              break;
          }
      }
      Connected = false;
      done = false;
  }
  </code></pre>
  
  <p>All the status come back as FT_Ok, and bytesWritten comes back as 512 (the number of channels on this USB controller)</p>
  
  <p>I keep thinking I've missed something like setting the device into a transmit mode or similar  (it only has one DMX socket)</p>
  
  <pre><code>public static void initOpenDMX()
  {
      status = FT_ResetDevice(handle);
      status = FT_SetDivisor(handle, (char)12); // set baud rate
      status = FT_SetDataCharacteristics(handle, BITS_8, STOP_BITS_2, PARITY_NONE);
      status = FT_SetFlowControl(handle, (char)FLOW_NONE, 0, 0);
      status = FT_ClrRts(handle);
      status = FT_SetLatencyTimer(handle, (byte)40);
      status = FT_Purge(handle, PURGE_TX);
      status = FT_Purge(handle, PURGE_RX);
  }
  </code></pre>
  
  <p>I've also tried the Entec OpenDMX class without any modifications from me and it doesn't seem to do anything either. </p>
  
  <p>Just want to stress that their control software is working fine, so the light and controller are compatible. I think something is missing in the way I'm using FTD2xx. 
  There's no errors coming through (everything is FT_OK) so this suggests the DLL is working - especially since I can query the device using the FT_ListDevices and FT_GetDeviceInfo methods.</p>
  
  <p>Any ideas?</p>
  
  <p>Gareth</p>