Skip to content

Instantly share code, notes, and snippets.

@corytodd
Created November 22, 2014 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corytodd/77d4169839b4902e8cbc to your computer and use it in GitHub Desktop.
Save corytodd/77d4169839b4902e8cbc to your computer and use it in GitHub Desktop.
Test MS Virtual Serial Port driver sample
using System;
using System.IO.Ports;
namespace VCPTest
{
class Program
{
static bool _continue;
static SerialPort _serialPort;
public static void Main()
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
_serialPort.DataReceived += _serialPort_DataReceived;
// These are the settings that work in Putty serial
_serialPort.PortName = "COM25";
_serialPort.BaudRate = 9600;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.XOnXOff;
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
_continue = true;
Console.WriteLine("Type QUIT to exit");
while (_continue)
{
message = Console.ReadLine();
if (stringComparer.Equals("quit", message))
{
_continue = false;
}
else
{
_serialPort.WriteLine(message);
}
}
_serialPort.Close();
}
// This event never fires
private static void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
throw new NotImplementedException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment