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