Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-15
3
Medium Priority
?
976 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 2000 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

Vim Reference Guide

Vim is a powerful text editor favored by many sysadmins and developers - here are some commands that you'll want to keep in your back pocket!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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