Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Created July 11, 2016 14:51
Show Gist options
  • Save ChrisMoney/5e83cb6e2dc4b870d60c1c88cc178967 to your computer and use it in GitHub Desktop.
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.
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