Solved

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

Posted on 2010-11-15
3
926 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 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