Created
November 22, 2014 19:42
-
-
Save corytodd/77d4169839b4902e8cbc to your computer and use it in GitHub Desktop.
Test MS Virtual Serial Port driver sample
This file contains 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; | |
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