Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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