Exemplo n.º 1
0
        public FGDimmer()
        {
            _commandHandler = new CommandHandler();
            DataPolicyFactory = new FGDimmerDataPolicyFactory();

            _packets = new byte[][]
            {
                new byte[34],
                new byte[34],
                new byte[34],
                new byte[34]
            };

            for (int i = 0; i < 4; i++)
            {
                _packets[i][0] = 0x55;
                _packets[i][1] = (byte)(i + 1);

            }
                _modules = new FGDimmerControlModule[4];
                for (int i = 0; i < 4; i++)
                {
                    _modules[i] = new FGDimmerControlModule(i + 1);
                }

                _eventThread = new Thread(new ThreadStart(EventThread));
                _eventTrigger = new AutoResetEvent(false);
                _multiplier = (float)100 / 255;
        }
Exemplo n.º 2
0
        public FGDimmer()
        {
            _commandHandler   = new CommandHandler();
            DataPolicyFactory = new FGDimmerDataPolicyFactory();

            _packets = new byte[][]
            {
                new byte[34],
                new byte[34],
                new byte[34],
                new byte[34]
            };

            for (int i = 0; i < 4; i++)
            {
                _packets[i][0] = 0x55;
                _packets[i][1] = (byte)(i + 1);
            }
            _modules = new FGDimmerControlModule[4];
            for (int i = 0; i < 4; i++)
            {
                _modules[i] = new FGDimmerControlModule(i + 1);
            }

            _eventThread  = new Thread(new ThreadStart(EventThread));
            _eventTrigger = new AutoResetEvent(false);
            _multiplier   = (float)100 / 255;

            //set 2 minute timer before retrying to access com port
            _retryTimer          = new System.Timers.Timer(120000);
            _retryTimer.Elapsed += new ElapsedEventHandler(_retryTimer_Elapsed);
            _retryCounter        = 0;
        }
Exemplo n.º 3
0
        public FGDimmer()
        {
            _commandHandler = new CommandHandler();
            DataPolicyFactory = new FGDimmerDataPolicyFactory();

            _packets = new byte[][]
            {
                new byte[34],
                new byte[34],
                new byte[34],
                new byte[34]
            };

            for (int i = 0; i < 4; i++)
            {
                _packets[i][0] = 0x55;
                _packets[i][1] = (byte)(i + 1);

            }
            _modules = new FGDimmerControlModule[4];
            for (int i = 0; i < 4; i++)
            {
                _modules[i] = new FGDimmerControlModule(i + 1);
            }

            _eventThread = new Thread(new ThreadStart(EventThread));
            _eventTrigger = new AutoResetEvent(false);
            _multiplier = (float)100 / 255;

            //set 2 minute timer before retrying to access com port
            _retryTimer = new System.Timers.Timer(120000);
            _retryTimer.Elapsed += new ElapsedEventHandler(_retryTimer_Elapsed);
            _retryCounter = 0;
        }
Exemplo n.º 4
0
        private void FireEvent()
        {
            if (_serialPort != null && !_serialPort.IsOpen)
            {
                _OpenComPort();
            }

            if (_serialPort != null && _serialPort.IsOpen)
            {
                if (_acOperation)
                {
                    //with dimming curve translation
                    for (int i = 0; i < _channelValues.Length; i++)
                    {
                        _commandHandler.Reset();
                        ICommand command = _outputStates[i];
                        if (command != null)
                        {
                            command.Dispatch(_commandHandler);
                        }
                        if (_channelValues != null)
                        {
                            _channelValues[i] = _commandHandler.Value;
                            _channelValues[i] = (byte)(_dimmingCurve[_channelValues[i]] * _multiplier + 100);
                        }
                    }
                }
                else
                {
                    //no dimming curve
                    for (int i = 0; i < _outputStates.Length; i++)
                    {
                        _commandHandler.Reset();
                        ICommand command = _outputStates[i];
                        if (command != null)
                        {
                            command.Dispatch(_commandHandler);
                        }
                        if (_channelValues != null)
                        {
                            _channelValues[i] = _commandHandler.Value;
                            _channelValues[i] = (byte)(_channelValues[i] * _multiplier + 100);
                        }
                    }
                }

                //Distribute the data
                int count = 0;
                FGDimmerControlModule module = null;
                for (int i = 0; i < 4; i++)
                {
                    module = _modules[i];
                    if (!module.Enabled)
                    {
                        continue;
                    }

                    // get the max number of bytes that will be copied from the data -1
                    // because module.StartChannel starts at 1 and _startChannel starts at 0
                    // and is the start channel for the data to be sent to this plugin
                    count = Math.Min(32, _outputStates.Length - (module.StartChannel - 1 - _startChannel));

                    //Copy the data to the module's packet
                    //but we need to check and see if the _channelValues are null first.
                    if (_channelValues != null)
                    {
                        Array.Copy(_channelValues, module.StartChannel - 1 - _startChannel, _packets[i], 2, count);
                        //update the hardware
                        _serialPort.Write(_packets[i], 0, _packets[i].Length);

                        //Console.WriteLine(Encoding.Default.GetString(_packets[i]));
                    }
                }
            }
        }