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
| HANDLE hComm;
int OuvreCom(char *strPort,long BaudRate,int BitsSize,int Parity,int StopBits)
{
DCB g_DCB;
// On ouvre le port série
hComm = CreateFile(strPort,GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING,NULL);
if(hComm == INVALID_HANDLE_VALUE)
{
// Echec
Msg(TEXT("Echec"));
}
else
{
// On vide les buffers
PurgeComm(hComm,PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
// On paramètre le port série
g_DCB.DCBlength = sizeof(DCB);
//Configuration actuelle
GetCommState(hComm, &g_DCB);
//Modification du DCB
DCB g_DCB =
{
sizeof(DCB), /* DCBlength */
9600, /* BaudRate */
TRUE, /* fBinary */
FALSE, /* fParity */
FALSE, /* fOutxCtsFlow */
FALSE, /* fOutxDsrFlow */
DTR_CONTROL_ENABLE, /* fDtrControl */
FALSE, /* fDsrSensitivity */
FALSE, /* fTXContinueOnXoff */
FALSE, /* fOutX */
FALSE, /* fInX */
FALSE, /* fErrorChar */
FALSE, /* fNull */
RTS_CONTROL_ENABLE, /* fRtsControl */
FALSE, /* fAbortOnError */
0, /* fDummy2 */
0, /* wReserved */
0x100, /* XonLim */
0x100, /* XoffLim */
8, /* ByteSize */
NOPARITY, /* Parity */
ONESTOPBIT, /* StopBits */
0x11, /* XonChar */
0x13, /* XoffChar */
'?', /* ErrorChar */
0x1A, /* EofChar */
0x10 /* EvtChar */
};
SetCommState(hComm,&g_DCB);
SetupComm(hComm, NULL, TX_SIZE);
EscapeCommFunction(hComm, SETDTR);
}
return 1;
} |
Partager