Ejemplo n.º 1
0
        public override IObservable <short> Process <TSource>(IObservable <TSource> source)
        {
            return(Observable.Defer(() =>
            {
                ErrorInfo configError;
                var portType = PortType;
                var bitNumber = BitNumber;
                var board = new MccBoard(BoardNumber);
                if (bitNumber.HasValue)
                {
                    configError = board.DConfigBit(portType, bitNumber.Value, DigitalPortDirection.DigitalIn);
                }
                else
                {
                    configError = board.DConfigPort(portType, DigitalPortDirection.DigitalIn);
                }
                ThrowExceptionForErrorInfo(configError);

                if (bitNumber.HasValue)
                {
                    return source.Select(input =>
                    {
                        var error = board.DBitIn(portType, bitNumber.Value, out DigitalLogicState bitValue);
                        ThrowExceptionForErrorInfo(error);
                        return (short)bitValue;
                    });
                }
                else
                {
                    return source.Select(input =>
                    {
                        var error = board.DIn(portType, out short dataValue);
                        ThrowExceptionForErrorInfo(error);
                        return dataValue;
                    });
                }
            }));
        }