New serialport in VS 2005

G

Guest

I am trying to read data from com1 and I am using the new serialport control.
I downloaded the script from microsoft that does a readline from the comm
port, but I keep getting the "operation timed out" error. I then will open
up HyperTerminal and connect and the output then displays? The arguments
appear to match up between my serialport control and what is setup in
HyperTerminal. Any help would be appreciated.
Thanks.

using System;
using System.IO.Ports;

class Sample
{
public static void Main()
{
string input;

SerialPort sp = new SerialPort("COM1", 9600, Parity.None, 8,
StopBits.One);
try
{
sp.ReadTimeout = 20000;

sp.Open();

input = sp.ReadLine();

Console.WriteLine(input);
Console.ReadLine();
}

catch (TimeoutException e)
{
Console.WriteLine(e);
Console.ReadLine();
}
finally
{
sp.Close();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top