473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Monitoring two serial ports

Hello.
I am trying to produce a pc-program that can monitor the rx-pin of two
serial ports.
(My own little port-analyzing application!)
Everything works fine, except that there seems to be some timedelay from the
moment the bytes arrive to the port, and to the moment my application can
read them.
This means that I cannot timestamp the arrival of the bytes accurately.
I tried both approaches in comport handling; event driven and polling...no
luck.

Perhaps I need to be able to set the rx-trigger level in the 16550 uart to 1
byte - but if thats the case, I dont know how to.

Can anybody help me, please?
Sep 19 '06 #1
2 1271
I found a way arond the problem.
The solution was to read each port until its empty, and NOT read one byte
from portA followed by reading one byte from portB etc.
My receiver thread (polling based) now looks like this:
//*******************
private void ReceiveThread()
{
byte AVal, BVal;
bool keepon;

while(true)
{
keepon = false;
while(ReadBufferA(out AVal))
{
if(CurrentChannel != 'a')
{
CurrentChannel = 'a';
if(++WIndex >= monBufSize) WIndex=0;
MonBuf[WIndex] = -1;
}
if(++WIndex >= monBufSize) WIndex=0;
MonBuf[WIndex] = AVal;
keepon = true;
}
while(ReadBufferB(out BVal))
{
if(CurrentChannel != 'b')
{
CurrentChannel = 'b';
if(++WIndex >= monBufSize) WIndex=0;
MonBuf[WIndex] = -2;
}
if(++WIndex >= monBufSize) WIndex=0;
MonBuf[WIndex] = BVal;
keepon = true;
}

if(!keepon)
Thread.Sleep(1);
}
}

where the ReadBuffer() - contains the ReadFile() - p/invokes.

"Flensted" wrote:
Hello.
I am trying to produce a pc-program that can monitor the rx-pin of two
serial ports.
(My own little port-analyzing application!)
Everything works fine, except that there seems to be some timedelay from the
moment the bytes arrive to the port, and to the moment my application can
read them.
This means that I cannot timestamp the arrival of the bytes accurately.
I tried both approaches in comport handling; event driven and polling...no
luck.

Perhaps I need to be able to set the rx-trigger level in the 16550 uart to 1
byte - but if thats the case, I dont know how to.

Can anybody help me, please?
Sep 19 '06 #2
Hi,

No.

The simple fact is that there is no real-time access to serial data (or any
other resource) under Windows, much less subordinated by the Windows serial
driver and the classes that implement the framework. Also, realize that the
standard PC UART implements a 16-byte receive FIFO (and some other
hardware/software devices even deeper FIFOs). The processing of the
receive FIFO is interrupt driven, but also is processed by timeouts at the
diver level.

YOU can set the rx-trigger level to 1 to improve this, but not to eliminate
the timing issues.

Also, if you depend on the DataReceived event, you are relying on a
Background (worker) thread for notification from each port. There is no
assurance of which thread will be processed first. You CAN poll, instead of
using DataReceived -- but even this process offers no guaranty.

The only way to tackle this with any assurance is outside the relm of
managed code. It would involve a laborious process or writing your own
serial device driver to do the time-stamp for you at a much lower level.

From managed code, the best that you can do is to get "sorta close." BTW,
your second post illustrates this. If that is good enough, then, OK.
Problem solved.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Sep 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: M. Raab | last post by:
i have written an application that utilizes serail ports. In order not to have to reinvent code, I decided to use John Hind's sample code that he presented in MSDN magazine last year (Serial Comm:...
13
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have...
1
by: David | last post by:
I have written an application in VB.NET 2003 that uses the SAX serial component for RS232 communications with hardware. The program sets up 2 serial ports so that it can talk to 2 different...
1
by: henrycortezwu | last post by:
Hi All, I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth Serial Port") using VS2005 System.IO.Ports. When I ran the ff code below here's what happens. 1) VS2005 Compiles w/o...
3
by: Tom Brown | last post by:
Hey people, I've written a python app that r/w eight serial ports to control eight devices using eight threads. This all works very nicely in Linux. I even put a GUI on it using PyQt4. Still...
5
by: LongBow | last post by:
Hello, Is there a way, in .NET, to determine what are the avialable Serial (Communications) Ports on a Windows OS and is there a way to determine that port isn't being use other than attempting...
2
by: joaquimfpinto | last post by:
Dear All, I made an app in c# that uses several serial ports. For the serial ports I use a pnp Sunix board, some with 8 serial ports other with 4 or even 2 serial ports. Whenever I use the...
3
by: naveen.sabapathy | last post by:
Hi, I am trying to use virtual serial ports to develop/test my serial communication program. Running in to trouble... I am using com0com to create the virtual ports. The virtual ports seem to...
2
by: Nasif | last post by:
Currently I am writing a program which sends and receives messages through serial port to a device. I am using C# and Microsoft Visual studio 2005 for windows program. But my problem is when i try...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.