public bool VerifyInfiniteTimeout(WriteMethodDelegate readMethod, bool setInfiniteTimeout) { SerialPort com1 = TCSupport.InitFirstSerialPort(); SerialPort com2 = null; WriteDelegateThread readThread = new WriteDelegateThread(com1, readMethod); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(readThread.CallWrite)); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Handshake = Handshake.RequestToSend; serPortProp.SetProperty("ReadTimeout", 10); com1.ReadTimeout = 10; com1.Open(); if (setInfiniteTimeout) { com1.WriteTimeout = 500; com1.WriteTimeout = SerialPort.InfiniteTimeout; } t.Start(); System.Threading.Thread.Sleep(DEFAULT_WAIT_INFINITE_TIMEOUT); if (!t.IsAlive) { Console.WriteLine("ERROR!!! {0} terminated with infinite timeout", readMethod.Method.Name); retValue = false; } com1.Handshake = Handshake.None; while (t.IsAlive) { System.Threading.Thread.Sleep(10); } com1.DiscardOutBuffer(); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (com1.IsOpen) { com1.Close(); } return(retValue); }
private void VerifyLongTimeout(WriteMethodDelegate writeMethod, SerialPort com1) { var writeThread = new WriteDelegateThread(com1.BaseStream, writeMethod); var t = new Task(writeThread.CallWrite); t.Start(); Thread.Sleep(DEFAULT_WAIT_LONG_TIMEOUT); Assert.False(t.IsCompleted, string.Format("Err_17071ahpa!!! {0} terminated with a long timeout of {1}ms", writeMethod.Method.Name, com1.BaseStream.WriteTimeout)); com1.Handshake = Handshake.None; TCSupport.WaitForTaskCompletion(t); }
private void VerifyLongTimeout(WriteMethodDelegate writeMethod, SerialPort com1) { var writeThread = new WriteDelegateThread(com1.BaseStream, writeMethod); var t = new Thread(writeThread.CallWrite); t.Start(); Thread.Sleep(DEFAULT_WAIT_LONG_TIMEOUT); Assert.True(t.IsAlive, string.Format("Err_17071ahpa!!! {0} terminated with a long timeout of {1}ms", writeMethod.Method.Name, com1.BaseStream.WriteTimeout)); com1.Handshake = Handshake.None; while (t.IsAlive) { Thread.Sleep(10); } }
public bool VerifyLongTimeout(WriteMethodDelegate writeMethod, SerialPort com1) { SerialPort com2 = null; WriteDelegateThread writeThread = new WriteDelegateThread(com1.BaseStream, writeMethod); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(writeThread.CallWrite)); bool retValue = true; t.Start(); System.Threading.Thread.Sleep(DEFAULT_WAIT_LONG_TIMEOUT); retValue &= Eval(t.IsAlive, String.Format("Err_17071ahpa!!! {0} terminated with a long timeout of {1}ms", writeMethod.Method.Name, com1.BaseStream.WriteTimeout)); com1.Handshake = Handshake.None; while (t.IsAlive) { System.Threading.Thread.Sleep(10); } return(retValue); }
private void VerifyInfiniteTimeout(WriteMethodDelegate readMethod, bool setInfiniteTimeout) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) { WriteDelegateThread readThread = new WriteDelegateThread(com1, readMethod); System.Threading.Thread t = new System.Threading.Thread(readThread.CallWrite); SerialPortProperties serPortProp = new SerialPortProperties(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Handshake = Handshake.RequestToSend; serPortProp.SetProperty("ReadTimeout", 10); com1.ReadTimeout = 10; com1.Open(); if (setInfiniteTimeout) { com1.WriteTimeout = 500; com1.WriteTimeout = SerialPort.InfiniteTimeout; } t.Start(); System.Threading.Thread.Sleep(DEFAULT_WAIT_INFINITE_TIMEOUT); Assert.True(t.IsAlive); com1.Handshake = Handshake.None; while (t.IsAlive) { System.Threading.Thread.Sleep(10); } com1.DiscardOutBuffer(); // If we're looped-back, then there will be data queud on the receive side which we need to discard com1.DiscardInBuffer(); serPortProp.VerifyPropertiesAndPrint(com1); } }