472,954 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

Help with SerialPort and C#

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
Dec 22 '05 #1
2 13387
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:
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


Dec 30 '05 #2
On Thu, 22 Dec 2005 18:32:27 +0100, "Andrea Judge"
<ju***@SPAMNOGRAZIEarea51staff.it> wrote:
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
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 30 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Joshua Moore | last post by:
I'm trying to convert from a lot of invoked code to c# 2.0 SerialPort code. I can't find a way to set fOutxCtsFlow to true (maybe CTSEnable?) and fRtsControl = RTS_CONTROL_HANDSHAKE (RtsEnable?). ...
2
by: Eric | last post by:
I'm trying to send a text message via my cell phone using the .net 2.0 SerialPort object. The command to send a text message requires a newline "\n" and a ctrl-z command to be entered. I've tried...
13
by: Jean Paul Mertens | last post by:
Hello, Someone can tell me why I dont get serial port events in a Service, I created a separate Thread to open the port but no events are coming up (the same happens when I use the timer...
0
by: ricolee99 | last post by:
Hi Everyone, I'm using the System.IO.Ports.SerialPort component to attempt to kill an existing component opened by another application. I use the following code: SerialPort serialPort = new...
2
by: Jay | last post by:
Extracted from the C# example in http://msdn2.microsoft.com/en-us/library/s14dyf47.aspx... public static void Main() { string name; string message; StringComparer stringComparer =...
3
by: Adriano | last post by:
Hello, I'm developing an application in VB.NET 2005 that communicates with a device through RS232, and need to send the following sequence of hexadecimal data to the device: 0xFF, 0x01, 0xC3,...
6
by: Keith Lee | last post by:
All: I am attempting to compile the perl module Device::SerialPort and get this error during make -- Manifying blib/man3/Device::SerialPort.3pm Can't open blib/man3/Device::SerialPort.3pm for...
2
by: Benedictum | last post by:
I have the following method that initializes the port. I am having problems assigning values to the Serial port properties. Can someone help ? Here is the snippet with my comments: private void...
0
by: cronusf | last post by:
I set up two virtual COM ports 3 and 4 using com0com. I tried to test it with the following program. However, the DataReceived event handlers never get called. Can anyone with SerialPort class...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.