예제 #1
0
        /***************************************************************************/

        public static void encoder(ILogicalElement _element)
        {
            ILineCollection inputs  = _element.Inputs;
            ILineCollection outputs = _element.Outputs;

            if (inputs.hasValue(LogicValue.Enum.Unknown))
            {
                outputs.setToAllLines(LogicValue.Enum.Unknown);
                return;
            }

            int enableIndex = inputs.Size - 1;

            if (inputs[enableIndex].Value == LogicValue.Enum.Low)
            {
                outputs.setToAllLines(LogicValue.Enum.Low);
                return;
            }

            if (inputs[enableIndex].Value == LogicValue.Enum.DontCare)
            {
                outputs.setToAllLines(LogicValue.Enum.DontCare);
                return;
            }

            int highValueIndex = -1;

            for (int i = enableIndex - 1; i >= 0; --i)
            {
                if (inputs[i].Value == LogicValue.Enum.High)
                {
                    highValueIndex = i;
                    break;
                }

                if (inputs[i].Value == LogicValue.Enum.DontCare)
                {
                    outputs.setToAllLines(LogicValue.Enum.DontCare);
                    return;
                }
            }

            if (highValueIndex == -1)
            {
                outputs.setToAllLines(LogicValue.Enum.DontCare);
                return;
            }

            int outputsCount = outputs.Size;
            LogicValuesNumbersConverter converter = new LogicValuesNumbersConverter();
            LogicSet outputSet = converter.toLogicSet(highValueIndex, outputsCount);

            for (int i = 0; i < outputsCount; ++i)
            {
                outputs[i].Value = outputSet[i];
            }
        }
예제 #2
0
        /***************************************************************************/

        public static void dmx(ILogicalElement _element)
        {
            ILineCollection inputs  = _element.Inputs;
            ILineCollection outputs = _element.Outputs;

            if (inputs.hasValue(LogicValue.Enum.Unknown))
            {
                outputs.setToAllLines(LogicValue.Enum.Unknown);
                return;
            }

            outputs.setToAllLines(LogicValue.Enum.Low);

            int enableIndex           = inputs.Size - 1;
            int informationInputIndex = enableIndex - 1;

            if (inputs[enableIndex].Value == LogicValue.Enum.Low)
            {
                return;
            }

            if (inputs[informationInputIndex].Value == LogicValue.Enum.Low)
            {
                return;
            }

            LogicValuesNumbersConverter converter = new LogicValuesNumbersConverter();
            Numbers outputLineNumbers             = converter.toNumbers(inputs, 0, informationInputIndex - 1);

            int outputLineNumbersCount = outputLineNumbers.Count;

            if (outputLineNumbersCount == 1)
            {
                outputs[outputLineNumbers[0]].Value = inputs[informationInputIndex].Value;
            }
            else
            {
                for (int i = 0; i < outputLineNumbersCount; ++i)
                {
                    outputs[outputLineNumbers[i]].Value = LogicValue.Enum.DontCare;
                }
            }
        }