-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
executable file
·68 lines (54 loc) · 1.45 KB
/
Source.cpp
File metadata and controls
executable file
·68 lines (54 loc) · 1.45 KB
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
#include <windows.h>
int main(int argc, char *argv[]) {
if (argc < 4) {
return 0;
}
char port[80];
strcpy(port, "\\\\.\\COM");
strcat(port, argv[1]);
HANDLE serialHandle;
serialHandle = CreateFile((LPCWSTR)port, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
/*
DCB serialParams = { 0 };
serialParams.DCBlength = sizeof(serialParams);
GetCommState(serialHandle, &serialParams);
serialParams.BaudRate = baudrate;
serialParams.ByteSize = byteSize;
serialParams.StopBits = stopBits;
serialParams.Parity = parity;
SetCommState(serialHandle, &serialParams);
*/
/*
COMMTIMEOUTS timeout = { 0 };
timeout.ReadIntervalTimeout = 50;
timeout.ReadTotalTimeoutConstant = 50;
timeout.ReadTotalTimeoutMultiplier = 50;
timeout.WriteTotalTimeoutConstant = 50;
timeout.WriteTotalTimeoutMultiplier = 10;
SetCommTimeouts(serialHandle, &timeout);
*/
unsigned char dev = 0;
char *dev_ptr = argv[2];
while (*dev_ptr) {
dev *= 10;
dev += *dev_ptr++ - '0';
}
unsigned char msg[3];
DWORD dwBytesToWrite = 3;
DWORD dwBytesWritten = 0;
msg[0] = 0xFF;
msg[1] = dev;
msg[2] = argv[3][0] - '0';
if (msg[2] == 2) {
msg[2] = 0;
WriteFile(serialHandle, msg, dwBytesToWrite, &dwBytesWritten, NULL);
Sleep(1000);
msg[2] = 1;
WriteFile(serialHandle, msg, dwBytesToWrite, &dwBytesWritten, NULL);
}
else {
WriteFile(serialHandle, msg, dwBytesToWrite, &dwBytesWritten, NULL);
}
CloseHandle(serialHandle);
return 0;
}