-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioctl.c
More file actions
114 lines (94 loc) · 2.08 KB
/
Copy pathioctl.c
File metadata and controls
114 lines (94 loc) · 2.08 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* INCLUDE FILE DECLARATIONS */
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <linux/sockios.h>
#include <linux/types.h>
#include <pthread.h>
#include "ioctl.h"
/* LOCAL VARIABLES DECLARATIONS */
int main(int argc, char* argv[])
{
char dev[16];
int select;
int mode;
int ret;
int check_as;
int devfd;
while (1) {
printf("Please input the port of AX781x0/MCS78x0 (ex. /dev/ttyUSB0):");
scanf("%s", dev);
if (memcmp(dev, "/dev/ttyUSB", 11) != 0)
printf("Wrong input !!\n");
else
break;
}
devfd = open(dev, O_RDWR);
if (devfd == -1) {
printf("Can't open %s\n", dev);
return 0;
}
ret = ioctl(devfd, IOCTL_CHECK_AS, &check_as);
if (ret < 0) {
printf("IOCTL failed!\n");
goto exit;
}
if (check_as != 1) {
printf("\nAuto-switch is disable!\n");
goto exit;
}
while (1) {
printf("Please specift the number of the mode of %s.\n", dev);
printf("1 : RS232\n");
printf("2 : RS422 - No Terminating Register\n");
printf("3 : RS422 - Terminating Register\n");
printf("4 : RS485 - Half Duplex with Echo\n");
printf("5 : RS485 - Half Duplex with No Echo\n");
printf("6 : RS485 - Full Duplex\n");
printf("7 : set 6M Baud\n");
printf("0 : Exit\n");
printf(":");
scanf("%d", &select);
if (select == 1) {
mode = 0;
break;
} else if (select == 2) {
mode = 0x22;
break;
} else if (select == 3) {
mode = 0x23;
break;
} else if (select == 4) {
mode = 0xC1;
break;
} else if (select == 5) {
mode = 0xC2;
break;
} else if (select == 6) {
mode = 0xC3;
break;
} else if (select == 7) {
if (ioctl(devfd, TIOCEXBAUD, 6000000) < 0)
printf("IOCTL failed!\n");
return 0;
} else if (select == 0) {
return 0;
}
}
ret = ioctl(devfd, IOCTL_SET_RS_MODE, mode);
if (ret < 0) {
printf("IOCTL failed!\n");
} else {
printf("The %s will operating in selected mode after open(re-open) it.\n", dev);
}
exit:
printf("\n");
return 0;
}