示例#1
0
        public void BytesToRead()
        {
            DGSerial serial1 = new DGSerial(_portName1, _baudRate1);
            DGSerial serial2 = new DGSerial(_portName2, _baudRate2);

            serial1.Open();
            serial2.Open();

            byte[] buffertx = DGSerialHelper.StringToBytes("Test1");
            serial1.WriteBytes(buffertx);

            Assert.That(serial2.BytesToRead(), Is.EqualTo(buffertx.Length));
            byte[] bufferrx = serial2.ReadBytes();

            Assert.That(serial2.BytesToRead(), Is.EqualTo(0));

            serial1.Close();
            serial2.Close();
        }
示例#2
0
        public void DiscardInBuffer()
        {
            DGSerial serial1 = new DGSerial(_portName1, _baudRate1);
            DGSerial serial2 = new DGSerial(_portName2, _baudRate2);

            serial1.Open();
            serial2.Open();

            byte[] buffertx = new byte[serial2.Get().ReadBufferSize];
            serial1.WriteBytes(buffertx);
            serial1.WriteBytes(buffertx);
            serial1.WriteBytes(buffertx);

            Assert.That(serial2.BytesToRead(), Is.EqualTo(serial2.Get().ReadBufferSize));

            serial2.DiscardInBuffer();

            Assert.That(serial2.BytesToRead(), Is.EqualTo(0));

            serial1.Close();
            serial2.Close();
        }