public bool VerifyInfiniteTimeout(ReadMethodDelegate readMethod, bool setInfiniteTimeout) { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName); ReadDelegateThread readThread = new ReadDelegateThread(com1, readMethod); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(readThread.CallRead)); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("WriteTimeout", 10); com1.WriteTimeout = 10; com1.Open(); if (!com2.IsOpen) { com2.Open(); } if (setInfiniteTimeout) { com1.ReadTimeout = 500; com1.ReadTimeout = 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; } retValue &= serPortProp.VerifyPropertiesAndPrint(com1); com2.WriteLine(String.Empty); while (t.IsAlive) { System.Threading.Thread.Sleep(10); } if (com1.IsOpen) { com1.Close(); } if (com2.IsOpen) { com2.Close(); } return(retValue); }
private void VerifyLongTimeout(ReadMethodDelegate readMethod, SerialPort com1, SerialPort com2) { var readThread = new ReadDelegateThread(com1.BaseStream, readMethod); var t = new Task(readThread.CallRead); 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", readMethod.Method.Name, com1.BaseStream.ReadTimeout)); com2.Write(new byte[8], 0, 8); TCSupport.WaitForTaskCompletion(t); }
private void VerifyLongTimeout(ReadMethodDelegate readMethod, SerialPort com1, SerialPort com2) { var readThread = new ReadDelegateThread(com1.BaseStream, readMethod); var t = new Thread(readThread.CallRead); 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", readMethod.Method.Name, com1.BaseStream.ReadTimeout)); com2.Write(new byte[8], 0, 8); while (t.IsAlive) { Thread.Sleep(10); } }
public void VerifyInfiniteTimeout(ReadMethodDelegate readMethod, bool setInfiniteTimeout) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { ReadDelegateThread readThread = new ReadDelegateThread(com1, readMethod); System.Threading.Thread t = new System.Threading.Thread(readThread.CallRead); SerialPortProperties serPortProp = new SerialPortProperties(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("WriteTimeout", 10); com1.WriteTimeout = 10; com1.Open(); if (!com2.IsOpen) { com2.Open(); } if (setInfiniteTimeout) { com1.ReadTimeout = 500; com1.ReadTimeout = SerialPort.InfiniteTimeout; } t.Start(); System.Threading.Thread.Sleep(DEFAULT_WAIT_INFINITE_TIMEOUT); Assert.True(t.IsAlive); serPortProp.VerifyPropertiesAndPrint(com1); com2.WriteLine(string.Empty); while (t.IsAlive) { System.Threading.Thread.Sleep(10); } } }
public bool VerifyLongTimeout(ReadMethodDelegate readMethod, SerialPort com1, SerialPort com2) { ReadDelegateThread readThread = new ReadDelegateThread(com1.BaseStream, readMethod); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(readThread.CallRead)); 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", readMethod.Method.Name, com1.BaseStream.ReadTimeout)); com2.Write(new byte[8], 0, 8); while (t.IsAlive) { System.Threading.Thread.Sleep(10); } return(retValue); }