0

I've been trying to write a C# application that send data to a stage light using the Enttec DMX USB Pro box. There are provided C# wrappers that I'm using and I've gotten the light to respond as expected but it very rarely works. I seem to have to switch between using from off the shelf application to "reset" the connection a few times before I can get it to start responding to my writes.

My DMX Code is

class DmxDriver
{
    const int DMX_PACKET_SIZE = 513;
    private bool connected;
    private FTDI device;
    private int startAddr;

    private byte[] packet;
    public DmxDriver(int baseDmxAddr)
    {
        startAddr = baseDmxAddr;
        device = new FTDI();
        FTDI.FT_STATUS result =  device.OpenByIndex(0);
        if (result == FTDI.FT_STATUS.FT_OK)
        {
            connected = true;
            Console.WriteLine("DMX connected");
        }
        else
        {
            connected = false;
            Console.WriteLine("DMX CONNECTION FAILED");
        }

        packet = new byte[DMX_PACKET_SIZE];
        for (int i = 0; i < DMX_PACKET_SIZE; i++)
        {
            packet[i] = 0;
        }
    }

    ~DmxDriver()
    {
        device.Close();
    }

    public bool deviceConnected()
    {
        return connected;
    }
    public void sendData()
    {
        if (packet.Length != 513)
        {
            return;
        }
        uint written = 0;
        FTDI.FT_STATUS result;

        byte[] header = new byte[4];
        header[0] = 0x7E; //start code
        header[1] = 6; //DMX TX
        header[2] = 255 & 0xFF; //pack length logical and with max packet size
        header[3] = 255 >> 8; //packet length shifted by byte length? DMX standard idk


        result = device.Write(header, 4, ref written);//send dmx header

        Console.WriteLine(result);
        Console.WriteLine(written);


        result = device.Write(packet, 513, ref written);//send data array
        Console.WriteLine(result);
        Console.WriteLine(written);


        byte[] endcode = new byte[1];
        endcode[0] = 0xE7;
        device.Write(endcode, 1, ref written);//send dmx end code

    }
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
John Lotacs
  • 1,184
  • 4
  • 20
  • 34

0 Answers0