473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Serial port communications

Has anyone successfully received serial communications from a COM port/RS232C
device? It's easy to connect and write to a serial device with Framework 2.0,
but when I try to read from the input buffer I get nothing except a timeout
exception. No matter how high you set the SerialPort.ReadTimeout property it
doesn't seem to matter. My code (using C# for Framework 2.0) looks something
like this:

use System.IO.Ports;
public static void Main (string[] args) {

/* Fully specified port params...portname and baud is the minimum to open
port. */
SerialPort sp = new SerialPort("COM1",19200,Parity.None,8,StopBits.One );
sp.Open();
sp.NewLine = "\n"; /* set the new line char for input and output so that
Write/ReadLine functions correctly interpret end of data. */
sp.ReadTimeout = 2000; /* set time out to 2 seconds. */
sp.WriteLine("SOMECMD");

/* synchronous call to read incoming data from serial port. */
string incomingData = sp.ReadLine();
sp.Close();
}

Only thing that seems to happen here is that ReadLine times out after
waiting however long you've told it to wait in the ReadTimeout property even
though I KNOW for a fact data is coming back from the serial device (verified
w/HyperTerminal and another app). Two things about the short little code
snippet is that 1) ReadLine should be wrapped in a try/catch as you will
surely get TimeoutExceptions; and 2) the reading operation should be done via
a delegate assigned to the SerialPort.ReceivedEvent event so that read/write
operations are asynchronous. Unfortunately the VS05 documentation appears to
be missing for this event so I don't have that code working just yet.

--
Jacob.
Jul 21 '05 #1
1 1974
Jacob,

Did you know that for the Framework 2.0 are special newsgroups.

http://communities.microsoft.com/new...idbey&slcid=us

I think there you will quicker your answer because there are more beta
testers.

I hope this helps something,

Cor
Jul 21 '05 #2

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

Similar topics

1
by: Andreas Horneff | last post by:
Hi @ all, I've got a problem with serial communication in Borland C++ Builder. I've already found a lot of stuff about serial communication in the internet, but it dosen't work. What I want...
6
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
10
by: Jim H | last post by:
I need to communicate using a serial port. Are there any classes or libraries for this in .NET? If not are there any open source libraries for this out there? jim
3
by: Ramakant Kasar | last post by:
Hi, If an application is reading data from a serial port, How can I open the same serial port with another application? Any idea? Please help. Thanks, Ramakant K.
4
by: Ben Zhu | last post by:
I have a small project, which need use both RS232 port and excel for data plot. I considering use excel VB macro for the entire project. Although I used serial port extensively in MFC, I am not...
0
by: David | last post by:
I am having trouble with "ACCESS DENIED" error messages in a VB.NET 2003 application when attempting to open serial comms ports. The application has 2 ports that connect via serial cable to 2...
1
by: Jacob | last post by:
Has anyone successfully received serial communications from a COM port/RS232C device? It's easy to connect and write to a serial device with Framework 2.0, but when I try to read from the input...
5
by: Franklin M. Gauer III | last post by:
Hi All, I've written an ASP.NET application (webservice) that does simple serial communications via the .NET 2.0 SerialComm object. The application runs fine on my development machine. The...
5
by: LongBow | last post by:
Hello, Is there a way, in .NET, to determine what are the avialable Serial (Communications) Ports on a Windows OS and is there a way to determine that port isn't being use other than attempting...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.