Bonjour,
J'ai un problème avec mon code lors de l'initilisation du port série. Voici le code:
* *** Constructors *** */
//! Default constructor
TestGPS_Serial::TestGPS_Serial(
char * port, int baudRate, int timeOut, BYTE parity,BYTE nbBits, BYTE stopBits)
{
//init class namestrcpy(_cn,
"TestGPS_Serial");// init communication portstrcpy(_comPort.Port, port);
_comPort.BaudRate = baudRate= 4800;
_comPort.idComDev = -1;
_comPort.DataBits = nbBits=8;
_comPort.Parity = parity = NOPARITY;
_comPort.StopBits = stopBits=1;
_comPort.hcom = INVALID_HANDLE_VALUE;
_comPort.TimeOut = timeOut;
// _cerr = cerr;
}
LA FONCTION QUE J'UTILISE POUR INITIALISER LE PORT SERIE:
void
TestGPS_Serial::connect(void){
DCB etat_port;
// int RXQUEUE = 1024;
// int TXQUEUE = 1024;
int err;disconnect();
//déja connecté->on se déconnecte
DWORD dwError;
_comPort.hcom = CreateFile (
"COM1",GENERIC_READ | GENERIC_WRITE,
0,
//comm devices must be opened w/exclusive-accessNULL,
// no security attributesOPEN_EXISTING,
// comm devices must use OPEN_EXISTING0,
// not overlapped I/ONULL);
// hTemplate must be NULL for comm devicesif (_comPort.hcom==INVALID_HANDLE_VALUE) {dwError = GetLastError();
printf(
"Probleme d'ouverture du port serie %s: 'CreateFile'", _comPort.Port);printf(
"code d'erreur : %lu", dwError);// _cerr->createError(_cn, CAPI_ERROR_SERIAL_O);
return;}
//configuration du port sérieBOOL fSuccess = GetCommState(_comPort.hcom, &etat_port);
if (!fSuccess) { // Handle the errordwError = GetLastError();
printf(
"Problème de recuperation de l'etat du port serie %s: 'GetCommState'", _comPort.Port);printf(
"code d'erreur : %lu", dwError);// _cerr->createError(_cn, CAPI_ERROR_SERIAL_O);
return;}
//infoConnection(etat_port);//etat_port.EofChar = 13; //code ascii CRetat_port.BaudRate = (DWORD)(_comPort.BaudRate);
etat_port.ByteSize = _comPort.DataBits;
etat_port.Parity = _comPort.Parity;
etat_port.StopBits = _comPort.StopBits;
fSuccess = SetCommState(_comPort.hcom, &etat_port); // le problème est ici
if (!fSuccess) { // Handle the errordwError = GetLastError();
printf(
"Problème d'initialisation du port série %s: 'SetCommState'", _comPort.Port);printf(
"code d'erreur : %lu", dwError);// _cerr->createError(_cn, CAPI_ERROR_SERIAL_O);
return;}
//gestion des time outCOMMTIMEOUTS comto;
comto.ReadIntervalTimeout = 0;
comto.ReadTotalTimeoutMultiplier = 0;
comto.ReadTotalTimeoutConstant = _comPort.TimeOut;
comto.WriteTotalTimeoutMultiplier = 0;
comto.WriteTotalTimeoutConstant = _comPort.TimeOut;
err = SetCommTimeouts(_comPort.hcom, &comto);
if (err<0) {printf(
"Erreur en programmation time out");// _cerr->createError(_cn, CAPI_ERROR_SERIAL_O);
return;}
resetConnection();
//printf ("Port série ouvert");}
voilà. La compilation fonctionne parfaitement mais dans l'executable, ma fonction reste bloquer à"
fSuccess = SetCommState(_comPort.hcom, &etat_port);"
J'ai à l'écran: Problème d'initialisation du port série |||||||||||||||||||||||: 'SetCommState' code d'erreur: 87
Visiblement il ne reconnait pas mon port série.
Quelqu'un pourrait m'aider, SVP?
Je vous remercie.