Animatroller.Framework.Expander.DMXPro.DMXPro C# (CSharp) Method

DMXPro() public method

public DMXPro ( string portName ) : System
portName string
return System
        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);
        }