@@ -1,7 +1,7 | |||||
1 | # -*- Autoconf -*- |
|
1 | # -*- Autoconf -*- | |
2 | # Process this file with autoconf to produce a configure script. |
|
2 | # Process this file with autoconf to produce a configure script. | |
3 | AC_PREREQ([2.67]) |
|
3 | AC_PREREQ([2.67]) | |
4 |
AC_INIT([librs232],[ |
|
4 | AC_INIT([librs232],[2.0.0],[alexis.jeandet@lpp.polytechnique.fr],[rs232],[http://www.lpp.fr]) | |
5 | AM_INIT_AUTOMAKE([1.10 -Wall foreign]) |
|
5 | AM_INIT_AUTOMAKE([1.10 -Wall foreign]) | |
6 | AC_CONFIG_MACRO_DIR([m4]) |
|
6 | AC_CONFIG_MACRO_DIR([m4]) | |
7 | # Checks for programs. |
|
7 | # Checks for programs. | |
@@ -18,10 +18,10 AM_PROG_LIBTOOL | |||||
18 | # Checks for libraries. |
|
18 | # Checks for libraries. | |
19 |
|
19 | |||
20 | # Checks for header files. |
|
20 | # Checks for header files. | |
21 | AC_CHECK_HEADERS([stdio.h string.h fcntl.h errno.h unistd.h termios.h windows.h]) |
|
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], [ |
|
23 | AC_SUBST([RS232_SO_VERSION], [2:0:0]) | |
24 |
AC_SUBST([RS232_API_VERSION], [ |
|
24 | AC_SUBST([RS232_API_VERSION], [2.0]) | |
25 | # Checks for typedefs, structures, and compiler characteristics. |
|
25 | # Checks for typedefs, structures, and compiler characteristics. | |
26 |
|
26 | |||
27 | # Checks for library functions. |
|
27 | # Checks for library functions. |
@@ -36,6 +36,12 rs232extern int rs232setparity(rs232port | |||||
36 | rs232extern int rs232setnbstop(rs232port_t fd, rs232stop NbStop); |
|
36 | rs232extern int rs232setnbstop(rs232port_t fd, rs232stop NbStop); | |
37 | rs232extern int rs232setcsize(rs232port_t fd, int ChSize); |
|
37 | rs232extern int rs232setcsize(rs232port_t fd, int ChSize); | |
38 | rs232extern int rs232setbaudrate(rs232port_t fd, int baudrate); |
|
38 | rs232extern int rs232setbaudrate(rs232port_t fd, int baudrate); | |
|
39 | rs232extern int rs232setRTS(rs232port_t fd); | |||
|
40 | rs232extern int rs232clearRTS(rs232port_t fd); | |||
|
41 | rs232extern int rs232setDTR(rs232port_t fd); | |||
|
42 | rs232extern int rs232clearDTR(rs232port_t fd); | |||
|
43 | rs232extern int rs232saferead(rs232port_t fd,char* data,int count ); | |||
|
44 | rs232extern int rs232safewrite(rs232port_t fd,char* data,int count); | |||
39 |
|
45 | |||
40 | #endif |
|
46 | #endif | |
41 |
|
47 |
@@ -7,6 +7,9 | |||||
7 | #ifdef HAVE_TERMIOS_H |
|
7 | #ifdef HAVE_TERMIOS_H | |
8 | #include <termios.h> |
|
8 | #include <termios.h> | |
9 | #endif |
|
9 | #endif | |
|
10 | #ifdef HAVE_TERMIO_H | |||
|
11 | #include <termio.h> | |||
|
12 | #endif | |||
10 | #include "RS232.h" |
|
13 | #include "RS232.h" | |
11 |
|
14 | |||
12 | #ifdef HAVE_WINDOWS_H |
|
15 | #ifdef HAVE_WINDOWS_H | |
@@ -95,6 +98,8 int rs232setparity(rs232port_t fd, rs232 | |||||
95 | { |
|
98 | { | |
96 | struct termios terminos; |
|
99 | struct termios terminos; | |
97 | tcgetattr(fd, &terminos); |
|
100 | tcgetattr(fd, &terminos); | |
|
101 | terminos.c_cflag &= ~PARENB; | |||
|
102 | terminos.c_cflag &= ~PARODD; | |||
98 | switch(Parity) |
|
103 | switch(Parity) | |
99 | { |
|
104 | { | |
100 | case rs232parityNo: |
|
105 | case rs232parityNo: | |
@@ -152,6 +157,7 int rs232setcsize(rs232port_t fd, int Ch | |||||
152 | { |
|
157 | { | |
153 | struct termios terminos; |
|
158 | struct termios terminos; | |
154 | tcgetattr(fd, &terminos); |
|
159 | tcgetattr(fd, &terminos); | |
|
160 | terminos.c_cflag &= ~CSIZE; | |||
155 | switch(ChSize) |
|
161 | switch(ChSize) | |
156 | { |
|
162 | { | |
157 | case 5: |
|
163 | case 5: | |
@@ -240,21 +246,25 int rs232cfparity(int fd, struct termios | |||||
240 | } |
|
246 | } | |
241 | else |
|
247 | else | |
242 | { |
|
248 | { | |
|
249 | terminos->c_cflag &= ~PARENB; | |||
|
250 | terminos->c_cflag &= ~PARODD; | |||
243 | switch(Parity) |
|
251 | switch(Parity) | |
244 | { |
|
252 | { | |
245 | case rs232parityNo: |
|
253 | case rs232parityNo: | |
246 |
terminos->c_cflag &= |
|
254 | terminos->c_cflag &= ~PARENB; | |
|
255 | terminos->c_cflag &= ~PARODD; | |||
247 | break; |
|
256 | break; | |
248 | case rs232parityOdd: |
|
257 | case rs232parityOdd: | |
249 |
terminos->c_cflag |
|
258 | terminos->c_cflag |= PARENB; | |
250 |
terminos->c_cflag |= P |
|
259 | terminos->c_cflag |= PARODD; | |
251 | break; |
|
260 | break; | |
252 | case rs232parityEven: |
|
261 | case rs232parityEven: | |
253 |
terminos->c_cflag |
|
262 | terminos->c_cflag |= PARENB; | |
254 |
terminos->c_cflag |
|
263 | terminos->c_cflag &= ~PARODD; | |
255 | break; |
|
264 | break; | |
256 | default: |
|
265 | default: | |
257 | terminos->c_cflag &= ~PARENB; |
|
266 | terminos->c_cflag &= ~PARENB; | |
|
267 | terminos->c_cflag &= ~PARODD; | |||
258 | break; |
|
268 | break; | |
259 | } |
|
269 | } | |
260 | return 0; |
|
270 | return 0; | |
@@ -291,6 +301,7 int rs232cfcsize(int fd, struct termios | |||||
291 | } |
|
301 | } | |
292 | else |
|
302 | else | |
293 | { |
|
303 | { | |
|
304 | terminos->c_cflag &= ~CSIZE; | |||
294 | switch(ChSize) |
|
305 | switch(ChSize) | |
295 | { |
|
306 | { | |
296 | case 5: |
|
307 | case 5: | |
@@ -338,6 +349,90 int rs232read(rs232port_t fd,char *psRea | |||||
338 |
|
349 | |||
339 | } |
|
350 | } | |
340 |
|
351 | |||
|
352 | ||||
|
353 | int rs232setRTS(rs232port_t fd) | |||
|
354 | { | |||
|
355 | int status; | |||
|
356 | ioctl(fd, TIOCMGET, &status); | |||
|
357 | status &= ~TIOCM_RTS; | |||
|
358 | if (ioctl(fd, TIOCMSET, &status)) | |||
|
359 | { | |||
|
360 | return -1; | |||
|
361 | } | |||
|
362 | return 0; | |||
|
363 | } | |||
|
364 | ||||
|
365 | int rs232clearRTS(rs232port_t fd) | |||
|
366 | { | |||
|
367 | int status; | |||
|
368 | ioctl(fd, TIOCMGET, &status); | |||
|
369 | status |= TIOCM_RTS; | |||
|
370 | if (ioctl(fd, TIOCMSET, &status)) | |||
|
371 | { | |||
|
372 | return -1; | |||
|
373 | } | |||
|
374 | return 0; | |||
|
375 | } | |||
|
376 | ||||
|
377 | int rs232setDTR(rs232port_t fd) | |||
|
378 | { | |||
|
379 | int status; | |||
|
380 | ioctl(fd, TIOCMGET, &status); | |||
|
381 | status &= ~TIOCM_DTR; | |||
|
382 | if (ioctl(fd, TIOCMSET, &status)) | |||
|
383 | { | |||
|
384 | return -1; | |||
|
385 | } | |||
|
386 | return 0; | |||
|
387 | } | |||
|
388 | ||||
|
389 | ||||
|
390 | int rs232clearDTR(rs232port_t fd) | |||
|
391 | { | |||
|
392 | int status; | |||
|
393 | ioctl(fd, TIOCMGET, &status); | |||
|
394 | status |= TIOCM_DTR; | |||
|
395 | if (ioctl(fd, TIOCMSET, &status)) | |||
|
396 | { | |||
|
397 | return -1; | |||
|
398 | } | |||
|
399 | return 0; | |||
|
400 | } | |||
|
401 | ||||
|
402 | ||||
|
403 | ||||
|
404 | int rs232saferead(rs232port_t fd,char* data,int count ) | |||
|
405 | { | |||
|
406 | int read=0; | |||
|
407 | int i=0; | |||
|
408 | for(i=0;i<100;i++) | |||
|
409 | { | |||
|
410 | read = rs232read(fd,data,count); | |||
|
411 | count -=read; | |||
|
412 | data+=read; | |||
|
413 | if(count==0) | |||
|
414 | return 0; | |||
|
415 | } | |||
|
416 | return -1; | |||
|
417 | } | |||
|
418 | ||||
|
419 | ||||
|
420 | ||||
|
421 | int rs232safewrite(rs232port_t fd,char* data,int count) | |||
|
422 | { | |||
|
423 | int written=0; | |||
|
424 | int i=0; | |||
|
425 | for(i=0;i<1000;i++) | |||
|
426 | { | |||
|
427 | written = rs232write(fd,data+written,count); | |||
|
428 | count-=written; | |||
|
429 | data+=written; | |||
|
430 | if(count==0) | |||
|
431 | return 0; | |||
|
432 | } | |||
|
433 | return -1; | |||
|
434 | } | |||
|
435 | ||||
341 | #endif |
|
436 | #endif | |
342 | #endif //#ifdef HAVE_TERMIOS_H |
|
437 | #endif //#ifdef HAVE_TERMIOS_H | |
343 |
|
438 |
@@ -220,4 +220,68 int rs232read(rs232port_t fd,char *psRea | |||||
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 |
|
222 | |||
|
223 | int rs232saferead(rs232port_t fd,char* data,int count ) | |||
|
224 | { | |||
|
225 | int read=0; | |||
|
226 | int i=0; | |||
|
227 | for(i=0;i<100;i++) | |||
|
228 | { | |||
|
229 | read = rs232read(fd,data,count); | |||
|
230 | count -=read; | |||
|
231 | data+=read; | |||
|
232 | if(count==0) | |||
|
233 | return 0; | |||
|
234 | } | |||
|
235 | return -1; | |||
|
236 | } | |||
|
237 | ||||
|
238 | ||||
|
239 | ||||
|
240 | int rs232safewrite(rs232port_t fd,char* data,int count) | |||
|
241 | { | |||
|
242 | int written=0; | |||
|
243 | int i=0; | |||
|
244 | for(i=0;i<1000;i++) | |||
|
245 | { | |||
|
246 | written = rs232write(fd,data+written,count); | |||
|
247 | count-=written; | |||
|
248 | data+=written; | |||
|
249 | if(count==0) | |||
|
250 | return 0; | |||
|
251 | } | |||
|
252 | return -1; | |||
|
253 | } | |||
|
254 | ||||
|
255 | ||||
|
256 | int rs232setRTS(rs232port_t fd) | |||
|
257 | { | |||
|
258 | if(EscapeCommFunction(fd, SETRTS)) | |||
|
259 | return 0; | |||
|
260 | return -1; | |||
|
261 | } | |||
|
262 | ||||
|
263 | int rs232clearRTS(rs232port_t fd) | |||
|
264 | { | |||
|
265 | if(EscapeCommFunction(fd, CLRRTS)) | |||
|
266 | return 0; | |||
|
267 | return -1; | |||
|
268 | } | |||
|
269 | ||||
|
270 | int rs232setDTR(rs232port_t fd) | |||
|
271 | { | |||
|
272 | if(EscapeCommFunction(fd, SETDTR)) | |||
|
273 | return 0; | |||
|
274 | return -1; | |||
|
275 | } | |||
|
276 | ||||
|
277 | ||||
|
278 | int rs232clearDTR(rs232port_t fd) | |||
|
279 | { | |||
|
280 | if(EscapeCommFunction(fd, CLRDTR)) | |||
|
281 | return 0; | |||
|
282 | return -1; | |||
|
283 | } | |||
|
284 | ||||
|
285 | ||||
|
286 | ||||
223 | #endif //#ifdef HAVE_WINDOWS_H |
|
287 | #endif //#ifdef HAVE_WINDOWS_H |
@@ -39,6 +39,9 | |||||
39 | /* Define to 1 if you have the <termios.h> header file. */ |
|
39 | /* Define to 1 if you have the <termios.h> header file. */ | |
40 | #undef HAVE_TERMIOS_H |
|
40 | #undef HAVE_TERMIOS_H | |
41 |
|
41 | |||
|
42 | /* Define to 1 if you have the <termio.h> header file. */ | |||
|
43 | #undef HAVE_TERMIO_H | |||
|
44 | ||||
42 | /* Define to 1 if you have the <unistd.h> header file. */ |
|
45 | /* Define to 1 if you have the <unistd.h> header file. */ | |
43 | #undef HAVE_UNISTD_H |
|
46 | #undef HAVE_UNISTD_H | |
44 |
|
47 |
General Comments 0
You need to be logged in to leave comments.
Login now