##// END OF EJS Templates
removed config file refenrence in headers. -> cleaner install
jeandet@pc-de-jeandet3.lab-lpp.local -
r31:faedd39dfee7 alexis
parent child
Show More
@@ -1,7 +1,7
1 1 # -*- Autoconf -*-
2 2 # Process this file with autoconf to produce a configure script.
3 3 AC_PREREQ([2.67])
4 AC_INIT([librs232],[2.0.0],[alexis.jeandet@lpp.polytechnique.fr],[rs232],[http://www.lpp.fr])
4 AC_INIT([librs232],[2.1.0],[alexis.jeandet@lpp.polytechnique.fr],[rs232],[http://www.lpp.fr])
5 5 AM_INIT_AUTOMAKE([1.10 -Wall foreign])
6 6 AC_CONFIG_MACRO_DIR([m4])
7 7 # Checks for programs.
@@ -20,8 +20,8 AM_PROG_LIBTOOL
20 20 # Checks for header files.
21 21 AC_CHECK_HEADERS([stdio.h string.h fcntl.h errno.h unistd.h termios.h termio.h windows.h])
22 22
23 AC_SUBST([RS232_SO_VERSION], [2:0:0])
24 AC_SUBST([RS232_API_VERSION], [2.0])
23 AC_SUBST([RS232_SO_VERSION], [2:1:0])
24 AC_SUBST([RS232_API_VERSION], [2.1])
25 25 # Checks for typedefs, structures, and compiler characteristics.
26 26
27 27 # Checks for library functions.
@@ -12,7 +12,7 librs232_@RS232_API_VERSION@_la_SOURCES
12 12 RS232_unix.c \
13 13 RS232_win.c
14 14
15 include_HEADERS = RS232.h rs232config.h
15 include_HEADERS = RS232.h
16 16
17 17
18 18 pkgconfigdir = $(libdir)/pkgconfig
@@ -3,25 +3,14
3 3 #define RS232_H
4 4 #define debug
5 5
6 #include "rs232config.h"
6 #define badPortValue -1
7 #define rs232noerr 0
8 typedef int rs232port_t;
9 typedef int rs232speed_t;
10 typedef enum {rs232OneStop=1,rs232One5Stop=2,rs232TwoStop=2}rs232stop;
11 typedef enum {rs232parityNo,rs232parityOdd,rs232parityEven}rs232parity;
7 12
8 #ifdef HAVE_WINDOWS_H
9 #include <windows.h>
10 #define badPortValue INVALID_HANDLE_VALUE
11 typedef HANDLE rs232port_t;
12 typedef DWORD rs232speed_t;
13 typedef enum {rs232OneStop=ONESTOPBIT,rs232One5Stop=ONE5STOPBITS,rs232TwoStop=TWOSTOPBITS}rs232stop;
14 typedef enum {rs232parityNo=NOPARITY,rs232parityOdd=ODDPARITY,rs232parityEven=EVENPARITY}rs232parity;
15 #else
16 #ifdef HAVE_TERMIOS_H
17 #include <termios.h>
18 #define badPortValue -1
19 typedef int rs232port_t;
20 typedef speed_t rs232speed_t;
21 typedef enum {rs232OneStop=1,rs232One5Stop=2,rs232TwoStop=2}rs232stop;
22 typedef enum {rs232parityNo,rs232parityOdd,rs232parityEven}rs232parity;
23 #endif
24 #endif
13
25 14 #ifdef __cplusplus
26 15 #define rs232extern extern "C"
27 16 #else
@@ -20,8 +20,8 rs232speed_t rs232cfspeed(unsigned int B
20 20 rs232port_t rs232open(char* psPortName)
21 21 {
22 22 rs232port_t fd;
23 fd = open(psPortName, O_RDWR | O_NOCTTY | O_NDELAY);
24 fcntl(fd, F_SETFL, 0);
23 fd = (rs232port_t)open(psPortName, O_RDWR | O_NOCTTY | O_NDELAY);
24 fcntl((int)fd, F_SETFL, 0);
25 25 //fd = open(psPortName, O_RDWR | O_NOCTTY);
26 26 #ifdef debug
27 27 if(fd==-1)printf("can't open Port\n");
@@ -56,9 +56,9 int rs232setup(rs232port_t fd, int ChSiz
56 56 cfsetispeed(&terminos, rs232cfspeed(BaudeRate));
57 57 cfsetospeed(&terminos, rs232cfspeed(BaudeRate));
58 58 terminos.c_cflag |= (CLOCAL | CREAD);
59 rs232cfparity(fd, &terminos, Parity);
60 rs232cfnbstop(fd, &terminos, NbStop);
61 rs232cfcsize(fd, &terminos, ChSize);
59 rs232cfparity((int)fd, &terminos, Parity);
60 rs232cfnbstop((int)fd, &terminos, NbStop);
61 rs232cfcsize((int)fd, &terminos, ChSize);
62 62 terminos.c_cc[VMIN]=0;
63 63 terminos.c_cc[VTIME]=1;
64 64 tcflush(fd, TCIFLUSH);
@@ -80,10 +80,10 int rs232setbaudrate(rs232port_t fd, int
80 80 else
81 81 {
82 82 struct termios terminos;
83 tcgetattr(fd, &terminos);
83 tcgetattr((int)fd, &terminos);
84 84 cfsetispeed(&terminos, rs232cfspeed(baudrate));
85 85 cfsetospeed(&terminos, rs232cfspeed(baudrate));
86 tcsetattr(fd, TCSANOW, &terminos);
86 tcsetattr((int)fd, TCSANOW, &terminos);
87 87 return 0;
88 88 }
89 89 }
@@ -97,7 +97,7 int rs232setparity(rs232port_t fd, rs232
97 97 else
98 98 {
99 99 struct termios terminos;
100 tcgetattr(fd, &terminos);
100 tcgetattr((int)fd, &terminos);
101 101 terminos.c_cflag &= ~PARENB;
102 102 terminos.c_cflag &= ~PARODD;
103 103 switch(Parity)
@@ -117,7 +117,7 int rs232setparity(rs232port_t fd, rs232
117 117 terminos.c_cflag &= ~PARENB;
118 118 break;
119 119 }
120 tcsetattr(fd, TCSANOW, &terminos);
120 tcsetattr((int)fd, TCSANOW, &terminos);
121 121 return 0;
122 122 }
123 123 }
@@ -131,7 +131,7 int rs232setnbstop(rs232port_t fd, rs232
131 131 else
132 132 {
133 133 struct termios terminos;
134 tcgetattr(fd, &terminos);
134 tcgetattr((int)fd, &terminos);
135 135 switch(NbStop)
136 136 {
137 137 case 2:
@@ -141,7 +141,7 int rs232setnbstop(rs232port_t fd, rs232
141 141 terminos.c_cflag &= ~CSTOPB;
142 142 break;
143 143 }
144 tcsetattr(fd, TCSANOW, &terminos);
144 tcsetattr((int)fd, TCSANOW, &terminos);
145 145 return 0;
146 146 }
147 147 }
@@ -156,7 +156,7 int rs232setcsize(rs232port_t fd, int Ch
156 156 else
157 157 {
158 158 struct termios terminos;
159 tcgetattr(fd, &terminos);
159 tcgetattr((int)fd, &terminos);
160 160 terminos.c_cflag &= ~CSIZE;
161 161 switch(ChSize)
162 162 {
@@ -173,7 +173,7 int rs232setcsize(rs232port_t fd, int Ch
173 173 terminos.c_cflag |= CS8;
174 174 break;
175 175 }
176 tcsetattr(fd, TCSANOW, &terminos);
176 tcsetattr((int)fd, TCSANOW, &terminos);
177 177 return 0;
178 178 }
179 179 }
@@ -330,7 +330,7 int rs232write(rs232port_t fd,char *psWr
330 330 }
331 331 else
332 332 {
333 return write(fd, psWrite, WriteBufferSize);
333 return write((int)fd, psWrite, WriteBufferSize);
334 334 }
335 335 }
336 336
@@ -344,7 +344,7 int rs232read(rs232port_t fd,char *psRea
344 344 }
345 345 else
346 346 {
347 return read(fd, psReadHex, ReadBufferSize);
347 return read((int)fd, psReadHex, ReadBufferSize);
348 348 }
349 349
350 350 }
@@ -353,9 +353,9 int rs232read(rs232port_t fd,char *psRea
353 353 int rs232setRTS(rs232port_t fd)
354 354 {
355 355 int status;
356 ioctl(fd, TIOCMGET, &status);
356 ioctl((int)fd, TIOCMGET, &status);
357 357 status &= ~TIOCM_RTS;
358 if (ioctl(fd, TIOCMSET, &status))
358 if (ioctl((int)fd, TIOCMSET, &status))
359 359 {
360 360 return -1;
361 361 }
@@ -365,9 +365,9 int rs232setRTS(rs232port_t fd)
365 365 int rs232clearRTS(rs232port_t fd)
366 366 {
367 367 int status;
368 ioctl(fd, TIOCMGET, &status);
368 ioctl((int)fd, TIOCMGET, &status);
369 369 status |= TIOCM_RTS;
370 if (ioctl(fd, TIOCMSET, &status))
370 if (ioctl((int)fd, TIOCMSET, &status))
371 371 {
372 372 return -1;
373 373 }
@@ -377,9 +377,9 int rs232clearRTS(rs232port_t fd)
377 377 int rs232setDTR(rs232port_t fd)
378 378 {
379 379 int status;
380 ioctl(fd, TIOCMGET, &status);
380 ioctl((int)fd, TIOCMGET, &status);
381 381 status &= ~TIOCM_DTR;
382 if (ioctl(fd, TIOCMSET, &status))
382 if (ioctl((int)fd, TIOCMSET, &status))
383 383 {
384 384 return -1;
385 385 }
@@ -390,9 +390,9 int rs232setDTR(rs232port_t fd)
390 390 int rs232clearDTR(rs232port_t fd)
391 391 {
392 392 int status;
393 ioctl(fd, TIOCMGET, &status);
393 ioctl((int)fd, TIOCMGET, &status);
394 394 status |= TIOCM_DTR;
395 if (ioctl(fd, TIOCMSET, &status))
395 if (ioctl((int)fd, TIOCMSET, &status))
396 396 {
397 397 return -1;
398 398 }
@@ -407,7 +407,7 int rs232saferead(rs232port_t fd,char* d
407 407 int i=0;
408 408 for(i=0;i<100;i++)
409 409 {
410 read = rs232read(fd,data,count);
410 read = rs232read((int)fd,data,count);
411 411 count -=read;
412 412 data+=read;
413 413 if(count==0)
@@ -424,7 +424,7 int rs232safewrite(rs232port_t fd,char*
424 424 int i=0;
425 425 for(i=0;i<1000;i++)
426 426 {
427 written = rs232write(fd,data+written,count);
427 written = rs232write((int)fd,data+written,count);
428 428 count-=written;
429 429 data+=written;
430 430 if(count==0)
@@ -13,172 +13,209
13 13 #ifdef HAVE_WINDOWS_H
14 14
15 15
16 int privatedecodeparity(rs232parity Parity )
17 {
18 switch(Parity)
19 {
20 case rs232parityNo:
21 return NOPARITY;
22 break;
23 case rs232parityOdd:
24 return ODDPARITY;
25 break;
26 case rs232parityEven:
27 return EVENPARITY;
28 break;
29 default:
30 return NOPARITY;
31 break;
32 }
33 }
34
35 int privatedecodestop(rs232stop NbStop)
36 {
37 switch(NbStop)
38 {
39 case rs232OneStop:
40 return ONESTOPBIT;
41 break;
42 case rs232One5Stop:
43 return ONE5STOPBITS;
44 break;
45 case rs232TwoStop:
46 return TWOSTOPBITS;
47 break;
48 default;
49 return ONESTOPBIT;
50 break;
51 }
52 }
53
16 54
17 55
18 56 rs232speed_t rs232cfspeed(unsigned int BaudeRate)
19 57 {
20 58
21 59 if(BaudeRate<123)
22 return CBR_110;
60 return (rs232speed_t)CBR_110;
23 61
24 62 if(BaudeRate<450)
25 return CBR_300;
63 return (rs232speed_t)CBR_300;
26 64
27 65 if(BaudeRate<900)
28 return CBR_600;
66 return (rs232speed_t)CBR_600;
29 67
30 68 if(BaudeRate<1500)
31 return CBR_1200;
69 return (rs232speed_t)CBR_1200;
32 70
33 71 if(BaudeRate<3600)
34 return CBR_2400;
72 return (rs232speed_t)CBR_2400;
35 73
36 74 if(BaudeRate<7200)
37 return CBR_4800;
75 return (rs232speed_t)CBR_4800;
38 76
39 77 if(BaudeRate<14000)
40 return CBR_9600;
78 return (rs232speed_t)CBR_9600;
41 79
42 80 if(BaudeRate<16800)
43 return CBR_14400;
81 return (rs232speed_t)CBR_14400;
44 82
45 83 if(BaudeRate<28800)
46 return CBR_19200;
84 return (rs232speed_t)CBR_19200;
47 85
48 86 if(BaudeRate<48000)
49 return CBR_38400;
87 return (rs232speed_t)CBR_38400;
50 88
51 89 if(BaudeRate<86400)
52 return CBR_57600;
90 return (rs232speed_t)CBR_57600;
53 91
54 92 if(BaudeRate<172800)
55 return CBR_115200;
93 return (rs232speed_t)CBR_115200;
56 94 else
57 return CBR_256000;
95 return (rs232speed_t)CBR_256000;
58 96 }
59 97
60 98
61 99 rs232port_t rs232open(char* psPortName)
62 100 {
63 101 rs232port_t fd;
64 fd = CreateFile(psPortName,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
102 fd = (rs232port_t)CreateFile(psPortName,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
103 #ifdef debug
104 if(fd==INVALID_HANDLE_VALUE)
105 {
106 printf("can't open Port\n");
107 return (rs232port_t)badPortValue;
108 }
109 #endif
65 110 return fd;
66 111 }
67 112
68 113 int rs232close(rs232port_t fd)
69 114 {
70 if (fd == badPortValue)
115 if (fd == (rs232port_t)INVALID_HANDLE_VALUE)
71 116 {
72 return -1;
117 return (rs232port_t)badPortValue;
73 118 }
74 119 else
75 120 {
76 CloseHandle(fd);
77 return 0;
121 CloseHandle((HANDLE)fd);
122 return rs232noerr;
78 123 }
79 124 }
80 125
81 126 int rs232setup(rs232port_t fd, int ChSize, int BaudeRate, rs232parity Parity, rs232stop NbStop)
82 127 {
83 if (fd == badPortValue)
128 if (fd == (rs232port_t)INVALID_HANDLE_VALUE)
84 129 {
85 return -1;
130 return (rs232port_t)badPortValue;
86 131 }
87 132 else
88 133 {
89 134 DCB dcbSerialParams = {0};
90 135 dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
91 GetCommState(fd, &dcbSerialParams);
136 GetCommState((HANDLE)fd, &dcbSerialParams);
92 137 dcbSerialParams.BaudRate=rs232cfspeed(BaudeRate);
93 138 dcbSerialParams.ByteSize=ChSize;
94 dcbSerialParams.StopBits=NbStop;
95 dcbSerialParams.Parity=Parity;
96 SetCommState(fd, &dcbSerialParams);
139 dcbSerialParams.StopBits=privatedecodestop(NbStop);
140 dcbSerialParams.Parity=privatedecodeparity(Parity);
141 SetCommState((HANDLE)fd, &dcbSerialParams);
97 142 COMMTIMEOUTS timeouts={0};
98 143 timeouts.ReadIntervalTimeout=100;
99 144 timeouts.ReadTotalTimeoutConstant=100;
100 145 timeouts.ReadTotalTimeoutMultiplier=1;
101 146 timeouts.WriteTotalTimeoutConstant=100;
102 147 timeouts.WriteTotalTimeoutMultiplier=10;
103 SetCommTimeouts(fd, &timeouts);
104 return 0;
148 SetCommTimeouts((HANDLE)fd, &timeouts);
149 return rs232noerr;
105 150 }
106 151 }
107 152
108 153 int rs232setbaudrate(rs232port_t fd, int baudrate)
109 154 {
110 if (fd == badPortValue)
155 if (fd == (rs232port_t)INVALID_HANDLE_VALUE)
111 156 {
112 return -1;
157 return (rs232port_t)badPortValue;
113 158 }
114 159 else
115 160 {
116 161 DCB dcbSerialParams = {0};
117 162 dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
118 GetCommState(fd, &dcbSerialParams);
163 GetCommState((HANDLE)fd, &dcbSerialParams);
119 164 dcbSerialParams.BaudRate=rs232cfspeed(baudrate);
120 SetCommState(fd, &dcbSerialParams);
121 return 0;
165 SetCommState((HANDLE)fd, &dcbSerialParams);
166 return rs232noerr;
122 167 }
123 168 }
124 169
125 170 int rs232setparity(rs232port_t fd, rs232parity Parity)
126 171 {
127 if (fd == badPortValue)
172 if (fd == (rs232port_t)INVALID_HANDLE_VALUE)
128 173 {
129 return -1;
174 return (rs232port_t)badPortValue;
130 175 }
131 176 else
132 177 {
133 178 DCB dcbSerialParams = {0};
134 179 dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
135 GetCommState(fd, &dcbSerialParams);
136 dcbSerialParams.Parity = Parity;
137 SetCommState(fd, &dcbSerialParams);
138 return 0;
180 GetCommState((HANDLE)fd, &dcbSerialParams);
181 dcbSerialParams.Parity = privatedecodeparity(Parity);
182 SetCommState((HANDLE)fd, &dcbSerialParams);
183 return rs232noerr;
139 184 }
140 185 }
141 186
142 187 int rs232setnbstop(rs232port_t fd, rs232stop NbStop)
143 188 {
144 if (fd == badPortValue)
189 if (fd == (rs232port_t)INVALID_HANDLE_VALUE)
145 190 {
146 return -1;
191 return (rs232port_t)badPortValue;
147 192 }
148 193 else
149 194 {
150 195 DCB dcbSerialParams = {0};
151 196 dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
152 GetCommState(fd, &dcbSerialParams);
153 switch(NbStop)
154 {
155 case 2:
156 dcbSerialParams.StopBits = 2;
157 break;
158 default:
159 dcbSerialParams.StopBits = 1;
160 break;
161 }
162 SetCommState(fd, &dcbSerialParams);
163 return 0;
197 GetCommState((HANDLE)fd, &dcbSerialParams);
198 dcbSerialParams.StopBits = privatedecodestop(NbStop);
199 SetCommState((HANDLE)fd, &dcbSerialParams);
200 return rs232noerr;
164 201 }
165 202 }
166 203
167 204
168 205 int rs232setcsize(rs232port_t fd, int ChSize)
169 206 {
170 if (fd == badPortValue)
207 if (fd == (rs232port_t)INVALID_HANDLE_VALUE)
171 208 {
172 return -1;
209 return (rs232port_t)badPortValue;
173 210 }
174 211 else
175 212 {
176 213 DCB dcbSerialParams = {0};
177 214 dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
178 GetCommState(fd, &dcbSerialParams);
215 GetCommState((HANDLE)fd, &dcbSerialParams);
179 216 dcbSerialParams.ByteSize = ChSize;
180 SetCommState(fd, &dcbSerialParams);
181 return 0;
217 SetCommState((HANDLE)fd, &dcbSerialParams);
218 return rs232noerr;
182 219 }
183 220 }
184 221
@@ -190,14 +227,14 int rs232setcsize(rs232port_t fd, int Ch
190 227 int rs232write(rs232port_t fd,char *psWrite, int WriteBufferSize)
191 228 {
192 229
193 if (fd == badPortValue)
230 if (fd == (rs232port_t)INVALID_HANDLE_VALUE)
194 231 {
195 return -1;
232 return (rs232port_t)badPortValue;
196 233 }
197 234 else
198 235 {
199 236 DWORD dwBytesWriten = 0;
200 WriteFile(fd, psWrite, WriteBufferSize, &dwBytesWriten, NULL);
237 WriteFile((HANDLE)fd, psWrite, WriteBufferSize, &dwBytesWriten, NULL);
201 238 return dwBytesWriten;
202 239 }
203 240 }
@@ -206,14 +243,14 int rs232write(rs232port_t fd,char *psWr
206 243 int rs232read(rs232port_t fd,char *psRead, int ReadBufferSize)
207 244 {
208 245
209 if (fd == badPortValue)
246 if (fd == (rs232port_t)INVALID_HANDLE_VALUE)
210 247 {
211 return -1;
248 return (rs232port_t)badPortValue;
212 249 }
213 250 else
214 251 {
215 252 DWORD dwBytesRead = 0;
216 ReadFile(fd, psRead, ReadBufferSize, &dwBytesRead, NULL);
253 ReadFile((HANDLE)fd, psRead, ReadBufferSize, &dwBytesRead, NULL);
217 254 return dwBytesRead;
218 255 }
219 256
@@ -230,7 +267,7 int rs232saferead(rs232port_t fd,char* d
230 267 count -=read;
231 268 data+=read;
232 269 if(count==0)
233 return 0;
270 return rs232noerr;
234 271 }
235 272 return -1;
236 273 }
@@ -247,7 +284,7 int rs232safewrite(rs232port_t fd,char*
247 284 count-=written;
248 285 data+=written;
249 286 if(count==0)
250 return 0;
287 return rs232noerr;
251 288 }
252 289 return -1;
253 290 }
@@ -255,30 +292,30 int rs232safewrite(rs232port_t fd,char*
255 292
256 293 int rs232setRTS(rs232port_t fd)
257 294 {
258 if(EscapeCommFunction(fd, CLRRTS))
259 return 0;
295 if(EscapeCommFunction((HANDLE)fd, CLRRTS))
296 return rs232noerr;
260 297 return -1;
261 298 }
262 299
263 300 int rs232clearRTS(rs232port_t fd)
264 301 {
265 if(EscapeCommFunction(fd, SETRTS))
266 return 0;
302 if(EscapeCommFunction((HANDLE)fd, SETRTS))
303 return rs232noerr;
267 304 return -1;
268 305 }
269 306
270 307 int rs232setDTR(rs232port_t fd)
271 308 {
272 if(EscapeCommFunction(fd, CLRDTR))
273 return 0;
309 if(EscapeCommFunction((HANDLE)fd, CLRDTR))
310 return rs232noerr;
274 311 return -1;
275 312 }
276 313
277 314
278 315 int rs232clearDTR(rs232port_t fd)
279 316 {
280 if(EscapeCommFunction(fd, SETDTR))
281 return 0;
317 if(EscapeCommFunction((HANDLE)fd, SETDTR))
318 return rs232noerr;
282 319 return -1;
283 320 }
284 321
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now