Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fd = open("/dev/ttyUSB0", O_RDONLY | O_NOCTTY);
- if (Fd == -1) {
- printf("Could not open serial port: %sn", strerror(errno));
- return 1;
- }
- fcntl(Fd, F_SETFL, 0);
- char buf;
- while (1) {
- read(Fd, &buf, 1);
- printf("%c", buf);
- }
- void signal_callback_handler(int signum) {
- printf("Caught SIGTERMn");
- close(Fd);
- exit(signum);
- }
- signal(SIGINT, signal_callback_handler);
- Boot.
- ^CTo send: Caught SIGTERM
- struct termios port_settings; // structure to store the port settings in
- cfsetispeed(&port_settings, B115200); // set baud rates
- cfsetospeed(&port_settings, B115200);
- port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
- port_settings.c_cflag &= ~CSTOPB;
- port_settings.c_cflag &= ~CSIZE;
- port_settings.c_cflag |= CS8;
- tcsetattr(Fd, TCSANOW, &port_settings);// apply the settings to the port
Add Comment
Please, Sign In to add comment