Help with SerialPort and C#

A

Andrea Judge

Hi there,

I'm developing an application to catch OBD sensors' data from my car.
I connect it via a RS232 interface.
Now.
with HyperTerminal I can connect and send/receive data, but I'd like to do
this from inside my C# program.
Anyone can write down a very small (or tell how to do it myself) application
containing methods like WriteToSerialPort(string what) and
ReadFromSerialPort(what).

Using the built in control SerialPort, I can correctly open a port, and
write something to it (commands like "ATX" and other worked fine from
HyperTerminal), but I can't read nothing, using SerialPort.ReadLine(). This
method always generates a Timeout exception.

What's wrong?
To send, for example, the "ATX" command through the serial port, I use
SerialPort.Write("ATX"), but nothing seems to happen.

Hope someone will help me soon!!!


Andrea
 
A

Ales

Hi,
you should use SerialPort.ReadLine() when you recive DataReceived
event. If no event is triggered then you didn't recive any data.

Try to send SerialPort.WriteLine("ATX") or SerialPort.Write("ATX\r").

Ales

Andrea Judge je napisal:
 
O

ozbear

Hi there,

I'm developing an application to catch OBD sensors' data from my car.
I connect it via a RS232 interface.
Now.
with HyperTerminal I can connect and send/receive data, but I'd like to do
this from inside my C# program.
Anyone can write down a very small (or tell how to do it myself) application
containing methods like WriteToSerialPort(string what) and
ReadFromSerialPort(what).

Using the built in control SerialPort, I can correctly open a port, and
write something to it (commands like "ATX" and other worked fine from
HyperTerminal), but I can't read nothing, using SerialPort.ReadLine(). This
method always generates a Timeout exception.

What's wrong?
To send, for example, the "ATX" command through the serial port, I use
SerialPort.Write("ATX"), but nothing seems to happen.

Hope someone will help me soon!!!


Andrea

Send a carriage return along with your command string.

Oz
 

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