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
166 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 Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now