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 75
| // ***** OUVERTURE DU PORT *****
m_hCom = CreateFile( "COM1", // Choix du port « COMx »
GENERIC_READ | GENERIC_WRITE, // accès pour lire et écrire sur le port
0, // accès exclusif au port de COM
NULL, // sécurité par défaut
OPEN_EXISTING, //Doit être à cette valeur car se nest pas un fichier
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, // mode synchrone asynchrone
NULL
);
ClearCommError(m_hCom, &dwErrors, NULL);
GetCommProperties(m_hCom, &prop);
err = (m_hCom == INVALID_HANDLE_VALUE) || (!SetupComm(m_hCom, 4096, 4096));
if (!err){
GetCommTimeouts (m_hCom, &gct);
gct.ReadIntervalTimeout = 0;
gct.ReadTotalTimeoutConstant = 0;
gct.ReadTotalTimeoutMultiplier = 0;
gct.WriteTotalTimeoutConstant = 5000;
gct.WriteTotalTimeoutMultiplier = 0;
if ( !SetCommTimeouts(m_hCom,&gct) ) err = 1;
}
if (!err){
memset(&m_Ov,0,sizeof(m_Ov));
// ***** CONFIGURATION DU PORT *****
m_config.DCBlength = sizeof( DCB );
GetCommState(m_hCom,&m_config);
m_config.BaudRate = 115200;
m_config.fBinary = 1;
m_config.fParity = 0;
m_config.fOutxCtsFlow = 0;
m_config.fOutxDsrFlow = 0;
m_config.fDtrControl = 1;
m_config.fDsrSensitivity =0;
m_config.fTXContinueOnXoff = 0;
m_config.fOutX = 0;
m_config.fInX = 0;
m_config.fErrorChar = 0;
m_config.fNull = 0;
m_config.fRtsControl = 1;
m_config.fAbortOnError = 0;
m_config.fDummy2 = 0;
//m_config.wReserved = 0;
m_config.XonLim = 2048;
m_config.XoffLim = 512;
m_config.ByteSize = 8;
m_config.Parity = 0;
m_config.StopBits = 0;
m_config.XonChar = 0;
m_config.XoffChar = 0;
m_config.ErrorChar = 0;
m_config.EofChar = 0;
m_config.EvtChar = 0;
//m_config.wReserved1 = 0;
err = SetCommState(m_hCom,&m_config) == 0;
// Purge
if (!err){
PurgeComm(m_hCom, PURGE_TXABORT|PURGE_RXABORT|
PURGE_TXCLEAR|PURGE_RXCLEAR);
GetCommMask(m_hCom, &old_mask);
SetCommMask(m_hCom, 0);
SetCommMask(m_hCom, old_mask);
}
} |
Partager