Ejemplo n.º 1
0
        public void CorrectBitsDecode()
        {
            Assert.Equal(1, CharacterFramingCommand.StopBitsDecode(8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.Two));
            Assert.Equal(2, CharacterFramingCommand.StopBitsDecode(8, System.IO.Ports.Parity.Mark, System.IO.Ports.StopBits.One));
            Assert.Equal(3, CharacterFramingCommand.StopBitsDecode(8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One));
            Assert.Equal(4, CharacterFramingCommand.StopBitsDecode(7, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.Two));
            Assert.Equal(5, CharacterFramingCommand.StopBitsDecode(7, System.IO.Ports.Parity.Mark, System.IO.Ports.StopBits.One));
            Assert.Equal(6, CharacterFramingCommand.StopBitsDecode(7, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One));


            Assert.Throws <System.ArgumentOutOfRangeException>(
                delegate
            {
                CharacterFramingCommand.StopBitsDecode(8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.OnePointFive);
            });

            Assert.Throws <System.ArgumentOutOfRangeException>(
                delegate
            {
                CharacterFramingCommand.StopBitsDecode(7, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.OnePointFive);
            });

            Assert.Throws <System.ArgumentOutOfRangeException>(
                delegate
            {
                CharacterFramingCommand.StopBitsDecode(6, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.OnePointFive);
            });
        }
Ejemplo n.º 2
0
        public void CorrectBitsEncode()
        {
            ushort zDataBits;

            System.IO.Ports.StopBits zStopBits;

            Assert.True(CharacterFramingCommand.StopBitsEncode(1, out zDataBits, out zStopBits));
            Assert.Equal(8, zDataBits);
            Assert.Equal(System.IO.Ports.StopBits.Two, zStopBits);

            Assert.True(CharacterFramingCommand.StopBitsEncode(2, out zDataBits, out zStopBits));
            Assert.Equal(8, zDataBits);
            Assert.Equal(System.IO.Ports.StopBits.One, zStopBits);

            Assert.True(CharacterFramingCommand.StopBitsEncode(3, out zDataBits, out zStopBits));
            Assert.Equal(8, zDataBits);
            Assert.Equal(System.IO.Ports.StopBits.One, zStopBits);

            Assert.True(CharacterFramingCommand.StopBitsEncode(4, out zDataBits, out zStopBits));
            Assert.Equal(7, zDataBits);
            Assert.Equal(System.IO.Ports.StopBits.Two, zStopBits);

            Assert.True(CharacterFramingCommand.StopBitsEncode(5, out zDataBits, out zStopBits));
            Assert.Equal(7, zDataBits);
            Assert.Equal(System.IO.Ports.StopBits.One, zStopBits);

            Assert.True(CharacterFramingCommand.StopBitsEncode(6, out zDataBits, out zStopBits));
            Assert.Equal(7, zDataBits);
            Assert.Equal(System.IO.Ports.StopBits.One, zStopBits);

            Assert.False(CharacterFramingCommand.StopBitsEncode(7, out zDataBits, out zStopBits));
        }
Ejemplo n.º 3
0
 public void CorrectParityDecode()
 {
     Assert.Equal(0, CharacterFramingCommand.ParityDecode(System.IO.Ports.Parity.Odd));
     Assert.Equal(1, CharacterFramingCommand.ParityDecode(System.IO.Ports.Parity.Even));
     Assert.Equal(2, CharacterFramingCommand.ParityDecode(System.IO.Ports.Parity.Mark));
     Assert.Equal(3, CharacterFramingCommand.ParityDecode(System.IO.Ports.Parity.Space));
     Assert.Equal(4, CharacterFramingCommand.ParityDecode(System.IO.Ports.Parity.None));
 }
Ejemplo n.º 4
0
        public override string WriteCommand()
        {
            ushort zBits;
            ushort zParity;

            zBits   = CharacterFramingCommand.StopBitsDecode(UARTDataBits, UARTParity, UARTStopBits);
            zParity = CharacterFramingCommand.ParityDecode(UARTParity);

            return(String.Format("AT+{0}={1},{2},{3},{4},{5},{6}", CommandPrefix, UARTBaudRate, zBits, zParity, FlowControlCommand.DecodeValue(RTSSignalEnabled), FlowControlCommand.DecodeValue(CTSSignalEnabled), UARTReadTimerInterval));
        }
Ejemplo n.º 5
0
        public virtual string WriteCommand()
        {
            ushort zBits;
            ushort zParity;

            zBits   = CharacterFramingCommand.StopBitsDecode(UARTDataBits, UARTParity, UARTStopBits);
            zParity = CharacterFramingCommand.ParityDecode(UARTParity);

            return(String.Format("AT+{0}={1},{2},{3},{4}", CommandPrefix, UARTBaudRate, zBits, zParity, UARTReadTimerInterval));
        }
Ejemplo n.º 6
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.º 7
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);
            }
        }
Ejemplo n.º 8
0
 public CharacterFramingCases()
 {
     _CharFrCommand = new CharacterFramingCommand();
     _Command       = _CharFrCommand;
 }