Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / November 2004

Tip: Looking for answers? Try searching our database.

Serial port communications

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jacob - 20 Nov 2004 23:11 GMT
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.

Signature

Jacob.

Cor Ligthert - 21 Nov 2004 10:07 GMT
Jacob,

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

http://communities.microsoft.com/newsgroups/default.asp?icp=whidbey&slcid=us

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

I hope this helps something,

Cor

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.