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
177 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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