public void DiscardNull_false_flase_Default_ReadByte() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying default DiscardNull with ReadByte"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); com1.DiscardNull = false; com1.DiscardNull = false; serPortProp.SetProperty("DiscardNull", false); serPortProp.VerifyPropertiesAndPrint(com1); VerifyDiscardNull(com1, ReadByte, false); serPortProp.VerifyPropertiesAndPrint(com1); } }
private void VerifyStopBitsBeforeOpen(int stopBits, int dataBits) { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.DataBits = dataBits; com1.StopBits = (StopBits)stopBits; com1.Open(); serPortProp.SetProperty("DataBits", dataBits); serPortProp.SetProperty("StopBits", (StopBits)stopBits); serPortProp.VerifyPropertiesAndPrint(com1); VerifyStopBits(com1); serPortProp.VerifyPropertiesAndPrint(com1); } }
public void BreakState_false() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying false BreakState"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); SetBreakStateandVerify(com1); serPortProp.SetProperty("BreakState", false); com1.BreakState = false; serPortProp.VerifyPropertiesAndPrint(com1); Assert.False(GetCurrentBreakState()); } }
public void Parity_Odd_Even() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying Parity Odd and then Even"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); com1.Parity = Parity.Odd; com1.Parity = Parity.Even; serPortProp.SetProperty("Parity", Parity.Even); serPortProp.VerifyPropertiesAndPrint(com1); VerifyParity(com1, DEFAULT_BYTE_SIZE); serPortProp.VerifyPropertiesAndPrint(com1); } }
public void BaseStream_Default() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying default BaseStream"); serPortProp.SetAllPropertiesToDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.VerifyPropertiesAndPrint(com1); } }
private void VerifyCtor(string portName, int baudRate, int parity, int dataBits, Type expectedException, ThrowAt throwAt) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying properties where PortName={0},BaudRate={1},Parity={2},DatBits={3}", portName, baudRate, parity, dataBits); try { using (SerialPort com = new SerialPort(portName, baudRate, (Parity)parity, dataBits)) { if (null != expectedException && throwAt == ThrowAt.Set) { Fail("Err_7212ahsdj Expected Ctor to throw {0}", expectedException); } serPortProp.SetAllPropertiesToDefaults(); serPortProp.SetProperty("PortName", portName); serPortProp.SetProperty("BaudRate", baudRate); serPortProp.SetProperty("Parity", (Parity)parity); serPortProp.SetProperty("DataBits", dataBits); serPortProp.VerifyPropertiesAndPrint(com); } } catch (Exception e) { if (null == expectedException) { Fail("Err_07081hadnh Did not expect exception to be thrown and the following was thrown: \n{0}", e); } else if (throwAt == ThrowAt.Open) { Fail("Err_88916adfa Expected {0} to be thrown at Open and the following was thrown at Set: \n{1}", expectedException, e); } else if (e.GetType() != expectedException) { Fail("Err_90282ahwhp Expected {0} to be thrown and the following was thrown: \n{1}", expectedException, e); } } }
public bool CtsHolding_true_false() { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; Console.WriteLine("Verifying CtsHolding=true then false on com1 when com2.RtsEnable=true then false"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("CtsHolding", true); com1.Open(); com2.Open(); com2.RtsEnable = true; retValue &= serPortProp.VerifyPropertiesAndPrint(com1); com2.RtsEnable = false; serPortProp.SetProperty("CtsHolding", false); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (!retValue) { Console.WriteLine("Err_004!!! Verifying CtsHolding=true then false on com1 when com2.RtsEnable=true then false FAILED"); } if (com1.IsOpen) { com1.Close(); } if (com2.IsOpen) { com2.Close(); } return(retValue); }
public void VerifyInfiniteTimeout(Action <SerialPort> readMethod, bool setInfiniteTimeout) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { SerialPortProperties serPortProp = new SerialPortProperties(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("WriteTimeout", 10); com1.WriteTimeout = 10; com1.Open(); serPortProp.VerifyPropertiesAndPrint(com1); if (!com2.IsOpen) { com2.Open(); } if (setInfiniteTimeout) { com1.ReadTimeout = 500; com1.ReadTimeout = SerialPort.InfiniteTimeout; } Task task = Task.Run(() => readMethod(com1)); System.Threading.Thread.Sleep(DEFAULT_WAIT_INFINITE_TIMEOUT); Assert.True(!task.IsCompleted); serPortProp.VerifyPropertiesAndPrint(com1); com2.WriteLine(string.Empty); TCSupport.WaitForTaskCompletion(task); } }
private bool VerifyExceptionAfterOpen(SerialPort com, int baudRate, System.Type expectedException) { bool retValue = true; SerialPortProperties serPortProp = new SerialPortProperties(); com.Open(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); try { com.BaudRate = baudRate; if (null != expectedException) { Console.WriteLine("ERROR!!! Expected setting the BaudRate after Open() to throw {0} and nothing was thrown", expectedException); retValue = false; } else { serPortProp.SetProperty("BaudRate", baudRate); } } catch (System.Exception e) { if (null == expectedException) { Console.WriteLine("ERROR!!! Expected setting the BaudRate after Open() NOT to throw an exception and {0} was thrown", e.GetType()); retValue = false; } else if (e.GetType() != expectedException) { Console.WriteLine("ERROR!!! Expected setting the BaudRate after Open() throw {0} and {1} was thrown", expectedException, e.GetType()); retValue = false; } } retValue &= serPortProp.VerifyPropertiesAndPrint(com); return(retValue); }
public void RtsEnable_true_false_BeforeOpen() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying seting RtsEnable to true then false before open"); com1.RtsEnable = true; serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("RtsEnable", false); com1.RtsEnable = false; com1.Open(); serPortProp.VerifyPropertiesAndPrint(com1); VerifyRtsEnable(com1); serPortProp.VerifyPropertiesAndPrint(com1); } }
public bool DataBits_8_StopBitsOnePointFive() { SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); bool retValue = true; SerialPortProperties serPortProp = new SerialPortProperties(); Console.WriteLine("Verifying setting DataBits=8 from 5 with StopBits=1.5"); com.DataBits = 5; com.StopBits = StopBits.OnePointFive; com.Open(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("StopBits", StopBits.OnePointFive); serPortProp.SetProperty("DataBits", 5); try { com.DataBits = 8; Console.WriteLine("ERROR!!! Setting DataBits did not thow an exception"); retValue = false; } catch (System.IO.IOException) { } catch (System.Exception e) { Console.WriteLine("ERROR!!! Expected IOException and {0} was thrown", e.GetType()); retValue = false; } retValue &= serPortProp.VerifyPropertiesAndPrint(com); if (!retValue) { Console.WriteLine("Err_018!!! Verifying setting DataBits=8 from 5 with StopBits=1.5 FAILED"); } return(retValue); }
public void DsrHolding_true() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying DsrHolding=true on com1 when com2.DtrEnable=true"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("DsrHolding", true); com1.Open(); com2.Open(); com2.DtrEnable = true; serPortProp.SetProperty("CDHolding", com1.CDHolding); //We dont care what this is set to since some serial cables loop CD to CTS serPortProp.VerifyPropertiesAndPrint(com1); } }
public void BytesToRead_RcvRndNumBytes() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying BytesToRead after receiving a random number of bytes"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); com2.Open(); com2.Write(new byte[DEFAULT_NUM_RND_BYTES], 0, DEFAULT_NUM_RND_BYTES); serPortProp.SetProperty("BytesToRead", DEFAULT_NUM_RND_BYTES); Thread.Sleep(100); //Wait for com1 to get all of the bytes serPortProp.VerifyPropertiesAndPrint(com1); } }
public void DataBits_8_StopBitsOnePointFive() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying setting DataBits=8 from 5 with StopBits=1.5"); com.DataBits = 5; com.StopBits = StopBits.OnePointFive; com.Open(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("StopBits", StopBits.OnePointFive); serPortProp.SetProperty("DataBits", 5); Assert.Throws <IOException>(() => com.DataBits = 8); serPortProp.VerifyPropertiesAndPrint(com); } }
public bool BytesToRead_RcvRndNumBytes() { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; Console.WriteLine("Verifying BytesToRead after receiving a random number of bytes"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); com2.Open(); com2.Write(new byte[DEFUALT_NUM_RND_BYTES], 0, DEFUALT_NUM_RND_BYTES); serPortProp.SetProperty("BytesToRead", DEFUALT_NUM_RND_BYTES); System.Threading.Thread.Sleep(100);//Wait for com1 to get all of the bytes retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (!retValue) { Console.WriteLine("Err_002!!! Verifying BytesToRead after receiving a random number of bytes FAILED"); } if (com1.IsOpen) { com1.Close(); } if (com2.IsOpen) { com2.Close(); } return(retValue); }
public void OpenFillBuffersClose() { using (var com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) using (var com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Calling Open(), fill both trasmit and receive buffers, call Close()"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); // Setting com1 to use Handshake so we can fill read buffer com1.Handshake = Handshake.RequestToSend; com1.Open(); com2.Open(); // BeginWrite is used so we can fill the read buffer then go onto to verify com1.BaseStream.BeginWrite(new byte[numWriteBytes], 0, numWriteBytes, null, null); com2.Write(new byte[numReadBytes], 0, numReadBytes); Thread.Sleep(500); serPortProp.SetProperty("Handshake", Handshake.RequestToSend); serPortProp.SetProperty("BytesToWrite", numWriteBytes); serPortProp.SetProperty("BytesToRead", numReadBytes); Debug.WriteLine("Verifying properties after port is open and bufferes have been filled"); serPortProp.VerifyPropertiesAndPrint(com1); com1.Handshake = Handshake.None; com1.BaseStream.Close(); serPortProp.SetAllPropertiesToDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); Debug.WriteLine("Verifying properties after port has been closed"); serPortProp.VerifyPropertiesAndPrint(com1); com1.Open(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); Debug.WriteLine("Verifying properties after port has been opened again"); serPortProp.VerifyPropertiesAndPrint(com1); try { if (com1.IsOpen) { com1.Close(); } } catch (Exception) { } } // Give the port time to finish closing since we potentially have an unclosed BeginRead/BeginWrite Thread.Sleep(200); }
public void ParityReplace_Default_AfterOpen() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying default ParityReplace after Open"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); serPortProp.VerifyPropertiesAndPrint(com1); } }
private bool VerifyBaudRateAfterOpen(int baudRate) { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; serPortProp.SetAllPropertiesToOpenDefaults(); com1.Open(); com1.BaudRate = baudRate; serPortProp.SetProperty("BaudRate", baudRate); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); retValue &= VerifyBaudRate(com1); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (com1.IsOpen) { com1.Close(); } return(retValue); }
public bool DsrHolding_true() { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; Console.WriteLine("Verifying DsrHolding=true on com1 when com2.DtrEnable=true"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("DsrHolding", true); com1.Open(); com2.Open(); com2.DtrEnable = true; serPortProp.SetProperty("CDHolding", com1.CDHolding); //We dont care what this is set to since some serial cables loop CD to CTS retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (!retValue) { Console.WriteLine("Err_003!!! Verifying DsrHolding=true on com1 when com2.DtrEnable=true FAILED"); } if (com1.IsOpen) { com1.Close(); } if (com2.IsOpen) { com2.Close(); } return(retValue); }
private void VerifyInfiniteTimeout(WriteMethodDelegate writeMethod, bool setInfiniteTimeout) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) { 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; } Task task = Task.Run(() => writeMethod(com1)); Thread.Sleep(DEFAULT_WAIT_INFINITE_TIMEOUT); Assert.False(task.IsCompleted, "Task should not have completed while tx is blocked by flow-control"); com1.Handshake = Handshake.None; TCSupport.WaitForTaskCompletion(task); com1.DiscardOutBuffer(); // If we're looped-back, then there will be data queued on the receive side which we need to discard com1.DiscardInBuffer(); serPortProp.VerifyPropertiesAndPrint(com1); } }
public bool BreakState_true_false() { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; Console.WriteLine("Verifying setting BreakState to true then false"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); retValue &= SetBreakStateandVerify(com1); serPortProp.SetProperty("BreakState", true); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); serPortProp.SetProperty("BreakState", false); com1.BreakState = false; retValue &= serPortProp.VerifyPropertiesAndPrint(com1); retValue &= !GetCurrentBreakState(); if (!retValue) { Console.WriteLine("Err_004!!! Verifying setting BreakState to true then false FAILED"); } if (com1.IsOpen) { com1.Close(); } return(retValue); }
public void OpenClose() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Calling Close() after calling Open()"); com.Open(); com.Close(); serPortProp.SetAllPropertiesToDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.VerifyPropertiesAndPrint(com); } }
public void BreakState_BeforeOpen() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying setting BreakState before open"); serPortProp.SetAllPropertiesToDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); Assert.Throws <InvalidOperationException>(() => com1.BreakState = true); serPortProp.VerifyPropertiesAndPrint(com1); } }
private bool VerifyEncodingAfterOpen(System.Text.Encoding encoding) { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); com1.Encoding = encoding; serPortProp.SetProperty("Encoding", encoding); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); retValue &= VerifyEncoding(com1); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (com1.IsOpen) { com1.Close(); } return(retValue); }
private bool VerifyParityAfterOpen(int parity, int numBytesToSend) { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); com1.Parity = (Parity)parity; serPortProp.SetProperty("Parity", (Parity)parity); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); retValue &= VerifyParity(com1, numBytesToSend); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (com1.IsOpen) { com1.Close(); } return(retValue); }
private bool VerifyRtsEnableBeforeOpen(bool rtsEnable) { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.RtsEnable = rtsEnable; com1.Open(); serPortProp.SetProperty("RtsEnable", rtsEnable); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); retValue &= VerifyRtsEnable(com1); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (com1.IsOpen) { com1.Close(); } return(retValue); }
public void CtsHolding_true_false() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying CtsHolding=true then false on com1 when com2.RtsEnable=true then false"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); serPortProp.SetProperty("CtsHolding", true); com1.Open(); com2.Open(); com2.RtsEnable = true; serPortProp.VerifyPropertiesAndPrint(com1); com2.RtsEnable = false; serPortProp.SetProperty("CtsHolding", false); serPortProp.VerifyPropertiesAndPrint(com1); } }
public void IsOpen_Open() { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); Debug.WriteLine("Verifying IsOpen after Open() has been called"); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); serPortProp.VerifyPropertiesAndPrint(com1); } }
public void OpenDefault() { using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) { SerialPortProperties serPortProp = new SerialPortProperties(); com.Open(); serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); Debug.WriteLine("BytesToWrite={0}", com.BytesToWrite); serPortProp.VerifyPropertiesAndPrint(com); } }
private bool VerifyDiscardNullAfterOpen(bool discardNull, ReadMethodDelegate readMethod, bool sendNewLine) { SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); SerialPortProperties serPortProp = new SerialPortProperties(); bool retValue = true; serPortProp.SetAllPropertiesToOpenDefaults(); serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName); com1.Open(); com1.DiscardNull = discardNull; serPortProp.SetProperty("DiscardNull", discardNull); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); retValue &= VerifyDiscardNull(com1, readMethod, sendNewLine); retValue &= serPortProp.VerifyPropertiesAndPrint(com1); if (com1.IsOpen) { com1.Close(); } return(retValue); }