Beste Tweakers,
Ik ben een applicatie aan het ontwikkelen dat seriele adc data via rs232 inleest en vervolgens parsed.
In mijn applicatie gebruik ik de read functie om de rs232 data via de device file in te lezen.
in een termios struct configureer ik de seriele poort:
De read functie blockt net zolang tot dat aan deze voorwaarden wordt voldaan. Ik maak nu gebruik van non-canonical processing en read net zo lang tot dat ik de complete chunk aan data (840 bytes) binnen heb.
Iedere chunk aan data dat door de rs232 apparaat word verstuurd eindigd met een \n. Is het mogelijk mijn tty config zo aan te passen dat de read functie pas returned als het \n karakter voorbij komt?
Ik ben een applicatie aan het ontwikkelen dat seriele adc data via rs232 inleest en vervolgens parsed.
In mijn applicatie gebruik ik de read functie om de rs232 data via de device file in te lezen.
in een termios struct configureer ik de seriele poort:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| fd = open(dev, O_RDWR | O_NOCTTY ); if(fd < 0) { perror("open"); exit(1); } memset(&tty, 0 , sizeof(tty)); //set baudrate cfsetospeed (&tty, B115200); cfsetispeed (&tty, B115200); tty.c_cflag &= ~PARENB; //Make 8n1 tty.c_cflag &= ~CSTOPB; tty.c_cflag &= ~CSIZE; tty.c_cflag |= CS8; tty.c_cflag &= ~CRTSCTS; //no flow control tty.c_lflag = 0; //no signaling chars, no echo, no canonical tty.c_oflag = 0; //no remapping, no delays tty.c_cc[VMIN] = 1; //minimal amount of bytes tty.c_cc[VTIME] = 0; tty.c_cflag |= CREAD | BRKINT | CLOCAL; //turn on read ignore c tty.c_iflag &= ~(IXON | IXOFF | IXANY); //turn off sw en flow c tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //make raw tty.c_oflag &= ~OPOST; //make raw //flush port tcflush( fd, TCIFLUSH ); if (tcsetattr(fd, TCSANOW, &tty) != 0) { perror("tty"); exit(1); } |
De read functie blockt net zolang tot dat aan deze voorwaarden wordt voldaan. Ik maak nu gebruik van non-canonical processing en read net zo lang tot dat ik de complete chunk aan data (840 bytes) binnen heb.
Iedere chunk aan data dat door de rs232 apparaat word verstuurd eindigd met een \n. Is het mogelijk mijn tty config zo aan te passen dat de read functie pas returned als het \n karakter voorbij komt?