[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
?
193 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

656 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