Accessing Serial Port (C#)
Posted on 2009-05-14
I am just beginning tinkering with serial ports and I have run across a strange problem. In the very beginning of my project I attempt to simply open the serial port, so I can begin listening to it. Here is the code:
private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
private void Form1_Load(object sender, EventArgs e)
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
This throws an excpetion on the "port.Open()" line that says:
The given port name does not start with COM/com or does not resolve to a valid serial port.
Parameter name: portName
I am running Windows Vista 32bit, and I have one hardware comport which is set to COM1. I have verified this through the device manager as well as through the following code:
foreach (string port in SerialPort.GetPortNames())
This method spits back only one string, and thats "COM1" without the quotes. I have also deleted all of my printers to ensure they were not causing an issue, but I still get the above exception. Anyone have any ideas what is causing this?