Qt
0
Вклад в тег
void* hSerial;
char c1;
DWORD bytesRead, bWritten;
BOOL fSuccess;
DWORD dwParam, dwThreadId;
const uint16_t TIMEOUT = 100;
DCB dcb;
COMMTIMEOUTS timeouts;
timeouts.ReadIntervalTimeout = MAXDWORD;
timeouts.ReadTotalTimeoutMultiplier = MAXDWORD;
timeouts.ReadTotalTimeoutConstant = TIMEOUT;
timeouts.WriteTotalTimeoutMultiplier = 10;
timeouts.WriteTotalTimeoutConstant = TIMEOUT;
hSerial = CreateFile(L"COM3", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (hSerial != INVALID_HANDLE_VALUE)
{
fSuccess = SetCommTimeouts(hSerial, &timeouts);
GetCommState(hSerial, &dcb);
dcb.BaudRate = CBR_115200;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.DCBlength = sizeof(DCB);
fSuccess = SetCommState(hSerial, &dcb);
CloseHandle(hSerial);
}