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
| #include <Windows.h>
void* serial_openSerial(void* lpFileName, unsigned int baudRate, unsigned int dwInQueue, unsigned int dwOutQueue) { HANDLE hComm = NULL; DCB dcb; COMMTIMEOUTS commTimeOuts; hComm = CreateFile(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); SetupComm(hComm, dwInQueue, dwOutQueue); GetCommState(hComm, &dcb); dcb.BaudRate = baudRate; SetCommState(hComm, &dcb); commTimeOuts.ReadIntervalTimeout = 0; commTimeOuts.ReadTotalTimeoutMultiplier = 0; commTimeOuts.ReadTotalTimeoutConstant = 0; commTimeOuts.WriteTotalTimeoutMultiplier = 0; commTimeOuts.WriteTotalTimeoutConstant = 0; SetCommTimeouts(hComm, &commTimeOuts); return hComm; }
int serial_readLen(void* hComm, unsigned char* pBuff, unsigned int len, unsigned int* pLenRead) { return ReadFile(hComm, pBuff, len, pLenRead, NULL); }
int serial_closeSerial(void* hComm) { return CloseHandle(hComm); }
int serial_purgeSerial(void* hComm) { return PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR); }
|