Debian Codegraph @

src/common/serial.cpp

raw
1 /*
2 * Component of the D-ITG 2.8.1 (r1023) platform (http://traffic.comics.unina.it/software/ITG)
3 *
4 * Copyright : (C) 2004-2013 by Alessio Botta, Walter de Donato, Alberto Dainotti,
5 * Stefano Avallone, Antonio Pescape' (PI)
6 * COMICS (COMputer for Interaction and CommunicationS) Group
7 * Department of Electrical Engineering and Information Technologies
8 * University of Napoli "Federico II".
9 * email : [email protected], [email protected], [email protected],
10 * [email protected], [email protected]
11 *
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * For commercial use please refer to D-ITG Professional.
26 */
27
28
29 #include "serial.h"
30
31 #ifdef WIN32
32 HANDLE serialUp(char *nameSerial)
33 {
34 HANDLE ret = CreateFile(nameSerial,
35 GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
36 FILE_FLAG_OVERLAPPED, 0);
37
38 return ret;
39 }
40
41
42
43 void DTR_Enable(HANDLE hComm)
44 {
45 DCB dcb_app;
46
47 GetCommState(hComm,&dcb_app);
48 dcb_app.fDtrControl = DTR_CONTROL_ENABLE;
49 SetCommState(hComm,&dcb_app);
50 }
51
52
53 void DTR_Disable(HANDLE hComm)
54 {
55 DCB dcb_app;
56
57 GetCommState(hComm,&dcb_app);
58 dcb_app.fDtrControl = DTR_CONTROL_DISABLE;
59 SetCommState(hComm,&dcb_app);
60 }
61
62 void RTS_Enable(HANDLE hComm)
63 {
64 DCB dcb_app;
65
66 GetCommState(hComm,&dcb_app);
67 dcb_app.fRtsControl = RTS_CONTROL_ENABLE;
68 SetCommState(hComm,&dcb_app);
69 }
70
71 void RTS_Disable(HANDLE hComm)
72 {
73 DCB dcb_app;
74
75 GetCommState(hComm,&dcb_app);
76 dcb_app.fRtsControl = RTS_CONTROL_DISABLE;
77 SetCommState(hComm,&dcb_app);
78 }
79 #endif
80
81 #ifdef UNIX
82
83 #include <string.h>
84 #include <unistd.h>
85 #include <termios.h>
86 #include <fcntl.h>
87 #include <stdio.h>
88 #include <sys/ioctl.h>
89
90 HANDLE serialUp(char *nameSerial)
91 {
92 int fd;
93 char stringa[]="/dev/";
94 strcat(stringa, nameSerial);
95
96 fd = open(stringa, O_RDWR | O_NOCTTY);
97
98 return fd;
99 }
100
101 void DTR_Disable(HANDLE hComm)
102 {
103 int status;
104 ioctl(hComm, TIOCMGET, &status);
105 status &= ~ TIOCM_DTR;
106 ioctl(hComm, TIOCMSET, &status);
107 }
108
109
110 void DTR_Enable(HANDLE hComm)
111 {
112 int status;
113 ioctl(hComm, TIOCMGET, &status);
114 status |= TIOCM_DTR;
115 ioctl(hComm, TIOCMSET, &status);
116 }
117
118 void RTS_Disable(HANDLE hComm)
119 {
120 int status;
121 ioctl(hComm, TIOCMGET, &status);
122 status &= ~ TIOCM_RTS;
123 ioctl(hComm, TIOCMSET, &status);
124 }
125
126 void RTS_Enable(HANDLE hComm)
127 {
128 int status;
129 ioctl(hComm, TIOCMGET, &status);
130 status |= TIOCM_RTS;
131 ioctl(hComm, TIOCMSET, &status);
132 }
133
134 #endif