Solved

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

Posted on 2010-11-15
3
939 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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