0

我一直在尝试编写一个使用 Enttec DMX USB Pro 盒子将数据发送到舞台灯的 C# 应用程序。提供了我正在使用的 C# 包装器,并且我已经得到了预期的响应,但它很少起作用。我似乎必须在使用现成的应用程序和“重置”连接之间切换几次,然后我才能让它开始响应我的写入。

我的 DMX 代码是

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

    }
4

0 回答 0