-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComConfig.cpp
50 lines (39 loc) · 1.23 KB
/
ComConfig.cpp
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
// ComConfig.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
int _tmain(int argc, _TCHAR* argv[])
{
COMMTIMEOUTS timeouts;
HANDLE hCommPort;
TCHAR pcCommPort[30];
if(argc < 2) {
_tprintf (TEXT("Please specifiy a COMM port\n"));
return 0;
}
_sntprintf(pcCommPort, 29, TEXT("%s"), argv[1]);
pcCommPort[29] = 0;
hCommPort = CreateFile(pcCommPort,
GENERIC_READ|GENERIC_WRITE,//access ( read and write)
0, //(share) 0:cannot share the COM port
0, //security (None)
OPEN_EXISTING,// creation : open_existing
FILE_ATTRIBUTE_NORMAL,// we want overlapped operation
0// no templates file for COM port...
);
if (hCommPort == INVALID_HANDLE_VALUE) {
_tprintf (TEXT("Unable to open %s\n"), pcCommPort);
exit(1);
}
timeouts.ReadIntervalTimeout = MAXDWORD;
timeouts.ReadTotalTimeoutMultiplier = 0;
timeouts.ReadTotalTimeoutConstant = 0;
timeouts.WriteTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;
if(!SetCommTimeouts(hCommPort, &timeouts)) {
printf("Error setting timeouts\r\n");
} else {
_tprintf (TEXT("Serial port %s successfully reconfigured.\r\n"), pcCommPort);
}
return 0;
}