Example #1
0
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            if (_socket.Available == 0)
            {
                if (!OpenConnection())
                {
                    Logging.Warn("Elexol Ether I/O: failed to connect to device, not updating the current state.");
                    return;
                }
            }
            int chan = 0;                           // Current channel being processed.
            int i    = 0;                           // Buffer iterator

            byte[] buf = new byte[6];               // The data buffer. ("A[byte_val]B[byte_val]C[byte_val]" = 6bytes)

            for (char port = 'A'; port <= 'C'; ++port)
            {
                buf[i++] = (byte)port;                  // Port specification
                buf[i]   = 0;                           // Initialize value to zero
                for (int bit = 0; (bit < 8 && chan < outputStates.Length); ++bit, ++chan)
                {
                    _commandHandler.Reset();
                    ICommand command = outputStates[chan];
                    if (command != null)
                    {
                        command.Dispatch(_commandHandler);
                    }
                    // If this channel's value is greater than minIntensity, turn on its bit for this port
                    buf[i] |= (byte)(((_commandHandler.Value > _minIntensity) ? 0x01 : 0x00) << bit);
                }
                i++;
            }
            _socket.Send(buf, buf.Length);
        }
Example #2
0
        public void UpdateState(double fps, ICommand[] outputStates)
        {
            _count++;
            _fps = fps;

            for (int i = 0; i < outputStates.Length; i++)
            {
                _commandHandler.Reset();

                ICommand command = outputStates[i];
                if (command != null)
                {
                    command.Dispatch(_commandHandler);
                }

                if (_values != null)
                {
                    _values[i] = _commandHandler.ByteValue;
                }
                if (_colorValues != null)
                {
                    _colorValues[i] = _commandHandler.ColorValue;
                }
            }

            if (!IsDisposed)
            {
                BeginInvoke(new MethodInvoker(Refresh));
            }
        }
Example #3
0
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            if (serialPortIsValid && _SerialPort.IsOpen)
            {
                _packet = new byte[headerLen + OutputCount + footerLen];
                var packetLen = _packet.Length;

                _header.CopyTo(_packet, 0);
                _footer.CopyTo(_packet, packetLen - footerLen);

                for (int i = 0; i < outputStates.Length && IsRunning; i++)
                {
                    _commandHandler.Reset();
                    ICommand command = outputStates[i];
                    if (command != null)
                    {
                        command.Dispatch(_commandHandler);
                    }
                    _packet[i + headerLen] = _commandHandler.Value;
                }

                if (outputStates.Length > headerLen + footerLen)
                {
                    _SerialPort.Write(_packet, 0, packetLen);
                }
            }
        }
Example #4
0
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            if (SerialPortIsValid && _serialPort.IsOpen)
            {
                _packet = new byte[_headerLen + OutputCount + _footerLen];
                var packetLen = _packet.Length;

                _header.CopyTo(_packet, 0);
                _footer.CopyTo(_packet, packetLen - _footerLen);

                for (int i = 0; i < outputStates.Length && IsRunning; i++)
                {
                    _commandHandler.Reset();
                    ICommand command = outputStates[i];
                    if (command != null)
                    {
                        command.Dispatch(_commandHandler);
                    }
                    _packet[i + _headerLen] = _commandHandler.Value;
                }

                if (packetLen > 0)
                {
                    try
                    {
                        _serialPort.Write(_packet, 0, packetLen);
                    }
                    catch (Exception ex)
                    {
                        Logging.Error(ex, "An error occured writing to the serial port.");
                    }
                }
            }
        }
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            int chan = 0;             // Current channel being processed.

            byte[] buf = new byte[2]; // The serial data buffer.

            if (serialPortIsValid && _serialPort.IsOpen)
            {
                for (char port = 'A'; port <= 'C'; ++port)
                {
                    buf[0] = (byte)port;
                    buf[1] = 0;
                    for (int bit = 0; (bit < 8 && chan < outputStates.Length && IsRunning); ++bit, ++chan)
                    {
                        _commandHandler.Reset();
                        ICommand command = outputStates[chan];
                        if (command != null)
                        {
                            command.Dispatch(_commandHandler);
                        }
                        buf[1] |= (byte)(((_commandHandler.Value > _minIntensity) ? 0x01 : 0x00) << bit);
                    }
                    _serialPort.Write(buf, 0, 2);
                }
            }
        }
Example #6
0
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            int  valueIndex = 0;
            int  bitCount;
            byte value;
            byte bankBox, bank;

            int loopCount = outputStates.Length >> 3;

            for (int box = 0; box < loopCount; box++)
            {
                value = 0;
                for (bitCount = 0; bitCount < 8; bitCount++)
                {
                    _commandHandler.Reset();

                    ICommand command = outputStates[valueIndex++];

                    if (command != null)
                    {
                        command.Dispatch(_commandHandler);

                        value >>= 1;
                        if (_commandHandler.Value > 0)
                        {
                            value |= (byte)0x80;
                        }
                        else
                        {
                            value |= (byte)0;
                        }
                    }
                    else
                    {
                        value >>= 1;
                        value  |= (byte)0;
                    }
                }

                bank    = (byte)(8 << (box >> 3));
                bankBox = (byte)(box % 8);

                LoadInpOutDLL.outputData(_moduleData.PortAddress, value);
                LoadInpOutDLL.outputData(_moduleData.ControlPort, 0);
                LoadInpOutDLL.outputData(_moduleData.ControlPort, 1);
                LoadInpOutDLL.outputData(_moduleData.PortAddress, (ushort)(bank | bankBox));
                LoadInpOutDLL.outputData(_moduleData.ControlPort, 3);
                LoadInpOutDLL.outputData(_moduleData.ControlPort, 1);

                Debug.WriteLine(string.Format("{0} {1} {2}", _moduleData.PortAddress, value, ((ushort)(bank | bankBox))));
            }
        }
Example #7
0
        private void UpdateState(ICommand[] outputStates)
        {
            _eventData.Clear();

            for (int i = 0; i < outputStates.Length; i++)
            {
                _exporterCommandHandler.Reset();
                ICommand command = outputStates[i];
                if (command != null)
                {
                    command.Dispatch(_exporterCommandHandler);
                }
                _eventData.Add(_exporterCommandHandler.Value);
            }

            _output.WriteNextPeriodData(_eventData);
        }
Example #8
0
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            if (_port != null && _port.IsOpen)
            {
                _protocolFormatter.StartPacket(OutputCount, chainIndex);

                for (int i = 0; i < outputStates.Length && IsRunning; i++)
                {
                    _commandHandler.Reset();
                    ICommand command = outputStates[i];
                    if (command != null)
                    {
                        command.Dispatch(_commandHandler);
                    }
                    _protocolFormatter.Add(_commandHandler.Value);
                }
                _WaitForBufferRoom(_PacketSize);
                byte[] packet = _GetPacket();
                _port.Write(packet, 0, _PacketSize);
            }
        }
Example #9
0
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            if (_sequenceStarted)
            {
                if (_timer.ElapsedMilliseconds < _lastUpdateMs + MsPerUpdate)
                {
                    return;
                }

                _lastUpdateMs = _timer.ElapsedMilliseconds;

                for (int i = 0; i < outputStates.Length; i++)
                {
                    _helixCommandHandler.Reset();
                    ICommand command = outputStates[i];
                    if (command != null)
                    {
                        command.Dispatch(_helixCommandHandler);
                    }
                    _eventData.Add(_helixCommandHandler.Value);
                }
            }
        }
Example #10
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]));
                    }
                }
            }
        }
Example #11
0
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            int  valueIndex = 0;
            int  bitCount;
            byte value;
            byte bankBox, bank;

            int loopCount = outputStates.Length >> 3;

            for (int box = 0; box < loopCount; box++)
            {
                value = 0;
                for (bitCount = 0; bitCount < 8; bitCount++)
                {
                    ICommand command = outputStates[valueIndex++];
                    _commandHandler.Reset();
                    if (command != null)
                    {
                        command.Dispatch(_commandHandler);
                    }

                    value >>= 1;
                    if (_commandHandler.Value > 0)
                    {
                        value |= 0x80;
                    }
                }

                bank    = (byte)(8 << (box >> 3));
                bankBox = (byte)(box % 8);


                //Write #1
                //Outputs data byte	(D0-D7)	on pins	2-9 of parallel port.  This is the data
                //we are trying to send	to box XX.
                LoadInpOutDLL.outputData(_moduleData.PortAddress, value);


                //Write #2:
                //Outputs a 1 (high) on C0 and C1 (pins 1 and 14) since they are inverted
                //without changing any states on the data pins.  This opens the
                //"data buffer" flip-flop so that it can read the data on D0-D7.
                //It also opens up the decoders for each bank solely to	avoid the need for a 7th write.
                LoadInpOutDLL.outputData(_moduleData.ControlPort, 0);


                //Write #3
                //Outputs a 0 (low) on C0 and a 1 (high) on C1 since they are inverted. Again, not
                //changing any states on the data pins.  This "locks" the data presently on	D0-D7
                //into the data buffer (C0) but leaves the state of the decoders (C1) unchanged.
                LoadInpOutDLL.outputData(_moduleData.ControlPort, 1);

                // Write #4
                // Outputs the steering (addressing) data on the data pins
                LoadInpOutDLL.outputData(_moduleData.ControlPort, (short)(bank | bankBox));
                if (value > 0)
                {
                    Console.Out.WriteLine((short)(bank | bankBox) + "," + value);
                }

                //Write	#5
                //Outputs a 0 (low) on both	C0 and C1 since	they are inverted.  This locks
                //the data into	the	correct decoder which sends a "low" single to the clock
                //port of one of the 40	flip flops allowing	the	data from the "buffer" flip	flop
                //to flow in.
                LoadInpOutDLL.outputData(_moduleData.ControlPort, 3);

                //Write #6
                //Outputs a 0 (low) on C0 and a 1 (high) on C1 since they are inverted. Again, not
                //changing any states on the data pins.  This locks	the	data into the correct
                //flip flop and will remain transmitting this data to the relays until the next time
                //this box needs to	be modified.
                LoadInpOutDLL.outputData(_moduleData.ControlPort, 1);
            }
        }
 public override ICommand Affect(ICommand command)
 {
     command.Dispatch(_commandHandler);
     return _commandHandler.Result;
 }
 public override ICommand Affect(ICommand command)
 {
     command.Dispatch(_commandHandler);
     return(_commandHandler.Result);
 }
Example #14
0
        public override void UpdateState(int chainIndex, ICommand[] outputStates)
        {
            if (!_data.UseUDP)
            {
                if (SerialPortIsValid && _serialPort.IsOpen)
                {
                    if (_data.XmasMode)
                    {
                        _packet = new byte[5 * 25];

                        for (int i = 0; i < 25; i++)
                        {
                            int      color = 0;
                            ICommand red   = outputStates[3 * i + 0];
                            ICommand grn   = outputStates[3 * i + 1];
                            ICommand blu   = outputStates[3 * i + 2];
                            if (red != null)
                            {
                                red.Dispatch(_commandHandler);
                            }
                            color |= (_commandHandler.Value / 16);
                            if (grn != null)
                            {
                                grn.Dispatch(_commandHandler);
                            }
                            color |= (_commandHandler.Value / 16) << 4;
                            if (blu != null)
                            {
                                blu.Dispatch(_commandHandler);
                            }
                            color |= (_commandHandler.Value / 16) << 8;

                            _packet[i * 5 + 0] = 0x00;
                            _packet[i * 5 + 1] = Convert.ToByte(i + 1);
                            _packet[i * 5 + 2] = Convert.ToByte(color >> 8);
                            _packet[i * 5 + 3] = Convert.ToByte(color & 0xFF);
                            _packet[i * 5 + 4] = 0xFE;

                            if (i == 24)
                            {
                                _packet[i * 5 + 4] = 0xFF;
                            }
                        }

                        try
                        {
                            _serialPort.Write(_packet, 0, 5 * 25);
                        }
                        catch (Exception ex)
                        {
                            Logging.Error(ex, "An error occured writing to the serial port.");
                        }
                    }
                    else
                    {
                        _packet = new byte[outputStates.Length + 3];

                        var packetLen = _packet.Length;

                        _packet[0] = 0xAA;

                        for (int i = 0; i < outputStates.Length && IsRunning; i++)
                        {
                            _commandHandler.Reset();
                            ICommand command = outputStates[i];
                            if (command != null)
                            {
                                command.Dispatch(_commandHandler);
                            }
                            _packet[i + 1] = _commandHandler.Value;
                        }

                        ushort sum = 0;

                        for (int i = 0; i < outputStates.Length + 1; i++)
                        {
                            sum += _packet[i];
                        }

                        _packet[outputStates.Length + 1] = (byte)(sum >> 8);
                        _packet[outputStates.Length + 2] = (byte)(sum & 0x00FF);

                        if (packetLen > 0)
                        {
                            try
                            {
                                _serialPort.Write(_packet, 0, packetLen);
                            }
                            catch (Exception ex)
                            {
                                Logging.Error(ex, "An error occured writing to the serial port.");
                            }
                        }
                    }
                }
            }
            else
            {
                {
                    _packet = new byte[outputStates.Length + 3];

                    var packetLen = _packet.Length;

                    _packet[0] = 0xAA;

                    for (int i = 0; i < outputStates.Length && IsRunning; i++)
                    {
                        _commandHandler.Reset();
                        ICommand command = outputStates[i];
                        if (command != null)
                        {
                            command.Dispatch(_commandHandler);
                        }
                        _packet[i + 1] = _commandHandler.Value;
                    }

                    ushort sum = 0;

                    for (int i = 0; i < outputStates.Length + 1; i++)
                    {
                        sum += _packet[i];
                    }

                    _packet[outputStates.Length + 1] = (byte)(sum >> 8);
                    _packet[outputStates.Length + 2] = (byte)(sum & 0x00FF);

                    if (packetLen > 0)
                    {
                        try
                        {
                            _udpClient.Send(_packet, packetLen);
                        }
                        catch (Exception ex)
                        {
                            Logging.Error(ex, "An error occured writing to the UDP port.");
                        }
                    }
                }
            }
        }