473,626 Members | 3,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Read Timeout 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...portna me and baud is the minimum to open
port. */
SerialPort sp = new SerialPort("COM 1",19200,Parity .None,8,StopBit s.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("S OMECMD");

/* 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 TimeoutExceptio ns; and 2) the reading operation should be done via
a delegate assigned to the SerialPort.Rece ivedEvent 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 2010
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
8824
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 to do: I want to connect only one button to my com port. If the button is pressed,
6
6974
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
2067
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
7903
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
15822
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 sure how to open serial port from VB. Can anyone give me a little light? Really appreciated,
0
2476
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 different hardware devices to transfer binary data to the application. The setup screen enables the user to select COM1 -- COM8 via combo boax for each port. Then they click "Apply" to open the ports. The code that I have written to open the...
1
338
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 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...
5
2325
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 problem is when we try to deploy it to another machine we receive: ACCESS IS DENIED TO COM1 PORT. We have tried unsuccessfully to get this to work. We have tried the following: 1) Assign the IUSR.... account to Administrators
5
9490
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 to opening the Serial Port and catching the associated exception? Thanks If there isn't a way to determine the Serial Port within .NET I would be willing, I guess, to use a WinAPI is that was the only way.
0
8269
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8203
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.