public MFTestResults GetSetReadTimeout() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.ReadTimeout, Timeout.Infinite); serialPort.ReadTimeout = 100; serialPort.Eval(serialPort.ReadTimeout, 100); serialPort.ReadTimeout = int.MinValue; serialPort.Eval(serialPort.ReadTimeout, int.MinValue); serialPort.ReadTimeout = int.MaxValue; serialPort.EvalOpenClose(serialPort.ReadTimeout, int.MaxValue); serialPort.ReadTimeout = 1000; serialPort.EvalOpenClose(serialPort.ReadTimeout, 1000); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public InitializeResult Initialize() { Log.Comment("Adding set up for the tests"); // Add your functionality here. portCount = HardwareProvider.HwProvider.GetSerialPortsCount(); if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3) //The Emulator on Windows Host { IsEmulator = true; } Debug.Print("IsEmulator: " + IsEmulator); // Test for loopback sendbuff = Encoding.UTF8.GetBytes(testString); Log.Comment("Port count: " + portCount); if (portCount > 0) { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.ReadTimeout = 1000; try { serialPort.VerifyWrite(testString); this.IsLoopback = true; } catch { Log.Comment("No loopback detected. Functional tests will not run"); } } } return(InitializeResult.ReadyToGo); }
public MFTestResults GetSetHandShake() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.Handshake, Handshake.None); serialPort.Handshake = Handshake.RequestToSend; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.RequestToSend); serialPort.Handshake = Handshake.XOnXOff; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.XOnXOff); } if (portCount > 0) { // Validate we can re-reserve all pins using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Handshake = Handshake.RequestToSend; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.RequestToSend); serialPort.Open(); } } // TODO: Write Desktop tests to validate proper function of RTS/XonXoff } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults VerifyValidChars() { if (!IsLoopback) { return(MFTestResults.Skip); } result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Open(); for (int i = 1; i < 255; i++) { string data = new string((char)i, 10); Log.FilteredComment("i = " + i + " chars: " + data); serialPort.VerifyWrite(data); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public InitializeResult Initialize() { Log.Comment("Adding set up for the tests"); // Add your functionality here. portCount = HardwareProvider.HwProvider.GetSerialPortsCount(); if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3) //The Emulator on Windows Host IsEmulator = true; Debug.Print("IsEmulator: " + IsEmulator); // Test for loopback sendbuff = Encoding.UTF8.GetBytes(testString); Log.Comment("Port count: " + portCount); if (portCount > 0) { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.ReadTimeout = 1000; try { serialPort.VerifyWrite(testString); this.IsLoopback = true; } catch { Log.Comment("No loopback detected. Functional tests will not run"); } } } return InitializeResult.ReadyToGo; }
public MFTestResults AdvancedGetSetTest() { if (!IsLoopback) { return(MFTestResults.Skip); } result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { // Exercise changing rate while open if port is available serialPort.VerifyWrite(); Log.Comment("Change baud and resend"); serialPort.BaudRate = (int)BaudRate.Baudrate19200; serialPort.VerifyWrite(); Log.Comment("Change Parity and resend"); serialPort.Parity = Parity.Even; serialPort.VerifyWrite(); Log.Comment("Change StopBit and resend"); serialPort.StopBits = StopBits.Two; serialPort.VerifyWrite(); Log.Comment("Change DataBits and resend"); serialPort.DataBits = 7; serialPort.VerifyWrite(); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults GetBytesToWrite() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.BytesToWrite, 0); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults LargeSendBuffer() { if (!IsLoopback) { return(MFTestResults.Skip); } result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Handshake = Handshake.RequestToSend; serialPort.Open(); serialPort.AsyncRead = true; string start = MFUtilities.GetRandomSafeString(10000); byte[] buff = Encoding.UTF8.GetBytes(start); serialPort.Write(buff, 0, buff.Length); // wait for data to drain while (serialPort.AsyncResult.Length < start.Length && (serialPort.BytesToWrite > 0 || serialPort.BytesToRead > 0)) { Thread.Sleep(100); } if (serialPort.AsyncResult != start) { Log.Exception("Failed: " + serialPort.AsyncResult + " != " + start); result = MFTestResults.Fail; } // wait to make sure AsyncReader is closed; serialPort.AsyncRead = false; while (serialPort.IsAsyncReading) { Thread.Sleep(100); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults GetSetStopBits() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.StopBits, StopBits.One); serialPort.StopBits = StopBits.Two; serialPort.EvalOpenClose(serialPort.StopBits, StopBits.Two); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults GetSetBaudRate() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.BaudRate, (int)BaudRate.Baudrate9600); serialPort.BaudRate = (int)BaudRate.Baudrate230400; serialPort.Eval(serialPort.BaudRate, (int)BaudRate.Baudrate230400); serialPort.BaudRate = (int)BaudRate.Baudrate19200; serialPort.EvalOpenClose(serialPort.BaudRate, (int)BaudRate.Baudrate19200); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults GetSetParity() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.Parity, Parity.None); serialPort.Parity = Parity.Even; serialPort.Eval(serialPort.Parity, Parity.Even); serialPort.Parity = Parity.Odd; serialPort.EvalOpenClose(serialPort.Parity, Parity.Odd); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults GetPortName() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.PortName, Serial.COM1); } if (portCount > 1) { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM2)) { serialPort.Eval(serialPort.PortName, Serial.COM2); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults GetSetBaudRate() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.BaudRate, (int)BaudRate.Baudrate9600); serialPort.BaudRate = (int)BaudRate.Baudrate230400; serialPort.Eval(serialPort.BaudRate, (int)BaudRate.Baudrate230400); serialPort.BaudRate = (int)BaudRate.Baudrate19200; serialPort.EvalOpenClose(serialPort.BaudRate, (int)BaudRate.Baudrate19200); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetSetParity() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.Parity, Parity.None); serialPort.Parity = Parity.Even; serialPort.Eval(serialPort.Parity, Parity.Even); serialPort.Parity = Parity.Odd; serialPort.EvalOpenClose(serialPort.Parity, Parity.Odd); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetSetStopBits() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.StopBits, StopBits.One); serialPort.StopBits = StopBits.Two; serialPort.EvalOpenClose(serialPort.StopBits, StopBits.Two); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetSetHandShake() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.Handshake, Handshake.None); serialPort.Handshake = Handshake.RequestToSend; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.RequestToSend); serialPort.Handshake = Handshake.XOnXOff; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.XOnXOff); } if (portCount > 0) { // Validate we can re-reserve all pins using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Handshake = Handshake.RequestToSend; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.RequestToSend); serialPort.Open(); } } // TODO: Write Desktop tests to validate proper function of RTS/XonXoff } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetSetWriteTimeout() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.WriteTimeout, Timeout.Infinite); serialPort.WriteTimeout = 100; serialPort.Eval(serialPort.WriteTimeout, 100); serialPort.WriteTimeout = int.MinValue; serialPort.Eval(serialPort.WriteTimeout, int.MinValue); serialPort.WriteTimeout = int.MaxValue; serialPort.EvalOpenClose(serialPort.WriteTimeout, int.MaxValue); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetPortName() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.PortName, Serial.COM1); } if (portCount > 1) { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM2)) { serialPort.Eval(serialPort.PortName, Serial.COM2); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetBytesToWrite() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.BytesToWrite, 0); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults LargeSendBuffer() { if (!IsLoopback) return MFTestResults.Skip; result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Handshake = Handshake.RequestToSend; serialPort.Open(); serialPort.AsyncRead = true; string start = MFUtilities.GetRandomSafeString(10000); byte[] buff = Encoding.UTF8.GetBytes(start); serialPort.Write(buff, 0, buff.Length); // wait for data to drain while (serialPort.AsyncResult.Length < start.Length && (serialPort.BytesToWrite > 0 || serialPort.BytesToRead > 0)) { Thread.Sleep(100); } if (serialPort.AsyncResult != start) { Log.Exception("Failed: " + serialPort.AsyncResult + " != " + start); result = MFTestResults.Fail; } // wait to make sure AsyncReader is closed; serialPort.AsyncRead = false; while (serialPort.IsAsyncReading) { Thread.Sleep(100); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults VerifyValidChars() { if (!IsLoopback) return MFTestResults.Skip; result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Open(); for (int i = 1; i < 255; i++) { string data = new string((char)i, 10); Log.FilteredComment("i = " + i + " chars: " + data); serialPort.VerifyWrite(data); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults AdvancedGetSetTest() { if (!IsLoopback) return MFTestResults.Skip; result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { // Exercise changing rate while open if port is available serialPort.VerifyWrite(); Log.Comment("Change baud and resend"); serialPort.BaudRate = (int)BaudRate.Baudrate19200; serialPort.VerifyWrite(); Log.Comment("Change Parity and resend"); serialPort.Parity = Parity.Even; serialPort.VerifyWrite(); Log.Comment("Change StopBit and resend"); serialPort.StopBits = StopBits.Two; serialPort.VerifyWrite(); Log.Comment("Change DataBits and resend"); serialPort.DataBits = 7; serialPort.VerifyWrite(); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }