@@ -25,14 +25,14 rs232speed_t rs232cfspeed(unsigned int B | |||
|
25 | 25 | |
|
26 | 26 | rs232port_t rs232open(char* psPortName) |
|
27 | 27 | { |
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
28 | rs232port_t fd; | |
|
29 | fd = (rs232port_t)open(psPortName, O_RDWR | O_NOCTTY | O_NDELAY); | |
|
30 | fcntl((int)fd, F_SETFL, FNDELAY); | |
|
31 | //fd = open(psPortName, O_RDWR | O_NOCTTY); | |
|
32 | #ifdef debug | |
|
33 | if(fd==-1)printf("can't open Port\n"); | |
|
34 | #endif | |
|
35 | return fd; | |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | int rs232close(rs232port_t fd) |
@@ -125,6 +125,10 int rs232setup(rs232port_t fd, int ChSiz | |||
|
125 | 125 | { |
|
126 | 126 | struct termios terminos; |
|
127 | 127 | tcgetattr(fd, &terminos); |
|
128 | terminos.c_iflag=0; | |
|
129 | terminos.c_oflag=0; | |
|
130 | terminos.c_cflag=0; | |
|
131 | terminos.c_lflag=0; | |
|
128 | 132 | cfsetispeed(&terminos, rs232cfspeed(BaudeRate)); |
|
129 | 133 | cfsetospeed(&terminos, rs232cfspeed(BaudeRate)); |
|
130 | 134 | terminos.c_cflag |= (CLOCAL | CREAD); |
@@ -483,13 +487,16 int rs232saferead(rs232port_t fd,char* d | |||
|
483 | 487 | { |
|
484 | 488 | int read=0; |
|
485 | 489 | int i=0; |
|
486 | for(i=0;i<100;i++) | |
|
490 | for(i=0;i<1000;i++) | |
|
487 | 491 | { |
|
488 | 492 | read = rs232read((int)fd,data,count); |
|
489 | count -=read; | |
|
493 | //printf("read %d bytes\n",read); | |
|
494 | if(read==-1)read=0; | |
|
495 | count-=read; | |
|
490 | 496 | data+=read; |
|
491 | 497 | if(count==0) |
|
492 | 498 | return 0; |
|
499 | usleep(10); | |
|
493 | 500 | } |
|
494 | 501 | return -1; |
|
495 | 502 | } |
@@ -503,6 +510,8 int rs232safewrite(rs232port_t fd,char* | |||
|
503 | 510 | for(i=0;i<1000;i++) |
|
504 | 511 | { |
|
505 | 512 | written = rs232write((int)fd,data+written,count); |
|
513 | //printf("%d bytes written\n",written); | |
|
514 | if(written==-1)written=0; | |
|
506 | 515 | count-=written; |
|
507 | 516 | data+=written; |
|
508 | 517 | if(count==0) |
General Comments 0
You need to be logged in to leave comments.
Login now