Problème initialisation port série

totoscill Messages postés 48 Date d'inscription jeudi 26 avril 2007 Statut Membre Dernière intervention 10 décembre 2009 - 23 mai 2007 à 09:43
lilight Messages postés 11 Date d'inscription lundi 9 avril 2012 Statut Membre Dernière intervention 28 avril 2012 - 21 avril 2012 à 14:45
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 devices

if (_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.

 

5 réponses

lilight Messages postés 11 Date d'inscription lundi 9 avril 2012 Statut Membre Dernière intervention 28 avril 2012 1
21 avril 2012 à 14:45
Bonjour.
Je sais que ce sujet n'est plus actif depuis longtemps mais est il encore possible de recevoir cette classe qui fonctionne ?
Merci
1
bobbyantho Messages postés 69 Date d'inscription vendredi 10 octobre 2003 Statut Membre Dernière intervention 23 avril 2009
23 mai 2007 à 10:55
Salut,

Il reconnait bien ton port série. Le problème est dans la configuration, apparemment il ne supporte pas les valeurs :
etat_port.BaudRate
etat_port.ByteSize
etat_port.Parity
etat_port.StopBits

que tu essaye de lui donner.

Essaye avec d'autres valeurs.
0
totoscill Messages postés 48 Date d'inscription jeudi 26 avril 2007 Statut Membre Dernière intervention 10 décembre 2009
23 mai 2007 à 16:43
Merci mais rien à y faire, même en change   nt les valeurs, le code d'erreur reste le même.
0
bobbyantho Messages postés 69 Date d'inscription vendredi 10 octobre 2003 Statut Membre Dernière intervention 23 avril 2009
23 mai 2007 à 18:45
Si tu veux, j'ai une classe pour l'utilisation du port série qui fonctionne bien et qui est simple d'utilisation.
Donnes-moi ton mail et je te l'enverrai.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
totoscill Messages postés 48 Date d'inscription jeudi 26 avril 2007 Statut Membre Dernière intervention 10 décembre 2009
24 mai 2007 à 12:22
Ok merci:
[mailto:anthonylhostis@club-internet.fr anthonylhostis@club-internet.fr]
0
Rejoignez-nous