OVH Cloud OVH Cloud

Probleme de port serie sous windows 2000

4 réponses
Avatar
PRORIOL Fabien
Bonjours,

Je réalise un programme C++ qui dialogue avec mon tel portable via commande
AT.
Le problème; c'est que j'ai l'impression que le télephone retourne des trucs
aberant.
Je me connecte avec l'hyper terminale, j'échange quelque commande AT, et
après m'être déconnecté, mon programme fonctionne a merveille....

Pourquoi donc????

Voici mon initialisation :

ComMobile::ComMobile(string mport)
{
DCB dcb;
COMMTIMEOUTS timeOuts;
port = CreateFile( mport.c_str(),
GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (!SetCommMask (port, EV_RXFLAG | EV_RXCHAR | EV_TXEMPTY | EV_CTS |
EV_DSR | EV_RLSD | EV_BREAK | EV_ERR | EV_RING)) cout<<"ERREUR1\n";
timeOuts.ReadIntervalTimeout = -1;
timeOuts.ReadTotalTimeoutConstant = 0;
timeOuts.ReadTotalTimeoutMultiplier = 0;
timeOuts.WriteTotalTimeoutConstant = 0;
timeOuts.WriteTotalTimeoutMultiplier = 0;
if (!SetCommTimeouts (port, &timeOuts)) cout<<"ERREUR2\n";
if (!GetCommState(port, &dcb)) cout<<"ERREUR3\n";
if (!PurgeComm (port, PURGE_RXABORT | PURGE_RXCLEAR) || !PurgeComm (port,
PURGE_TXABORT | PURGE_TXCLEAR)) cout<<"ERREUR4\n";
dcb.BaudRate = 57600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.XonLim = 512;
dcb.XoffLim = 512;
EnvoyerCommandeAT ("AT+CREG=?");
EnvoyerCommandeAT ("AT+CREG=0");
EnvoyerCommandeAT ("ATI");
EnvoyerCommandeAT ("ATI2");
}

et la fonction EnvoyerCommandeAT

string ComMobile::EnvoyerCommandeAT(string commande, string analyse, bool
trace)
{
COMSTAT Stat;
DWORD Errors;
unsigned int nCarALire, bcl=0;
unsigned long NCarLus=0, nbBit;
char lpBuf[8000];
string tmpS;
commande += "\r";
lpBuf[0] = '\0';
if(trace)
{
if(analyse=="+CMGL") cout<<"Message en cours de lecture : ";
else if(analyse=="+CPBR") cout<<"Contact en cours de lecture : ";
else cout<<"---> : ";
}
WriteFile(port,commande.c_str(),commande.size(),&nbBit,NULL);
Sleep(400);
ClearCommError(port,&Errors,&Stat);
nCarALire=Stat.cbInQue;
string bufferIn = "";
while(nCarALire != 0)
{
if((nCarALire>0)) ReadFile(port,lpBuf,nCarALire,&NCarLus,NULL);
if(trace)
{
tmpS = lpBuf;
tmpS += " ";
for(int i=0; i<tmpS.size()-8; i++)
{
if(tmpS.substr(i,analyse.size())==analyse)
{
++bcl;
printf("\010\010\010%3i",bcl);
fflush(stdout);
}
}
}
lpBuf[NCarLus] = '\0';
bufferIn += lpBuf;
Sleep(300);
ClearCommError(port,&Errors,&Stat);
nCarALire=Stat.cbInQue;
}
if(trace) cout<<endl;

if((bufferIn.find("+CME")<=bufferIn.size())||(bufferIn.find("+CMS")<=bufferI
n.size())||(bufferIn.find("ERROR")<=bufferIn.size())) throw(bufferIn);
return bufferIn;
}

Je pense que le probleme viens uniquement de l'init....
merci; @+Fab

4 réponses

Avatar
PRORIOL Fabien
J'avais entendu dire que pour utiliser le prot serie sous win2k il y avait
un truc speciale a faire....

Mon problème peu venir de ça, mais que faut-il faire???
Avatar
PRORIOL Fabien
Désolé, je viens de résoudre mon problème moi même...
3 semaines que je cherche mon erreur, je post sur le forum et finalement je
trooouve l'erreur le lendemain!!!!!

En plus l'erreur est vraiment débile!!! j'avais simplement oublié la ligne
SetCommState ....

Voila, merci quand même

@+Fab


"PRORIOL Fabien" a écrit dans
le message de news: ca6hg7$onq$
J'avais entendu dire que pour utiliser le prot serie sous win2k il y avait
un truc speciale a faire....

Mon problème peu venir de ça, mais que faut-il faire???




Avatar
halfwolf
Salut,

"PRORIOL Fabien" wrote in message news:<ca4ori$m1j$...
Bonjours,

Je réalise un programme C++ qui dialogue avec mon tel portable via commande
AT.
Le problème; c'est que j'ai l'impression que le télephone retourne des trucs
aberant.
Je me connecte avec l'hyper terminale, j'échange quelque commande AT, et
après m'être déconnecté, mon programme fonctionne a merveille....

Pourquoi donc????

Voici mon initialisation :

ComMobile::ComMobile(string mport)
{
DCB dcb;
COMMTIMEOUTS timeOuts;
port = CreateFile( mport.c_str(),
GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (!SetCommMask (port, EV_RXFLAG | EV_RXCHAR | EV_TXEMPTY | EV_CTS |
EV_DSR | EV_RLSD | EV_BREAK | EV_ERR | EV_RING)) cout<<"ERREUR1n";
timeOuts.ReadIntervalTimeout = -1;
timeOuts.ReadTotalTimeoutConstant = 0;
timeOuts.ReadTotalTimeoutMultiplier = 0;
timeOuts.WriteTotalTimeoutConstant = 0;
timeOuts.WriteTotalTimeoutMultiplier = 0;
if (!SetCommTimeouts (port, &timeOuts)) cout<<"ERREUR2n";
if (!GetCommState(port, &dcb)) cout<<"ERREUR3n";
if (!PurgeComm (port, PURGE_RXABORT | PURGE_RXCLEAR) || !PurgeComm (port,
PURGE_TXABORT | PURGE_TXCLEAR)) cout<<"ERREUR4n";
dcb.BaudRate = 57600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.XonLim = 512;
dcb.XoffLim = 512;
EnvoyerCommandeAT ("AT+CREG=?");
EnvoyerCommandeAT ("AT+CREG=0");
EnvoyerCommandeAT ("ATI");
EnvoyerCommandeAT ("ATI2");
}



Je pense qu'il manque le SetCommState, donc les modifs que tu fais
dans le dcb ne sont pas prises en compte.

HalfWolf
Avatar
halfwolf
"Re salut,

"PRORIOL Fabien" wrote in message news:<ca6hg7$onq$...
J'avais entendu dire que pour utiliser le prot serie sous win2k il y avait
un truc speciale a faire....



Pas à ma connaissance, tant que tu utilises l'API.

Les gens parlaient peut-être de gestion à la DOS, avec écriture
directe aux adresses physiques pour piloter le port de comm.
Je crois que ça marchait encore sous 9x, certainement pas sous 2000.
Mais bon, je suis trop jeune pour avoir connu ce genre de
programmation pour accéder aux ports, donc je ne suis pas sûr de ce
que je dis.
Je suis sûr que ceux qui savent me corrigeront si j'ai dit une bêtise.

HalfWolf