1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| const U8 envoi_chaine(AnsiString Chaine_a_Envoyer,AnsiString Char_Controle)
{
U32 NbOctet_Message;
unsigned long nBytesWrite;
char *Message = new char[2048];
char *EolChar=new char[Char_Controle.Length()+1];
strcpy(EolChar,Char_Controle.c_str());
vector<U8> Chaine(Chaine_a_Envoyer.Length());
for(U16 i =1;i<=Chaine_a_Envoyer.Length();i++)
{
Chaine[i]=Chaine_a_Envoyer[i];
}
//on concatene le caractère de contrôle a notre chaine
if(strcmp(EolChar,"CR")==0)
sprintf(Message,"%s%c",Chaine,0x0D);
if(strcmp(EolChar,"LF")==0)
sprintf(Message,"%s%c",Chaine,0x0A);
if(strcmp(EolChar,"LF/CR")==0)
sprintf(Message,"%s%c%c",Chaine,0x0A,0x0D);
if(strcmp(EolChar,"CR/LF")==0)
sprintf(Message,"%s%c%c",Chaine,0x0D,0x0A);
if(strcmp(EolChar,"")==0)
sprintf(Message,"%s",Chaine);
// compter le nombre doctet à envoyer
NbOctet_Message = StrLen(Message);
// écrire dans le fichier(ici dans notre port de com)
WriteFile(hwi_comrs_hCom_,Message,NbOctet_Message,&nBytesWrite,NULL); delete[] Message;
delete[] EolChar;
return 0;
} |
Partager