-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUARTcommander.cpp
More file actions
74 lines (65 loc) · 1.74 KB
/
Copy pathUARTcommander.cpp
File metadata and controls
74 lines (65 loc) · 1.74 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
69
70
71
72
73
74
// txcmd.cpp: Program to control RTS and DTS output lines
// Author: Martin Dittrich
// Creation Date: 2024-11-02
#include <cstdio>
#include <iostream>
#include <conio.h>
#include "windows.h"
int main(int argc, char* argv[])
{
int count = 0;
while(argv[++ count] != NULL);
if (-- count != 2 || argv[1] == NULL)
{
printf("Error wrong Arguments! Getting %i of 2 needed\n", count);
printf("Syntax: txcmd <port> <function>\n");
printf("1 set DTR\n");
printf("2 reset DTR\n");
printf("3 set CTS\n");
printf("4 reset CTS\n");
return -1;
}
long funcComm = strtol(argv[2], NULL, 10);
HANDLE hComm = CreateFileA(
argv[1],
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
0,
NULL
);
if (hComm == INVALID_HANDLE_VALUE)
{
printf("Cannot open %s\n", argv[1]);
return -1;
}
switch (funcComm)
{
case 1:
if(EscapeCommFunction(hComm, SETDTR))
printf("Setting DTR\n");
else
printf("Error Setting DTR\n");
break;
case 2:
if(EscapeCommFunction(hComm, CLRDTR))
printf("Clearing DTR\n");
else
printf("Error Clearing DTR\n");
break;
case 3:
if(EscapeCommFunction(hComm, SETRTS))
printf("Setting CTS\n");
else
printf("Error Setting CTS\n");
break;
case 4:
if(EscapeCommFunction(hComm, CLRRTS))
printf("Clearing CTS\n");
else
printf("Error Clearing CTS\n");
break;
}
return 0;
}