public void Close() { DGSerial serial = new DGSerial(_portName1, _baudRate1); Assert.IsFalse(serial.Close()); serial.Open(); Assert.IsTrue(serial.Close()); }
public void TimeOutReadFail() { DGSerial serial2 = new DGSerial(_portName2, _baudRate2); serial2.Open(); byte[] bufferrx1 = serial2.ReadBytes(); Assert.That(bufferrx1.Length, Is.EqualTo(0)); serial2.Close(); }
private void WriteBytesBlocking_ReadThread() { Thread.Sleep(2000); DGSerial serial2 = new DGSerial(_portName2, _baudRate2); serial2.Open(); byte[] bufferrx = serial2.ReadBytes(); serial2.Close(); }
private void ReadBytesTo_ReadThread() { Thread.Sleep(2000); DGSerial serial1 = new DGSerial(_portName1, _baudRate1); serial1.Open(); byte[] buffertx = DGSerialHelper.StringToBytes("T44es41t1"); serial1.WriteBytes(buffertx); serial1.Close(); }
private void ReadBytesBlocking_ReadThread() { Thread.Sleep(2000); DGSerial serial1 = new DGSerial(_portName1, _baudRate1); serial1.Open(); byte[] buffertx = new byte[serial1.Get().ReadBufferSize]; serial1.WriteBytes(buffertx); serial1.Close(); }
public void TimeOutWriteFail() { DGSerial serial1 = new DGSerial(_portName1, _baudRate1); serial1.Open(); byte[] buffertx1 = DGSerialHelper.StringToBytes("Test1"); Assert.IsTrue(serial1.WriteBytes(buffertx1)); byte[] buffertx2 = DGSerialHelper.StringToBytes("Test1"); Assert.IsFalse(serial1.WriteBytes(buffertx2)); serial1.Close(); }
public void DiscardOutBuffer() { DGSerial serial1 = new DGSerial(_portName1, _baudRate1); serial1.Open(); byte[] buffertx = new byte[serial1.Get().WriteBufferSize]; serial1.WriteBytes(buffertx); serial1.DiscardOutBuffer(); Assert.That(serial1.BytesToRead(), Is.EqualTo(0)); serial1.Close(); }
public void WriteBytesBlocking() { DGSerial serial1 = new DGSerial(_portName1, _baudRate1); Thread thread = new Thread(new ThreadStart(WriteBytesBlocking_ReadThread)); serial1.Open(); byte[] buffertx = new byte[serial1.Get().WriteBufferSize]; Stopwatch watch = Stopwatch.StartNew(); thread.Start(); serial1.WriteBytesBlocking(buffertx); watch.Stop(); Assert.That(watch.ElapsedMilliseconds, Is.AtLeast(1999)); serial1.Close(); }
public void ReadBytes() { DGSerial serial1 = new DGSerial(_portName1, _baudRate1); DGSerial serial2 = new DGSerial(_portName2, _baudRate2); serial1.Open(); serial2.Open(); byte[] buffertx = DGSerialHelper.StringToBytes("Test1"); serial1.WriteBytes(buffertx); byte[] bufferrx = serial2.ReadBytes(); Assert.That(buffertx, Is.EqualTo(bufferrx)); serial1.Close(); serial2.Close(); }
public void AttachDataReceived() { DGSerial serial1 = new DGSerial(_portName1, _baudRate1); DGSerial serial2 = new DGSerial(_portName2, _baudRate2); serial1.Open(); serial2.Open(); serial2.AttachDataReceived(WriteBytes_DataReceived); byte[] buffertx = DGSerialHelper.StringToBytes("Test1"); serial1.WriteBytes(buffertx); serial1.Close(); Thread.Sleep(1000); serial2.Close(); }
public void ReadBytesBlocking() { DGSerial serial2 = new DGSerial(_portName2, _baudRate2); Thread thread = new Thread(new ThreadStart(ReadBytesBlocking_ReadThread)); serial2.Open(); Stopwatch watch = Stopwatch.StartNew(); thread.Start(); byte[] bufferrx = serial2.ReadBytesBlocking(); watch.Stop(); var wd = watch.ElapsedMilliseconds; Assert.That(watch.ElapsedMilliseconds, Is.AtLeast(1999)); serial2.Close(); }
public void TimeOutWriteSuccess() { DGSerial serial1 = new DGSerial(_portName1, _baudRate1); DGSerial serial2 = new DGSerial(_portName2, _baudRate2); serial1.Open(); serial2.Open(); byte[] buffertx1 = new byte[serial1.Get().ReadBufferSize]; Assert.IsTrue(serial1.WriteBytes(buffertx1)); byte[] bufferrx1 = serial2.ReadBytes(); byte[] buffertx2 = new byte[serial1.Get().ReadBufferSize - 5]; Assert.IsTrue(serial1.WriteBytes(buffertx2)); byte[] bufferrx2 = serial2.ReadBytes(); serial1.Close(); serial2.Close(); }
public void TimeOutReadSuccess() { DGSerial serial1 = new DGSerial(_portName1, _baudRate1); DGSerial serial2 = new DGSerial(_portName2, _baudRate2); serial1.Open(); serial2.Open(); byte[] buffertx1 = new byte[serial1.Get().ReadBufferSize]; serial1.WriteBytes(buffertx1); byte[] bufferrx1 = serial2.ReadBytes(); Assert.That(bufferrx1.Length, Is.EqualTo(serial1.Get().ReadBufferSize)); byte[] buffertx2 = new byte[serial1.Get().ReadBufferSize - 5]; serial1.WriteBytes(buffertx2); byte[] bufferrx2 = serial2.ReadBytes(); Assert.That(bufferrx2.Length, Is.EqualTo(serial1.Get().ReadBufferSize - 5)); serial1.Close(); serial2.Close(); }
public void ReadBytesTo() { DGSerial serial2 = new DGSerial(_portName2, _baudRate2); serial2.Open(); Thread thread = new Thread(new ThreadStart(ReadBytesTo_ReadThread)); thread.Start(); byte[] bufferrx = serial2.ReadBytesTo(Convert.ToByte('1'), Convert.ToByte('4'), SerialPort.InfiniteTimeout); var a = DGSerialHelper.BytesToString(bufferrx); Assert.That(DGSerialHelper.BytesToString(bufferrx), Is.EqualTo("T4es1t")); Thread thread2 = new Thread(new ThreadStart(ReadBytesTo_ReadThread)); thread2.Start(); byte[] bufferrx2 = serial2.ReadBytesTo(Convert.ToByte('2'), Convert.ToByte('4'), 3000); Assert.That(DGSerialHelper.BytesToString(bufferrx2), Is.EqualTo("T4es1t1")); serial2.Close(); }
public void Get() { DGSerial serial = new DGSerial(_portName1, _baudRate1); Assert.That(serial.Get(), Is.Not.EqualTo(null)); }