By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,784 Members | 3,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,784 IT Pros & Developers. It's quick & easy.

Writing serial port does not work

P: n/a
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

Nov 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Nov 11 '07 #2

P: n/a
On Sun, 11 Nov 2007 12:38:07 -0000, Nasif <na*******@gmail.comwrote:
>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();
}
Nov 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.