?
Solved

Serial Communication NT/95 - NONOVERLAPPED does not block execution untill HW end sending message. It seems that the buffer get erased before all bits are sent by the transport.

Posted on 2003-10-26
8
Medium Priority
?
187 Views
Last Modified: 2013-11-20
The methode I used is to send a zero byte in a slow bit rate (9600) before resuming to normal baudrate (19200).
I need to send a syncbreak (at least 13 consecutive bits in zero).
I use NONOVERLAPPED communication.
I wrote a "sendbreak" subroutine that changes baudrate to 9600,
sends a byte, than, changes baudrate back to 19200.
The problem I noticed is that on some computers the break signal is partialy executed, on others it is not executed at all. On all computers each of the lines of the routine performs perfectly when I set a "debug-break" before changing the baudrate back to 19200.
It seems that "WriteFile( ....,NULL) does not block execution before executing next line.
What can I do in order to assert that the message was fully executed on the hardware before executing next line?

Thank you,

Ronny
0
Comment
Question by:ronnyz
[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
8 Comments
 
LVL 12

Expert Comment

by:migel
ID: 9623007
Hi!
May be you need wait untill all bytes will be sended ;-)

    while(GetOutQueueSize())  Sleep(0);

where

UINT GetOutQueueSize()
{
      COMSTAT Stat ;
            DWORD dwErr = 0;
            ClearCommError(m_hPort, &dwErr, &Stat);
             return (int)dwErr;
      return Stat.cbOutQue ;
}
0
 

Author Comment

by:ronnyz
ID: 9625653
Hi ,

I tried the method you have sujjested but it remains at the same. It is like a dubble check that proves that the buffer is empty and indeed it is empty although the phisical layer hasn't transfered yet. Therefore when I change baudrate after these checks it cuts the transmition of the syncbreak.

I tried working with a loopback in hardware - here I am trying to assert that the byte was transfered by receiving it into the receive buffer - this method was too slow - about 40 bits time.

An other method was implementing a timer but this is not reliable as they have a latency of 10 to 55 mSec depending on the PC.

Any idea of how to overcome?

Ronny
0
 
LVL 13

Expert Comment

by:SteH
ID: 9625906
The latency is OS intrinsic. Even with another approach the OS might claim time for its own purposes and thus interupting your code. This will affect you espescially on 95.

Quote from MSDN:

cbOutQue
Specifies the number of bytes of user data remaining to be transmitted for all write operations. This value will be zero for a nonoverlapped write.

This means you need to go to overlapped IO in order to get the number of bytes in the buffer.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:ronnyz
ID: 9626884
cbOutQue must be zero in nonoverlapped as the code is blocked untill all data is moved out from the transmit buffer to the transport layer. One can ask for the status of the buffer only after the write has been finished - buffer is empty.

I looked in MSDN in a technicle article "complition I/O". It says that overlapped events can achieve signal completion as in nonoverlapped. I tried that too but it is no better.

It seems that I should find a way to get a shorter latency with  timers. I need a latency that is shorter from 2 milli seconds.
Any idea how can I achieve that?
Thanks, Ronny
0
 
LVL 12

Expert Comment

by:migel
ID: 9627001
Hi!
You can use HighResolution (or Multimedia) timers
see timeSetEvent in MSDN
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 11975760
Submitted to PAQ with no points refunded (of 245)

DarthMod
Community Support Moderator
0

Featured Post

Industry Leaders: 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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

764 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