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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include "stdafx.h"
#include "Module_test1.h"
#include "cl_Bluetooth.h"
// cl_Bluetooth
IMPLEMENT_DYNAMIC(cl_Bluetooth, CWnd)
//---------------------------------------------------------------------------
/* Partie PDA */
/* */
/* */
/* Définition des méthodes de Bluetooth */
//---------------------------------------------------------------------------
cl_Bluetooth::cl_Bluetooth()
{char *Port=new char (5);
serie=new DCB();
int vitesse;
strcpy(Port,"COM1");
vitesse=4800;
modifPARAM (Port,vitesse);
}
//-------------------------------------------------------------------------
cl_Bluetooth::~cl_Bluetooth()
{ /* Destructeur */
bool test;
test=PurgeComm (hcomm,PURGE_RXCLEAR);
if (test==true)
{test=CloseHandle (hcomm); //fermeture du port
}
else
{MessageBox(TEXT("Impossible de vider le port com"),TEXT("Erreur #003"),MB_ICONSTOP);
}
}
//-----------------------------------------------------------------------------
char* cl_Bluetooth::Lecture ()
/* Lecture des données sur le port */
{bool test;
unsigned long pt=0;
char chaine[100];
test=ReadFile(hcomm,&chaine,82,&pt,&over); //lecture du port série
strcat (chaine,"\0");
if (test==false)
{MessageBox(TEXT("Impossible de lire sur le port com"),TEXT("Erreur #004"),MB_ICONSTOP);
}
PurgeComm (hcomm,PURGE_RXCLEAR); // vide le buffer du port
return chaine; //on retourne la trame NMEA
}
//---------------------------------------------------------------------------
void cl_Bluetooth::modifPARAM (char *Port,int vitesse)
/* Modification des paramètres du port série */
{LPWSTR wch;
strcat(Port,":");
int Size = MultiByteToWideChar (CP_ACP, 0, Port, -1, NULL, 0);
wch = new WCHAR[Size];
MultiByteToWideChar (CP_ACP, 0, Port, -1, wch, Size);
bool test;
hcomm=CreateFile(wch,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL); //ouverture du port sélectionné
if(hcomm==INVALID_HANDLE_VALUE)
{MessageBox(TEXT("Impossible d'ouvrire le port choisi"),TEXT("Erreur #001"),MB_ICONSTOP);
}
GetCommState (hcomm,serie); //lecture des paramètre de configuration du port
serie->BaudRate=vitesse;
serie->ByteSize=8;
serie->Parity=NOPARITY;
serie->StopBits=0;
test=SetCommState (hcomm,serie); //fin de la configuration
if (test==false)
{MessageBox(TEXT("Impossible d'ouvrire le port choisi"),TEXT("Erreur #002"),MB_ICONSTOP);
}
PurgeComm (hcomm,PURGE_RXCLEAR); //vider le buffer
} |