473,388 Members | 1,382 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,388 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 1981
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.