Writing serial port does not work

N

Nasif

Currently I am writing a program which sends and receives messages
through serial port to a device. I am using C# and Microsoft Visual
studio 2005 for windows program. But my problem is when i try to write
in serial port from my windows a Timeoutexception is thrown. I use
SerialPort class in System.IO.Ports and for writing port i used
write() function under the built in class SerialPort. But when i use
hyperterminal , everything goes fine.

Can anyone say how can i overcome this problem?

Another thing , I have used SerialPort.GetPortNames() to get the list
of serial ports. But sometimes the list of serial ports that is
returned by this method is not same as the list of serial ports shown
in device manager.(Currently SerialPort.GetPortNames() return COM1
and COM3 but no existence of COM3 in device manager) Which method can
i use to get the actual list of serial ports?

Thanks in advance
Nasif Bin Shafi
 
M

Michael A. Covington

I don't understand the whole situation, but remember that if your computer
has an internal modem, that occupies one of the serial ports. You may be
using the wrong serial port.

The other thing to be aware of is the connection of CTS, DSR, etc. (the
various "ready" signals). Either loop them back properly or tell the
software to ignore them.
 
B

bob clegg

Currently I am writing a program which sends and receives messages
through serial port to a device. I am using C# and Microsoft Visual
studio 2005 for windows program. But my problem is when i try to write
in serial port from my windows a Timeoutexception is thrown. I use
SerialPort class in System.IO.Ports and for writing port i used
write() function under the built in class SerialPort. But when i use
hyperterminal , everything goes fine.

Can anyone say how can i overcome this problem?

Another thing , I have used SerialPort.GetPortNames() to get the list
of serial ports. But sometimes the list of serial ports that is
returned by this method is not same as the list of serial ports shown
in device manager.(Currently SerialPort.GetPortNames() return COM1
and COM3 but no existence of COM3 in device manager) Which method can
i use to get the actual list of serial ports?

Thanks in advance
Nasif Bin Shafi

Hi Nasif,
You 100% sure you are opening the port correctly before trying the
write?
i.e.
The following works for me, admittedly the com port is not connected
to anything.
private void button1_Click(object sender, EventArgs e)
{
SerialPort s = new SerialPort("Com1", 9600, Parity.None,
7, StopBits.One);
s.Open();
s.Write("HelloWorld");
s.Close();
s.Dispose();
}
 

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