예제 #1
0
파일: Module.cs 프로젝트: paulhimle/Vixen
        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))));
            }
        }
예제 #2
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);
            }
        }