WaitCommEvent avec C++Builder

nixonne Messages postés 5 Date d'inscription samedi 19 avril 2003 Statut Membre Dernière intervention 20 février 2004 - 20 févr. 2004 à 11:37
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 - 20 févr. 2004 à 18:16
bonjour,

je souhaite utiliser la fonction WautCommEvent pour un port série afin d'etre prévenu d'un changement d'état du port et afficher dans un Edit ce qui est recu.

Voici mon code source:

void lecteur::attente() 
{DWORD rep=0;bool retour; 

SetCommMask(comm,EV_RXCHAR); 
if(WaitCommEvent(comm,&rep,&over)) 
{ 
Form1->Edit2->Text=rep; 
} 
} 


Cela ne m'affiche rien, quelqu'un pourrait-il m'aider?

Merci d'avance

Nixonne

1 réponse

ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
20 févr. 2004 à 18:16
DWORD dwEvtMask = 0;
OVERLAPPED ov;
ZeroMemory(&ov, sizeof(OVERLAPPED));
ov.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(!WaitCommEvent(hComm, &dwEvtMask, &ov))
{
// si toujours en attente
if(GetLastError() == ERROR_IO_PENDING)
{
// on attent que l'opération se termine ou qu'elle soit interrompue
// (lors de l'appel à SetCommMask(0) à la deconnexion par exemple)
DWORD dwResult;
while(!GetOverlappedResult(hComm), &ov,&dwResult, TRUE))
{
if(GetLastError() != ERROR_IO_INCOMPLETE)
break;
}
}
}

// lecture si des caractères ont été reçus
if(dwEvtMask & EV_RXCHAR)
{

}

Le port doit avoir été ouvert avec FILE_FLAG_OVERLAPPED
0
Rejoignez-nous