Solved

Increasing "priority" of serial port access in my VB.NET program

Posted on 2010-11-15
3
912 Views
Last Modified: 2012-05-10
So I have written a VB.NET program that controls hardware over a serial port, and receives feedback from the port, sometimes quickly.  I am using the System.IO.Ports.SerialPort class and handling the DataReceived event.

What I find is that the speed at which I receive these updates in my VB.NET program is not that fast, I'm trying to send 10-15 character messages at 30-40 hz, and I find that my VB.NET program itself is a bit of a bottleneck.  When I listen in hyperterminal I see every message at a smooth rate, but when I strip down my VB.NET program to just the port and counting the messages, the number tends to ebb and flow, be choppy, slow then fast,  like an internal queue is falling behind, catching up, etc.

Does anyone know any tricks to relieve the bottleneck, maybe give my System.IO.Ports.SerialPort  a higher priority or something?  Somehow hyperterminal achieves a snappiness on serial input that I am unable to achieve with a barebones VB.NET program.

Thanks for any thoughts...

0
Comment
Question by:riceman0
  • 2
3 Comments
 
LVL 8

Expert Comment

by:davesgonebananas
ID: 34138398
In the past I found VB6 was unable to handle critical timing and low level serial port communication so I resorted to writing those sections in C++.  

However, I would have thought VB.NET would be more responsive with it's direct access to the Serial API through System.IO.Ports.SerialPort.

Are you receiving from the serial port on a separate thread/
0
 

Author Comment

by:riceman0
ID: 34138432

Well, not sure -- just creating System.IO.Ports.SerialPort and handling the OnReceive event.  I guess this would be on the same thread?
0
 
LVL 8

Accepted Solution

by:
davesgonebananas earned 500 total points
ID: 34138817
OK.  According to the documentation:

PinChanged , DataReceived, and ErrorReceived events may be called out of order, and there may be a slight delay between when the underlying stream reports the error and when the event handler is executed. Only one event handler can execute at a time.

The DataReceived event is not guaranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the buffer.

The DataReceived event is raised on a secondary thread when data is received from the SerialPort object

You may find you get a more responsive app by using a dedicated thread to receive your data.  See the example at http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now