GetCommState pour port serie RS232
Bonjour,
J'ai un petit soucil lors de l'appel de la fonction GetCommState du port RS232... (j'utilise Visual C++ 2005)
Cette fonction retourne un 0 (ci-dessous bSuccess vaudra 0), donc elle ne c'est pas bien passée, j'ai récupéré l'erreur avec la fonction GetLastError(), qui me dit :
error 87 : The parameter is incorrect
Voici le petit bout de code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| DCB Com1Config;
HANDLE hCom1 = 0;
hCom1 = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hCom1 == INVALID_HANDLE_VALUE)
{
printf ("error=1");
Sleep(100000);
exit(1);
}
// On vide les buffers
PurgeComm (hCom1, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
// On paramètre le port série
Com1Config.DCBlength = sizeof (DCB);
// Read before Write to have all parameters
bSuccess = GetCommState(hCom1, &Com1Config); |
Merci de votre aide !