Created
July 11, 2016 14:51
-
-
Save ChrisMoney/5e83cb6e2dc4b870d60c1c88cc178967 to your computer and use it in GitHub Desktop.
Unit Test Serial Port: Find which Serial port is open to test a piece of hardware.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO.Ports; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using CardDispenser; | |
namespace CardDispenserTests | |
{ | |
[TestClass] | |
public class CardDispenerTests | |
{ | |
private SerialPort GetSp() | |
{ | |
// try COM1 | |
string port = "COM1"; | |
var sp = new SerialPort(port, 9600, Parity.None, 8, StopBits.One); | |
// try COM2 | |
if (!sp.IsOpen) | |
{ | |
port = "COM2"; | |
} | |
sp = new SerialPort(port, 9600, Parity.None, 8, StopBits.One); | |
// try COM3 | |
if (!sp.IsOpen) | |
{ | |
port = "COM3"; | |
} | |
sp = new SerialPort(port, 9600, Parity.None, 8, StopBits.One); | |
// try COM4 | |
if (!sp.IsOpen) | |
{ | |
port = "COM3"; | |
} | |
sp = new SerialPort(port, 9600, Parity.None, 8, StopBits.One); | |
return sp; | |
} | |
[TestMethod] | |
public void ResetTest() | |
{ | |
//// run test app to determine port. This test is looking for Comport 3 | |
SerialPort sp = GetSp(); | |
IMD1000A imd1000A = new MD1000ADriver(); | |
MD1000AHelper.Reset(imd1000A, ResetAction.Capture_Card, sp); | |
Assert.AreEqual((Int32)ResetAction.Capture_Card, 49); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment