Пример #1
0
        public DMXPro(string portName)
        {
            this.log        = Log.Logger;
            this.initWait   = new System.Threading.ManualResetEvent(false);
            this.serialPort = new SerialPort(portName, 38400);
            this.serialPort.DataReceived      += serialPort_DataReceived;
            this.packetManager                 = new DmxPacketManager();
            this.packetManager.PacketReceived += packetManager_PacketReceived;
            this.dmxData = new byte[513];
            // Set Start Code
            this.dmxData[0] = 0;

            this.cancelSource = new System.Threading.CancellationTokenSource();
            this.firstChange  = new System.Diagnostics.Stopwatch();

            this.senderTask = new Task(x =>
            {
                while (!this.cancelSource.IsCancellationRequested)
                {
                    bool sentChanges = false;

                    lock (lockObject)
                    {
                        if (this.dataChanges > 0)
                        {
                            this.firstChange.Stop();
                            //this.log.Information("Sending {0} changes to DMX Pro. Oldest {1:N2}ms",
                            //    this.dataChanges, this.firstChange.Elapsed.TotalMilliseconds);
                            this.dataChanges = 0;
                            sentChanges      = true;

                            SendSerialCommand(6, this.dmxData);
                        }
                    }

                    if (!sentChanges)
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                }
            }, this.cancelSource.Token, TaskCreationOptions.LongRunning);

            Executor.Current.Register(this);
        }
Пример #2
0
        protected void packetManager_PacketReceived(object sender, DmxPacketManager.DmxPacketReceivedEventArgs e)
        {
            string bufData = string.Join(",", e.PacketData.ToList().ConvertAll(x => x.ToString("d")));
            log.Info("Received from DMXPro: Label: {0:d}   Payload: {1}", e.Label, bufData);

            if (!foundDmxPro)
            {
                // Check if we have a DMX Pro
                if (e.PacketData.Length == 5)
                {
                    int version = e.PacketData[0] + (e.PacketData[1] << 8);
                    if (version >= 300)
                        foundDmxPro = true;
                    this.initWait.Set();
                }
            }
        }
Пример #3
0
        public DMXPro(string portName)
        {
            this.initWait = new System.Threading.ManualResetEvent(false);
            this.serialPort = new SerialPort(portName, 38400);
            this.serialPort.DataReceived += serialPort_DataReceived;
            this.packetManager = new DmxPacketManager();
            this.packetManager.PacketReceived += packetManager_PacketReceived;
            this.dmxData = new byte[513];
            // Set Start Code
            this.dmxData[0] = 0;

            this.cancelSource = new System.Threading.CancellationTokenSource();
            this.firstChange = new System.Diagnostics.Stopwatch();

            this.senderTask = new Task(x =>
                {
                    while (!this.cancelSource.IsCancellationRequested)
                    {
                        bool sentChanges = false;

                        lock (lockObject)
                        {
                            if (this.dataChanges > 0)
                            {
                                this.firstChange.Stop();
                                //log.Info("Sending {0} changes to DMX Pro. Oldest {1:N2}ms",
                                //    this.dataChanges, this.firstChange.Elapsed.TotalMilliseconds);
                                this.dataChanges = 0;
                                sentChanges = true;

                                SendSerialCommand(6, this.dmxData);
                            }
                        }

                        if(!sentChanges)
                            System.Threading.Thread.Sleep(10);
                    }
                }, this.cancelSource.Token, TaskCreationOptions.LongRunning);

            Executor.Current.Register(this);
        }