##// END OF EJS Templates
Changed to qmake build system.
Jeandet Alexis -
r44:81254c2cf763 qt
parent child
Show More
@@ -0,0 +1,18
1
2 TEMPLATE = lib
3 CONFIG -= qt
4 CONFIG += static
5
6 HEADERS += \
7 src/RS232.h
8
9 win32:SOURCES += src/RS232_win.c
10
11 unix:SOURCES += src/RS232_unix.c
12
13 debug:DEFINES+=RS232_debug
14
15 DESTDIR=lib
16
17 OBJECTS_DIR = obj
18
@@ -1,7 +1,6
1 // SOPSUYSI_RS232.h
1 // SOPSUYSI_RS232.h
2 #ifndef RS232_H
2 #ifndef RS232_H
3 #define RS232_H
3 #define RS232_H
4 #define RS232_debug
5
4
6 #define badPortValue -1
5 #define badPortValue -1
7 #define rs232noerr 0
6 #define rs232noerr 0
This diff has been collapsed as it changes many lines, (862 lines changed) Show them Hide them
@@ -8,551 +8,541
8 #include <limits.h>
8 #include <limits.h>
9 #include <stdlib.h>
9 #include <stdlib.h>
10 #include <sys/stat.h>
10 #include <sys/stat.h>
11 #include "rs232config.h"
12
11
13 #ifdef HAVE_TERMIOS_H
12 #include <termios.h>
14 #include <termios.h>
13 #include <termio.h>
15 #endif
16 #ifdef HAVE_TERMIO_H
17 #include <termio.h>
18 #endif
19 #include "RS232.h"
14 #include "RS232.h"
20
15
21 #ifdef HAVE_WINDOWS_H
22 #else
23 #ifdef HAVE_TERMIOS_H
24 rs232speed_t rs232cfspeed(unsigned int BaudeRate);
16 rs232speed_t rs232cfspeed(unsigned int BaudeRate);
25
17
26 rs232port_t rs232open(char* psPortName)
18 rs232port_t rs232open(char* psPortName)
27 {
19 {
28 rs232port_t fd;
20 rs232port_t fd;
29 int flags;
21 int flags;
30 fd = (rs232port_t)open(psPortName, O_RDWR | O_NOCTTY );//| O_NDELAY);
22 fd = (rs232port_t)open(psPortName, O_RDWR | O_NOCTTY );//| O_NDELAY);
31 //fcntl((int)fd, F_SETFL, FNDELAY);
23 //fcntl((int)fd, F_SETFL, FNDELAY);
32 //fd = open(psPortName, O_RDWR | O_NOCTTY);
24 //fd = open(psPortName, O_RDWR | O_NOCTTY);
33 #ifdef RS232_debug
25 #ifdef RS232_debug
34 if(fd==-1)printf("can't open Port\n");
26 if(fd==-1)printf("can't open Port\n");
35 #else
27 #else
36 if(fd!=-1)
28 if(fd!=-1)
37 {
29 {
38 //flags = fcntl(fd, F_GETFL);
30 //flags = fcntl(fd, F_GETFL);
39 //flags |= O_NONBLOCK;
31 //flags |= O_NONBLOCK;
40 //flags|=FNDELAY;
32 //flags|=FNDELAY;
41 //fcntl(fd, F_SETFL, flags);
33 //fcntl(fd, F_SETFL, flags);
42 //fcntl((int)fd, F_SETFL, FNDELAY);
34 //fcntl((int)fd, F_SETFL, FNDELAY);
43 }
35 }
44
36
45 #endif
37 #endif
46 return fd;
38 return fd;
47 }
39 }
48
40
49 int rs232close(rs232port_t fd)
41 int rs232close(rs232port_t fd)
50 {
42 {
51 if ((int)fd == -1)
43 if ((int)fd == -1)
52 {
44 {
53 return -1;
45 return -1;
54 }
46 }
55 else
47 else
56 {
48 {
57 close(fd);
49 close(fd);
58 return 0;
50 return 0;
59 }
51 }
60 }
52 }
61
53
62 rs232portslist_t* rs232getportlist()
54 rs232portslist_t* rs232getportlist()
63 {
55 {
64 struct dirent *dp;
56 struct dirent *dp;
65 char* path="/dev/serial/by-id";
57 char* path="/dev/serial/by-id";
66 DIR *dir = opendir(path);
58 DIR *dir = opendir(path);
67 rs232portslist_t* firstitem=NULL;
59 rs232portslist_t* firstitem=NULL;
68 rs232portslist_t* previtem=NULL;
60 rs232portslist_t* previtem=NULL;
69 char linkname[1024];
61 char linkname[1024];
70 int i=0;
62 int i=0;
71 if(dir!=NULL)
63 if(dir!=NULL)
72 {
64 {
73 while ((dp=readdir(dir)) != NULL)
65 while ((dp=readdir(dir)) != NULL)
74 {
66 {
75 char* name = (char*)malloc(1024);
67 char* name = (char*)malloc(1024);
76 for(i=0;i<1024;i++)
68 for(i=0;i<1024;i++)
77 {
69 {
78 name[i]='\0';
70 name[i]='\0';
79 linkname[i]='\0';
71 linkname[i]='\0';
80 }
72 }
81 struct stat statbuf;
73 struct stat statbuf;
82 strcpy(linkname,path);
74 strcpy(linkname,path);
83 strcat(linkname,"/");
75 strcat(linkname,"/");
84 strcat(linkname,dp->d_name);
76 strcat(linkname,dp->d_name);
85 lstat(linkname, &statbuf);
77 lstat(linkname, &statbuf);
86 if(S_ISLNK(statbuf.st_mode))
78 if(S_ISLNK(statbuf.st_mode))
87 {
79 {
88 if(-1!=readlink(linkname,name,1024))
80 if(-1!=readlink(linkname,name,1024))
89 {
81 {
90 for(i=0;i<1024;i++)
82 for(i=0;i<1024;i++)
91 {
83 {
92 linkname[i]='\0';
84 linkname[i]='\0';
93 }
85 }
94 strcpy(linkname,path);
86 strcpy(linkname,path);
95 strcat(linkname,"/");
87 strcat(linkname,"/");
96 strcat(linkname,name);
88 strcat(linkname,name);
97 for(i=0;i<1024;i++)
89 for(i=0;i<1024;i++)
98 {
90 {
99 name[i]='\0';
91 name[i]='\0';
100 }
92 }
101 if(NULL!=realpath(linkname, name))
93 if(NULL!=realpath(linkname, name))
102 {
94 {
103 rs232portslist_t* item = (rs232portslist_t*)malloc(sizeof(rs232portslist_t));
95 rs232portslist_t* item = (rs232portslist_t*)malloc(sizeof(rs232portslist_t));
104 item->name = name;
96 item->name = name;
105 item->next = NULL;
97 item->next = NULL;
106 if(NULL!=previtem)previtem->next = item;
98 if(NULL!=previtem)previtem->next = item;
107 previtem = item;
99 previtem = item;
108 if(NULL==firstitem)firstitem = item;
100 if(NULL==firstitem)firstitem = item;
109 }
101 }
110
111 }
112 }
113
102
114 }
103 }
115 }
104 }
116 return firstitem;
105
106 }
107 }
108 return firstitem;
117 }
109 }
118
110
119 void rs232deleteportlist(rs232portslist_t* list)
111 void rs232deleteportlist(rs232portslist_t* list)
120 {
112 {
121 if(list!=NULL)
113 if(list!=NULL)
122 {
114 {
123 if(list->next != NULL)
115 if(list->next != NULL)
124 rs232deleteportlist(list->next);
116 rs232deleteportlist(list->next);
125 free(list);
117 free(list);
126 }
118 }
127 }
119 }
128
120
129 int rs232setup(rs232port_t fd, int ChSize, int BaudeRate, rs232parity Parity, rs232stop NbStop)
121 int rs232setup(rs232port_t fd, int ChSize, int BaudeRate, rs232parity Parity, rs232stop NbStop)
130 {
122 {
131 if ((int)fd == -1)
123 if ((int)fd == -1)
132 {
124 {
133 return -1;
125 return -1;
134 }
126 }
135 else
127 else
136 {
128 {
137 struct termios terminos;
129 struct termios terminos;
138 tcgetattr(fd, &terminos);
130 tcgetattr(fd, &terminos);
139 terminos.c_iflag=0;
131 terminos.c_iflag=0;
140 terminos.c_oflag=0;
132 terminos.c_oflag=0;
141 terminos.c_cflag=0;
133 terminos.c_cflag=0;
142 terminos.c_lflag=0;
134 terminos.c_lflag=0;
143 cfsetispeed(&terminos, rs232cfspeed(BaudeRate));
135 cfsetispeed(&terminos, rs232cfspeed(BaudeRate));
144 cfsetospeed(&terminos, rs232cfspeed(BaudeRate));
136 cfsetospeed(&terminos, rs232cfspeed(BaudeRate));
145 terminos.c_cflag |= (CLOCAL | CREAD);
137 terminos.c_cflag |= (CLOCAL | CREAD);
146 rs232cfparity((int)fd, &terminos, Parity);
138 rs232cfparity((int)fd, &terminos, Parity);
147 rs232cfnbstop((int)fd, &terminos, NbStop);
139 rs232cfnbstop((int)fd, &terminos, NbStop);
148 rs232cfcsize((int)fd, &terminos, ChSize);
140 rs232cfcsize((int)fd, &terminos, ChSize);
149 terminos.c_cc[VMIN]=0;
141 terminos.c_cc[VMIN]=0;
150 terminos.c_cc[VTIME]=1;
142 terminos.c_cc[VTIME]=1;
151 tcflush(fd, TCIFLUSH);
143 tcflush(fd, TCIFLUSH);
152 #ifdef RS232_debug
144 #ifdef RS232_debug
153 if(tcsetattr(fd, TCSANOW, &terminos)!=0)printf("bad setup\n");
145 if(tcsetattr(fd, TCSANOW, &terminos)!=0)printf("bad setup\n");
154 #else
146 #else
155 tcsetattr(fd, TCSANOW, &terminos);
147 tcsetattr(fd, TCSANOW, &terminos);
156 #endif
148 #endif
157 return 0;
149 return 0;
158 }
150 }
159 }
151 }
160
152
161 int rs232setbaudrate(rs232port_t fd, int baudrate)
153 int rs232setbaudrate(rs232port_t fd, int baudrate)
162 {
154 {
163 if ((int)fd == -1)
155 if ((int)fd == -1)
164 {
156 {
165 return fd;
157 return fd;
166 }
158 }
167 else
159 else
168 {
160 {
169 struct termios terminos;
161 struct termios terminos;
170 tcgetattr((int)fd, &terminos);
162 tcgetattr((int)fd, &terminos);
171 cfsetispeed(&terminos, rs232cfspeed(baudrate));
163 cfsetispeed(&terminos, rs232cfspeed(baudrate));
172 cfsetospeed(&terminos, rs232cfspeed(baudrate));
164 cfsetospeed(&terminos, rs232cfspeed(baudrate));
173 tcsetattr((int)fd, TCSANOW, &terminos);
165 tcsetattr((int)fd, TCSANOW, &terminos);
174 return 0;
166 return 0;
175 }
167 }
176 }
168 }
177
169
178 int rs232setparity(rs232port_t fd, rs232parity Parity)
170 int rs232setparity(rs232port_t fd, rs232parity Parity)
179 {
171 {
180 if ((int)fd == -1)
172 if ((int)fd == -1)
181 {
173 {
182 return fd;
174 return fd;
183 }
175 }
184 else
176 else
185 {
177 {
186 struct termios terminos;
178 struct termios terminos;
187 tcgetattr((int)fd, &terminos);
179 tcgetattr((int)fd, &terminos);
188 terminos.c_cflag &= ~PARENB;
180 terminos.c_cflag &= ~PARENB;
189 terminos.c_cflag &= ~PARODD;
181 terminos.c_cflag &= ~PARODD;
190 switch(Parity)
182 switch(Parity)
191 {
183 {
192 case rs232parityNo:
184 case rs232parityNo:
193 terminos.c_cflag &= ~PARENB;
185 terminos.c_cflag &= ~PARENB;
194 break;
186 break;
195 case rs232parityOdd:
187 case rs232parityOdd:
196 terminos.c_cflag |= PARENB;
188 terminos.c_cflag |= PARENB;
197 terminos.c_cflag |= PARODD;
189 terminos.c_cflag |= PARODD;
198 break;
190 break;
199 case rs232parityEven:
191 case rs232parityEven:
200 terminos.c_cflag |= PARENB;
192 terminos.c_cflag |= PARENB;
201 terminos.c_cflag &= ~PARODD;
193 terminos.c_cflag &= ~PARODD;
202 break;
194 break;
203 default:
195 default:
204 terminos.c_cflag &= ~PARENB;
196 terminos.c_cflag &= ~PARENB;
205 break;
197 break;
206 }
198 }
207 tcsetattr((int)fd, TCSANOW, &terminos);
199 tcsetattr((int)fd, TCSANOW, &terminos);
208 return 0;
200 return 0;
209 }
201 }
210 }
202 }
211
203
212 int rs232setnbstop(rs232port_t fd, rs232stop NbStop)
204 int rs232setnbstop(rs232port_t fd, rs232stop NbStop)
213 {
205 {
214 if ((int)fd == -1)
206 if ((int)fd == -1)
215 {
207 {
216 return fd;
208 return fd;
217 }
209 }
218 else
210 else
219 {
211 {
220 struct termios terminos;
212 struct termios terminos;
221 tcgetattr((int)fd, &terminos);
213 tcgetattr((int)fd, &terminos);
222 switch(NbStop)
214 switch(NbStop)
223 {
215 {
224 case rs232OneStop:
216 case rs232OneStop:
225 terminos.c_cflag &= ~CSTOPB;
217 terminos.c_cflag &= ~CSTOPB;
226 break;
218 break;
227 case rs232One5Stop:
219 case rs232One5Stop:
228 terminos.c_cflag |= CSTOPB;
220 terminos.c_cflag |= CSTOPB;
229 break;
221 break;
230 case rs232TwoStop:
222 case rs232TwoStop:
231 terminos.c_cflag |= CSTOPB;
223 terminos.c_cflag |= CSTOPB;
232 break;
224 break;
233 default:
225 default:
234 terminos.c_cflag &= ~CSTOPB;
226 terminos.c_cflag &= ~CSTOPB;
235 break;
227 break;
236 }
228 }
237 tcsetattr((int)fd, TCSANOW, &terminos);
229 tcsetattr((int)fd, TCSANOW, &terminos);
238 return 0;
230 return 0;
239 }
231 }
240 }
232 }
241
233
242
234
243 int rs232setcsize(rs232port_t fd, int ChSize)
235 int rs232setcsize(rs232port_t fd, int ChSize)
244 {
236 {
245 if ((int)fd == -1)
237 if ((int)fd == -1)
246 {
238 {
247 return fd;
239 return fd;
248 }
240 }
249 else
241 else
250 {
242 {
251 struct termios terminos;
243 struct termios terminos;
252 tcgetattr((int)fd, &terminos);
244 tcgetattr((int)fd, &terminos);
253 terminos.c_cflag &= ~CSIZE;
245 terminos.c_cflag &= ~CSIZE;
254 switch(ChSize)
246 switch(ChSize)
255 {
247 {
256 case 5:
248 case 5:
257 terminos.c_cflag |= CS5;
249 terminos.c_cflag |= CS5;
258 break;
250 break;
259 case 6:
251 case 6:
260 terminos.c_cflag |= CS6;
252 terminos.c_cflag |= CS6;
261 break;
253 break;
262 case 7:
254 case 7:
263 terminos.c_cflag |= CS7;
255 terminos.c_cflag |= CS7;
264 break;
256 break;
265 default:
257 default:
266 terminos.c_cflag |= CS8;
258 terminos.c_cflag |= CS8;
267 break;
259 break;
268 }
260 }
269 tcsetattr((int)fd, TCSANOW, &terminos);
261 tcsetattr((int)fd, TCSANOW, &terminos);
270 return 0;
262 return 0;
271 }
263 }
272 }
264 }
273
265
274 rs232speed_t rs232cfspeed(unsigned int BaudeRate)
266 rs232speed_t rs232cfspeed(unsigned int BaudeRate)
275 {
267 {
276 if(BaudeRate<25)
268 if(BaudeRate<25)
277 return B0;
269 return B0;
270
271 if(BaudeRate<67)
272 return B50;
273
274 if(BaudeRate<93)
275 return B75;
276
277 if(BaudeRate<123)
278 return B110;
279
280 if(BaudeRate<142)
281 return B134;
282
283 if(BaudeRate<175)
284 return B150;
285
286 if(BaudeRate<250)
287 return B200;
288
289 if(BaudeRate<450)
290 return B300;
291
292 if(BaudeRate<900)
293 return B600;
294
295 if(BaudeRate<1500)
296 return B1200;
297
298 if(BaudeRate<2100)
299 return B1800;
300
301 if(BaudeRate<3600)
302 return B2400;
278
303
279 if(BaudeRate<67)
304 if(BaudeRate<7200)
280 return B50;
305 return B4800;
281
306
282 if(BaudeRate<93)
307 if(BaudeRate<1400)
283 return B75;
308 return B9600;
284
309
285 if(BaudeRate<123)
310 if(BaudeRate<28800)
286 return B110;
311 return B19200;
287
312
288 if(BaudeRate<142)
313 if(BaudeRate<48000)
289 return B134;
314 return B38400;
290
315
291 if(BaudeRate<175)
316 if(BaudeRate<86400)
292 return B150;
317 return B57600;
293
318
294 if(BaudeRate<250)
319 if(BaudeRate<172800)
295 return B200;
320 return B115200;
296
297 if(BaudeRate<450)
298 return B300;
299
300 if(BaudeRate<900)
301 return B600;
302
303 if(BaudeRate<1500)
304 return B1200;
305
306 if(BaudeRate<2100)
307 return B1800;
308
309 if(BaudeRate<3600)
310 return B2400;
311
312 if(BaudeRate<7200)
313 return B4800;
314
315 if(BaudeRate<1400)
316 return B9600;
317
318 if(BaudeRate<28800)
319 return B19200;
320
321 if(BaudeRate<48000)
322 return B38400;
323
324 if(BaudeRate<86400)
325 return B57600;
326
327 if(BaudeRate<172800)
328 return B115200;
329
321
330 if(BaudeRate<345600)
322 if(BaudeRate<345600)
331 return B230400;
323 return B230400;
332
324
333 if(BaudeRate<345600)
325 if(BaudeRate<345600)
334 return B460800;
326 return B460800;
335
327
336 if(BaudeRate<748800)
328 if(BaudeRate<748800)
337 return B576000;
329 return B576000;
338
330
339 if(BaudeRate<1210800)
331 if(BaudeRate<1210800)
340 return B921600;
332 return B921600;
341
333
342 if(BaudeRate<1750000)
334 if(BaudeRate<1750000)
343 return B1500000;
335 return B1500000;
344
336
345 if(BaudeRate<2250000)
337 if(BaudeRate<2250000)
346 return B2000000;
338 return B2000000;
347
339
348 if(BaudeRate<2750000)
340 if(BaudeRate<2750000)
349 return B2500000;
341 return B2500000;
350 else
342 else
351 return B3000000;
343 return B3000000;
352
344
353 }
345 }
354
346
355
347
356 int rs232cfparity(int fd, struct termios *terminos, rs232parity Parity)
348 int rs232cfparity(int fd, struct termios *terminos, rs232parity Parity)
357 {
349 {
358 if ((int)fd == -1)
350 if ((int)fd == -1)
359 {
351 {
360 return fd;
352 return fd;
361 }
353 }
362 else
354 else
363 {
355 {
364 terminos->c_cflag &= ~PARENB;
356 terminos->c_cflag &= ~PARENB;
365 terminos->c_cflag &= ~PARODD;
357 terminos->c_cflag &= ~PARODD;
366 switch(Parity)
358 switch(Parity)
367 {
359 {
368 case rs232parityNo:
360 case rs232parityNo:
369 terminos->c_cflag &= ~PARENB;
361 terminos->c_cflag &= ~PARENB;
370 terminos->c_cflag &= ~PARODD;
362 terminos->c_cflag &= ~PARODD;
371 break;
363 break;
372 case rs232parityOdd:
364 case rs232parityOdd:
373 terminos->c_cflag |= PARENB;
365 terminos->c_cflag |= PARENB;
374 terminos->c_cflag |= PARODD;
366 terminos->c_cflag |= PARODD;
375 break;
367 break;
376 case rs232parityEven:
368 case rs232parityEven:
377 terminos->c_cflag |= PARENB;
369 terminos->c_cflag |= PARENB;
378 terminos->c_cflag &= ~PARODD;
370 terminos->c_cflag &= ~PARODD;
379 break;
371 break;
380 default:
372 default:
381 terminos->c_cflag &= ~PARENB;
373 terminos->c_cflag &= ~PARENB;
382 terminos->c_cflag &= ~PARODD;
374 terminos->c_cflag &= ~PARODD;
383 break;
375 break;
384 }
376 }
385 return 0;
377 return 0;
386 }
378 }
387 }
379 }
388
380
389 int rs232cfnbstop(int fd, struct termios *terminos, rs232stop NbStop)
381 int rs232cfnbstop(int fd, struct termios *terminos, rs232stop NbStop)
390 {
382 {
391 if ((int)fd == -1)
383 if ((int)fd == -1)
392 {
384 {
393 return fd;
385 return fd;
394 }
386 }
395 else
387 else
396 {
388 {
397 switch(NbStop)
389 switch(NbStop)
398 {
390 {
399 case 2:
391 case 2:
400 terminos->c_cflag |= CSTOPB;
392 terminos->c_cflag |= CSTOPB;
401 break;
393 break;
402 default:
394 default:
403 terminos->c_cflag &= ~CSTOPB;
395 terminos->c_cflag &= ~CSTOPB;
404 break;
396 break;
405 }
397 }
406 return 0;
398 return 0;
407 }
399 }
408 }
400 }
409
401
410
402
411 int rs232cfcsize(int fd, struct termios *terminos, int ChSize)
403 int rs232cfcsize(int fd, struct termios *terminos, int ChSize)
412 {
404 {
413 if ((int)fd == -1)
405 if ((int)fd == -1)
414 {
406 {
415 return fd;
407 return fd;
416 }
408 }
417 else
409 else
418 {
410 {
419 terminos->c_cflag &= ~CSIZE;
411 terminos->c_cflag &= ~CSIZE;
420 switch(ChSize)
412 switch(ChSize)
421 {
413 {
422 case 5:
414 case 5:
423 terminos->c_cflag |= CS5;
415 terminos->c_cflag |= CS5;
424 break;
416 break;
425 case 6:
417 case 6:
426 terminos->c_cflag |= CS6;
418 terminos->c_cflag |= CS6;
427 break;
419 break;
428 case 7:
420 case 7:
429 terminos->c_cflag |= CS7;
421 terminos->c_cflag |= CS7;
430 break;
422 break;
431 default:
423 default:
432 terminos->c_cflag |= CS8;
424 terminos->c_cflag |= CS8;
433 break;
425 break;
434 }
426 }
435 return 0;
427 return 0;
436 }
428 }
437 }
429 }
438
430
439
431
440 int rs232write(rs232port_t fd,char *psWrite, int WriteBufferSize)
432 int rs232write(rs232port_t fd,char *psWrite, int WriteBufferSize)
441 {
433 {
442 if ((int)fd == -1)
434 if ((int)fd == -1)
443 {
435 {
444 return -1;
436 return -1;
445 }
437 }
446 else
438 else
447 {
439 {
448 return write((int)fd, psWrite, WriteBufferSize);
440 return write((int)fd, psWrite, WriteBufferSize);
449 }
441 }
450 }
442 }
451
443
452
444
453 int rs232read(rs232port_t fd,char *psReadHex, int ReadBufferSize)
445 int rs232read(rs232port_t fd,char *psReadHex, int ReadBufferSize)
454 {
446 {
455
447
456 if ((int)fd == -1)
448 if ((int)fd == -1)
457 {
449 {
458 return -1;
450 return -1;
459 }
451 }
460 else
452 else
461 {
453 {
462 return read((int)fd, psReadHex, ReadBufferSize);
454 return read((int)fd, psReadHex, ReadBufferSize);
463 }
455 }
464
456
465 }
457 }
466
458
467
459
468 int rs232setRTS(rs232port_t fd)
460 int rs232setRTS(rs232port_t fd)
469 {
461 {
470 int status;
462 int status;
471 ioctl((int)fd, TIOCMGET, &status);
463 ioctl((int)fd, TIOCMGET, &status);
472 status &= ~TIOCM_RTS;
464 status &= ~TIOCM_RTS;
473 if (ioctl((int)fd, TIOCMSET, &status))
465 if (ioctl((int)fd, TIOCMSET, &status))
474 {
466 {
475 return -1;
467 return -1;
476 }
468 }
477 return 0;
469 return 0;
478 }
470 }
479
471
480 int rs232clearRTS(rs232port_t fd)
472 int rs232clearRTS(rs232port_t fd)
481 {
473 {
482 int status;
474 int status;
483 ioctl((int)fd, TIOCMGET, &status);
475 ioctl((int)fd, TIOCMGET, &status);
484 status |= TIOCM_RTS;
476 status |= TIOCM_RTS;
485 if (ioctl((int)fd, TIOCMSET, &status))
477 if (ioctl((int)fd, TIOCMSET, &status))
486 {
478 {
487 return -1;
479 return -1;
488 }
480 }
489 return 0;
481 return 0;
490 }
482 }
491
483
492 int rs232setDTR(rs232port_t fd)
484 int rs232setDTR(rs232port_t fd)
493 {
485 {
494 int status;
486 int status;
495 ioctl((int)fd, TIOCMGET, &status);
487 ioctl((int)fd, TIOCMGET, &status);
496 status &= ~TIOCM_DTR;
488 status &= ~TIOCM_DTR;
497 if (ioctl((int)fd, TIOCMSET, &status))
489 if (ioctl((int)fd, TIOCMSET, &status))
498 {
490 {
499 return -1;
491 return -1;
500 }
492 }
501 return 0;
493 return 0;
502 }
494 }
503
495
504
496
505 int rs232clearDTR(rs232port_t fd)
497 int rs232clearDTR(rs232port_t fd)
506 {
498 {
507 int status;
499 int status;
508 ioctl((int)fd, TIOCMGET, &status);
500 ioctl((int)fd, TIOCMGET, &status);
509 status |= TIOCM_DTR;
501 status |= TIOCM_DTR;
510 if (ioctl((int)fd, TIOCMSET, &status))
502 if (ioctl((int)fd, TIOCMSET, &status))
511 {
503 {
512 return -1;
504 return -1;
513 }
505 }
514 return 0;
506 return 0;
515 }
507 }
516
508
517
509
518
510
519 int rs232saferead(rs232port_t fd,char* data,int count )
511 int rs232saferead(rs232port_t fd,char* data,int count )
520 {
512 {
521 int read=0;
513 int read=0;
522 int i=0;
514 int i=0;
523 for(i=0;i<1000;i++)
515 for(i=0;i<1000;i++)
524 {
516 {
525 read = rs232read((int)fd,data,count);
517 read = rs232read((int)fd,data,count);
526 //printf("read %d bytes\n",read);
518 //printf("read %d bytes\n",read);
527 if(read==-1)read=0;
519 if(read==-1)read=0;
528 count-=read;
520 count-=read;
529 data+=read;
521 data+=read;
530 if(count==0)
522 if(count==0)
531 return 0;
523 return 0;
532 usleep(10);
524 usleep(10);
533 }
525 }
534 return -1;
526 return -1;
535 }
527 }
536
528
537
529
538
530
539 int rs232safewrite(rs232port_t fd,char* data,int count)
531 int rs232safewrite(rs232port_t fd,char* data,int count)
540 {
532 {
541 int written=0;
533 int written=0;
542 int i=0;
534 int i=0;
543 for(i=0;i<1000;i++)
535 for(i=0;i<1000;i++)
544 {
536 {
545 written = rs232write((int)fd,data+written,count);
537 written = rs232write((int)fd,data+written,count);
546 //printf("%d bytes written\n",written);
538 //printf("%d bytes written\n",written);
547 if(written==-1)written=0;
539 if(written==-1)written=0;
548 count-=written;
540 count-=written;
549 data+=written;
541 data+=written;
550 if(count==0)
542 if(count==0)
551 return 0;
543 return 0;
552 }
544 }
553 return -1;
545 return -1;
554 }
546 }
555
547
556 #endif
557 #endif //#ifdef HAVE_TERMIOS_H
558
548
@@ -1,4 +1,3
1 #include "rs232config.h"
2 #include <stdio.h>
1 #include <stdio.h>
3 #include <unistd.h>
2 #include <unistd.h>
4 #include <fcntl.h>
3 #include <fcntl.h>
@@ -6,12 +5,10
6 #include <errno.h>
5 #include <errno.h>
7 #include <malloc.h>
6 #include <malloc.h>
8
7
9 #ifdef HAVE_WINDOWS_H
8 #include <windows.h>
10 #include <windows.h>
11 #endif
12 #include "RS232.h"
9 #include "RS232.h"
13
10
14 #ifdef HAVE_WINDOWS_H
11
15
12
16
13
17 int privatedecodeparity(rs232parity Parity )
14 int privatedecodeparity(rs232parity Parity )
@@ -383,4 +380,4 int rs232clearDTR(rs232port_t fd)
383 return -1;
380 return -1;
384 }
381 }
385
382
386 #endif //#ifdef HAVE_WINDOWS_H
383
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (674 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (732 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (9585 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (14851 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (14852 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (2500 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (597 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1522 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1766 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (14852 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (688 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (527 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (9655 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (7986 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (604 lines changed) Show them Hide them
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