New serialport in VS 2005

  • Thread starter Thread starter Guest
  • Start date Start date
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();
}
}
}
 
Back
Top