hang up in WriteFile() if WaitCommEvent() is active in receive thread

E

Elmar Jacobs

hi folk,

if I define a SetCommMask for the receive event and the thread is waiting
for an Rx Event the writeFile function will hang up if I try to send byte.
I use the standard settings for the port. Can anybody tell me why the
WriteFile function hang up?


thanks a lot,
elmar

GetCommTimeouts(m_hComPort, &cto);

// Change the COMMTIMEOUTS structure settings.
cto.ReadIntervalTimeout = MAXDWORD;
cto.ReadTotalTimeoutMultiplier = 0;
cto.ReadTotalTimeoutConstant = 0;
cto.WriteTotalTimeoutMultiplier = 0;//10;
cto.WriteTotalTimeoutConstant = 0;//1000;

// Set the time-out parameters for all read and write operations
// on the port.
SetCommTimeouts(m_hComPort, &cto);



DWORD WINAPI ReadThread(PVOID pArg)
{
HANDLE hSerPort = (HANDLE) pArg;
BOOL retVal;
//DWORD dwMask;

if (hSerPort != NULL){
rCntInBuffer = rCntOutBuffer = cntOfNotFetchedBytes = 0;

// Specify a set of events to be monitored for the port.
SetCommMask (hSerPort, EV_RXCHAR | EV_ERR);

do{
WaitCommEvent(hSerPort, &dwMask, 0);
switch (dwMask){
case EV_RXCHAR:
{
if (cntOfNotFetchedBytes < d_receiveBufferSize){ // if
receivedBuffer not full insert byte
do{
retVal = ReadFile(hSerPort, &receiveBuffer[rCntInBuffer], 1,
&numberOfReceiving, 0);
if (numberOfReceiving == 1){
rCntInBuffer++;
cntOfNotFetchedBytes++;

if (rCntInBuffer > d_receiveBufferSize){
rCntInBuffer = 0;
}
}
}while(retVal != NULL); // readFile untile fifo is empty
}
}
break;
case EV_ERR:
break;
}
}while(1);
}
return 0;
}
 
C

Chris Tacke, eMVP

Sounds like the driver doesn't support full duplex. Have you tried with any
of the well-tested serial libraries already out there (like the one from
OpenNETCF.org or Dick Grier)?
 
E

Elmar Jacobs

No I am not using one of this libraries.

How can I handle the 2 events EV_RXCHAR and a selfmade event EV_TXCHAR in
one thread, like :

{
.....
if ((WaitComEvent(hSerPort, &dwMask, o) || WaitForSingleEvent(EV_TXCHAR,
INFINITE)){
if (EV_TXCHAR){
...handel transmit event....
}else{
....handle receive event..
}

}
so that I can make an bye pass about the full dublex problem?
Do you mean it works?

elmar
 
C

Chris Tacke, eMVP

You really can't do send and receive on the same thread. If the driver
truly doesn't support full duplex, you'll have to change your waits from
INFINITE to a finite period then swap from send to receive mode and back
again (or define a communication protocol that prevents the possibility of
needing full duplex).

-Chris
 
E

Elmar Jacobs

thanks a lot Chris

- el

Chris Tacke said:
You really can't do send and receive on the same thread. If the driver
truly doesn't support full duplex, you'll have to change your waits from
INFINITE to a finite period then swap from send to receive mode and back
again (or define a communication protocol that prevents the possibility of
needing full duplex).

-Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top