Ejemplo n.º 1
0
        public void CorrectParityEncode()
        {
            Assert.Equal(System.IO.Ports.Parity.Odd, CharacterFramingCommand.ParityEncode(0));
            Assert.Equal(System.IO.Ports.Parity.Even, CharacterFramingCommand.ParityEncode(1));
            Assert.Equal(System.IO.Ports.Parity.Mark, CharacterFramingCommand.ParityEncode(2));
            Assert.Equal(System.IO.Ports.Parity.Space, CharacterFramingCommand.ParityEncode(3));
            Assert.Equal(System.IO.Ports.Parity.None, CharacterFramingCommand.ParityEncode(4));

            Assert.Throws <System.ArgumentOutOfRangeException>(
                delegate
            {
                CharacterFramingCommand.ParityEncode(5);
            });
        }
Ejemplo n.º 2
0
        public override bool Parse(List <string> aAnswer)
        {
            if (base.Parse(aAnswer))
            {
                string[] zSplit = aAnswer[0].Split(new Char[] { ':', ',' });
                if (zSplit.Count() >= 5)
                {
                    try
                    {
                        ushort zBits   = ushort.Parse(TrimValue(zSplit[2]));
                        ushort zParity = ushort.Parse(TrimValue(zSplit[3]));

                        ushort   zUartDataBits = 0;
                        StopBits zUartStopBits = StopBits.One;

                        if (!CharacterFramingCommand.StopBitsEncode(zBits, out zUartDataBits, out zUartStopBits))
                        {
                            return(false);
                        }

                        UARTBaudRate          = UInt32.Parse(TrimValue(zSplit[1]));
                        UARTDataBits          = zUartDataBits;
                        UARTParity            = CharacterFramingCommand.ParityEncode(zParity);
                        UARTStopBits          = zUartStopBits;
                        UARTReadTimerInterval = UInt16.Parse(TrimValue(zSplit[4]));

                        return(true);
                    }
                    catch (Exception zException)
                    {
                        _logger.WarnException("Handled exception", zException);
                        return(false);
                    }
                }
                else
                {
                    _logger.Debug("InCorrect Params Count: {0}", zSplit.Count());
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }