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
| DCB l_dcb;
COMMTIMEOUTS l_timeouts;
//Ouvre la communication sur le port serie
m_PortHandle = CreateFile(getPortName().data(),
GENERIC_READ|GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
0);
if (m_PortHandle == INVALID_HANDLE_VALUE )
{
m_PortHandle = NULL;
return 0;
}
//Créer un overlapped event pour l'attente du car spéciale
m_osStatus.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (m_osStatus.hEvent == NULL)
{
return 0;
}
if (!PurgeComm(m_PortHandle,PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR))
{
return 0;
}
//Configure la communication sur le port série
l_timeouts.ReadIntervalTimeout = MAXDWORD;
l_timeouts.ReadTotalTimeoutMultiplier = 0;
l_timeouts.ReadTotalTimeoutConstant = 0;
l_timeouts.WriteTotalTimeoutMultiplier = 0;
l_timeouts.WriteTotalTimeoutConstant = 30000;
if (!SetCommTimeouts(m_PortHandle, &l_timeouts))
{
return 0;
}
FillMemory(&l_dcb, sizeof(l_dcb), 0);
if (!GetCommState(m_PortHandle, &l_dcb))
{
return LNK_INITLIEN_KO;
}
l_dcb.BaudRate = 38400 ;
l_dcb.Parity = 1;
l_dcb.StopBits = 1;
l_dcb.ByteSize = 8;
l_dcb.EvtChar = '\n';
l_dcb.fDtrControl = DTR_CONTROL_ENABLE;
l_dcb.fRtsControl = RTS_CONTROL_ENABLE;
l_dcb.fOutxDsrFlow= FALSE;
l_dcb.fOutxCtsFlow= FALSE;
l_dcb.fOutX = FALSE;
l_dcb.fInX = FALSE;
if(!SetCommState(m_PortHandle, &l_dcb))
{
return 0;
}
return 1; |
Partager