public void Handshake_None() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com, CHAR_SIZE_HANDSHAKE); System.Threading.Thread t = new System.Threading.Thread(asyncWriteRndCharArray.WriteRndCharArray); int waitTime; //Write a random char[] asynchronously so we can verify some things while the write call is blocking Debug.WriteLine("Verifying Handshake=None"); com.Open(); t.Start(); waitTime = 0; while (t.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000) { //Wait for the thread to start System.Threading.Thread.Sleep(50); waitTime += 50; } //Wait for both write methods to timeout while (t.IsAlive) { System.Threading.Thread.Sleep(100); } Assert.Equal(0, com.BytesToWrite); } }
public void BytesToWriteSuccessive() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com, CHAR_SIZE_BYTES_TO_WRITE); var t1 = new Task(asyncWriteRndCharArray.WriteRndCharArray); var t2 = new Task(asyncWriteRndCharArray.WriteRndCharArray); Debug.WriteLine("Verifying BytesToWrite with successive calls to Write"); com.Handshake = Handshake.RequestToSend; com.Open(); com.WriteTimeout = 4000; //Write a random char[] asynchronously so we can verify some things while the write call is blocking t1.Start(); TCSupport.WaitForTaskToStart(t1); TCSupport.WaitForExactWriteBufferLoad(com, CHAR_SIZE_BYTES_TO_WRITE); //Write a random char[] asynchronously so we can verify some things while the write call is blocking t2.Start(); TCSupport.WaitForTaskToStart(t2); TCSupport.WaitForExactWriteBufferLoad(com, CHAR_SIZE_BYTES_TO_WRITE * 2); //Wait for both write methods to timeout TCSupport.WaitForTaskCompletion(t1); var aggregatedException = Assert.Throws <AggregateException>(() => TCSupport.WaitForTaskCompletion(t2)); Assert.IsType <IOException>(aggregatedException.InnerException); } }
public void BytesToWrite() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com, CHAR_SIZE_BYTES_TO_WRITE); Thread t = new Thread(asyncWriteRndCharArray.WriteRndCharArray); int waitTime = 0; Debug.WriteLine("Verifying BytesToWrite with one call to Write"); com.Handshake = Handshake.RequestToSend; com.Open(); com.WriteTimeout = 500; //Write a random char[] asynchronously so we can verify some things while the write call is blocking t.Start(); waitTime = 0; while (t.ThreadState == ThreadState.Unstarted && waitTime < 2000) { //Wait for the thread to start Thread.Sleep(50); waitTime += 50; } TCSupport.WaitForExactWriteBufferLoad(com, CHAR_SIZE_BYTES_TO_WRITE); //Wait for write method to timeout while (t.IsAlive) { Thread.Sleep(100); } } }
private bool BytesToWrite() { SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com, CHAR_SIZE_BYTES_TO_WRITE); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndCharArray.WriteRndCharArray)); bool retValue = true; int waitTime = 0; Console.WriteLine("Verifying BytesToWrite with one call to Write"); com.Handshake = Handshake.RequestToSend; com.Open(); com.WriteTimeout = 500; //Write a random char[] asynchronously so we can verify some things while the write call is blocking t.Start(); waitTime = 0; while (t.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000) { //Wait for the thread to start System.Threading.Thread.Sleep(50); waitTime += 50; } waitTime = 0; while (CHAR_SIZE_BYTES_TO_WRITE > com.BytesToWrite && waitTime < 500) { System.Threading.Thread.Sleep(50); waitTime += 50; } if (CHAR_SIZE_BYTES_TO_WRITE != com.BytesToWrite) { retValue = false; Console.WriteLine("ERROR!!! Expcted BytesToWrite={0} actual {1} after first write", CHAR_SIZE_BYTES_TO_WRITE, com.BytesToWrite); } //Wait for write method to timeout while (t.IsAlive) { System.Threading.Thread.Sleep(100); } if (com.IsOpen) { com.Close(); } if (!retValue) { Console.WriteLine("Err_007!!! Verifying BytesToWrite with one call to Write FAILED"); } return(retValue); }
public bool Handshake_None() { SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com, CHAR_SIZE_HANDSHAKE); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndCharArray.WriteRndCharArray)); bool retValue = true; int waitTime; //Write a random char[] asynchronously so we can verify some things while the write call is blocking Console.WriteLine("Verifying Handshake=None"); com.Open(); t.Start(); waitTime = 0; while (t.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000) { //Wait for the thread to start System.Threading.Thread.Sleep(50); waitTime += 50; } //Wait for both write methods to timeout while (t.IsAlive) { System.Threading.Thread.Sleep(100); } if (0 != com.BytesToWrite) { retValue = false; Console.WriteLine("ERROR!!! Expcted BytesToWrite=0 actual {0}", com.BytesToWrite); } if (!retValue) { Console.WriteLine("Err_009!!! Verifying Handshake=None FAILED"); } if (com.IsOpen) { com.Close(); } return(retValue); }
public void BytesToWrite() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com, CHAR_SIZE_BYTES_TO_WRITE); System.Threading.Thread t = new System.Threading.Thread(asyncWriteRndCharArray.WriteRndCharArray); int waitTime = 0; Debug.WriteLine("Verifying BytesToWrite with one call to Write"); com.Handshake = Handshake.RequestToSend; com.Open(); com.WriteTimeout = 500; //Write a random char[] asynchronously so we can verify some things while the write call is blocking t.Start(); waitTime = 0; while (t.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000) { //Wait for the thread to start System.Threading.Thread.Sleep(50); waitTime += 50; } waitTime = 0; while (CHAR_SIZE_BYTES_TO_WRITE > com.BytesToWrite && waitTime < 500) { System.Threading.Thread.Sleep(50); waitTime += 50; } if (CHAR_SIZE_BYTES_TO_WRITE != com.BytesToWrite) { Fail("ERROR!!! Expcted BytesToWrite={0} actual {1} after first write", CHAR_SIZE_BYTES_TO_WRITE, com.BytesToWrite); } //Wait for write method to timeout while (t.IsAlive) { System.Threading.Thread.Sleep(100); } } }
public void Handshake_None() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com, CHAR_SIZE_HANDSHAKE); var t = new Task(asyncWriteRndCharArray.WriteRndCharArray); //Write a random char[] asynchronously so we can verify some things while the write call is blocking Debug.WriteLine("Verifying Handshake=None"); com.Open(); t.Start(); TCSupport.WaitForTaskCompletion(t); Assert.Equal(0, com.BytesToWrite); } }
public void BytesToWrite() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com, CHAR_SIZE_BYTES_TO_WRITE); var t = new Task(asyncWriteRndCharArray.WriteRndCharArray); Debug.WriteLine("Verifying BytesToWrite with one call to Write"); com.Handshake = Handshake.RequestToSend; com.Open(); com.WriteTimeout = 500; //Write a random char[] asynchronously so we can verify some things while the write call is blocking t.Start(); TCSupport.WaitForTaskToStart(t); TCSupport.WaitForExactWriteBufferLoad(com, CHAR_SIZE_BYTES_TO_WRITE); TCSupport.WaitForTaskCompletion(t); } }
private void Verify_Handshake(Handshake handshake) { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName)) { AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com1, CHAR_SIZE_HANDSHAKE); System.Threading.Thread t = new System.Threading.Thread(asyncWriteRndCharArray.WriteRndCharArray); byte[] XOffBuffer = new byte[1]; byte[] XOnBuffer = new byte[1]; int waitTime = 0; XOffBuffer[0] = 19; XOnBuffer[0] = 17; Debug.WriteLine("Verifying Handshake={0}", handshake); com1.Handshake = handshake; com1.Open(); com2.Open(); //Setup to ensure write will bock with type of handshake method being used if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) { com2.RtsEnable = false; } if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake) { com2.Write(XOffBuffer, 0, 1); System.Threading.Thread.Sleep(250); } //Write a random char array asynchronously so we can verify some things while the write call is blocking t.Start(); waitTime = 0; while (t.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000) { //Wait for the thread to start System.Threading.Thread.Sleep(50); waitTime += 50; } waitTime = 0; while (CHAR_SIZE_HANDSHAKE > com1.BytesToWrite && waitTime < 500) { System.Threading.Thread.Sleep(50); waitTime += 50; } //Verify that the correct number of bytes are in the buffer if (CHAR_SIZE_HANDSHAKE != com1.BytesToWrite) { Fail("ERROR!!! Expcted BytesToWrite={0} actual {1}", CHAR_SIZE_HANDSHAKE, com1.BytesToWrite); } //Verify that CtsHolding is false if the RequestToSend or RequestToSendXOnXOff handshake method is used if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) && com1.CtsHolding) { Fail("ERROR!!! Expcted CtsHolding={0} actual {1}", false, com1.CtsHolding); } //Setup to ensure write will succeed if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) { com2.RtsEnable = true; } if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake) { com2.Write(XOnBuffer, 0, 1); } //Wait till write finishes while (t.IsAlive) { System.Threading.Thread.Sleep(100); } //Verify that the correct number of bytes are in the buffer Assert.Equal(0, com1.BytesToWrite); //Verify that CtsHolding is true if the RequestToSend or RequestToSendXOnXOff handshake method is used if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) && !com1.CtsHolding) { Fail("ERROR!!! Expcted CtsHolding={0} actual {1}", true, com1.CtsHolding); } } }
private void Verify_Handshake(Handshake handshake) { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName)) { AsyncWriteRndCharArray asyncWriteRndCharArray = new AsyncWriteRndCharArray(com1, CHAR_SIZE_HANDSHAKE); var t = new Task(asyncWriteRndCharArray.WriteRndCharArray); byte[] XOffBuffer = new byte[1]; byte[] XOnBuffer = new byte[1]; XOffBuffer[0] = 19; XOnBuffer[0] = 17; Debug.WriteLine("Verifying Handshake={0}", handshake); com1.Handshake = handshake; com1.Open(); com2.Open(); //Setup to ensure write will bock with type of handshake method being used if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) { com2.RtsEnable = false; } if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake) { com2.Write(XOffBuffer, 0, 1); Thread.Sleep(250); } //Write a random char array asynchronously so we can verify some things while the write call is blocking t.Start(); TCSupport.WaitForTaskToStart(t); TCSupport.WaitForExactWriteBufferLoad(com1, CHAR_SIZE_HANDSHAKE); //Verify that CtsHolding is false if the RequestToSend or RequestToSendXOnXOff handshake method is used if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) && com1.CtsHolding) { Fail("ERROR!!! Expcted CtsHolding={0} actual {1}", false, com1.CtsHolding); } //Setup to ensure write will succeed if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) { com2.RtsEnable = true; } if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake) { com2.Write(XOnBuffer, 0, 1); } TCSupport.WaitForTaskCompletion(t); //Verify that the correct number of bytes are in the buffer Assert.Equal(0, com1.BytesToWrite); //Verify that CtsHolding is true if the RequestToSend or RequestToSendXOnXOff handshake method is used if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) && !com1.CtsHolding) { Fail("ERROR!!! Expcted CtsHolding={0} actual {1}", true, com1.CtsHolding); } } }