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
173 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
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
NotAlone Challenge 20 83
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 253
firstChar challenge 13 115
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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