Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows COM
Hi,
 
First, sorry, I don't know much software, so please excuse my posting, if this is in the wrong spot. I have a consultant doing a meter program using MS Visual C++ 2010, and he is having trouble fixing a bug, so I thought I would see if anybody has a suggestion.
 
The application connects to a com port (115200, no handshaking), and displays an angle. The data can come quite fast at times. He occasionally misses the last sets of values (the last value sent is the most important one). He claims it is something to do with Windows.
 
When I use Hyperterm, it never fails, so I seem to think it shouldn't be a problem.
 
Any comments/suggestions?
 
Thanks,
 
Mark
Posted 2-Jul-12 8:28am
Comments
SoMad at 3-Jul-12 2:21am
   
Is it possible for you to go to a lower baud rate (obviously on both sides) to see if that works without missing any values?
 
Soren Madsen
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

As others have said, I'd suspect that the code is currently polling the receive queue, rather than having a dedicated thread sucking it dry, and pushing it into a buffer somewhere
 
20 years ago, I was comfortably getting 115k2 out of a 30Mhz DOS machine with a 16550UART, so these days it's not a problem for the hardware - Windows however, is extremely 'lumpy' in terms of performance if you don't talk to hardware effectively - i.e. on a second thread
 
I'd wager there's a single thread reading the com port, writing to disk - the latency in disk IO is delaying the poller sufficiently for the UART buffer to get swamped
  Permalink  
Comments
pwasser at 3-Jul-12 8:34am
   
This has to be it.
SoMad at 3-Jul-12 18:20pm
   
I agree, assuming they are using an on-board COM port. I have seen several virtual COM ports that have issues when you use a high baud rate.
 
Soren Madsen
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Obviously it cannot be to do with Windows if Hyperterminal never misses the values (as you've suggested, Mark).
 
"Something to do with Windows" is the old classic excuse for bugs in app software.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Mark,
If your consultant is using unmanaged code, make sure he's using overlapped I/O. This helped me with a similar issue a few years ago.
In any case, have him google 'SERIAL PORT I/O'. The APIs are similar to file APIs, but the devil, as always, hides in the details.
 
Hope this helps,
Pablo.
  Permalink  
Comments
pwasser at 3-Jul-12 0:14am
   
Which can be summed up by asking whether the COM port is being polled from the main thread or whether a separate thread is running to monitor the port using overlapped I/O.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

How many bytes of data are received from the device in a single message. Perhaps there is more data coming and it's simply not being read.
 
It's quite common for the com port receive buffer to only hold 16 bytes (16550 FIFO), so anything over that might require two reads.
 
Good luck.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

First, thanks to all for the suggestions. I will run these past him to see if anything helps. Unfortunately, he won't be able to work on if for a week or longer. Is there a way to attach the SerialPort.cpp file here? I have no issues with anybody seeing it.
 
Thanks again,
 
Mark
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 400
1 Maciej Los 222
2 OriginalGriff 213
3 BillWoodruff 130
4 Zoltán Zörgő 85
0 OriginalGriff 7,969
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,309
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100