Guest User

Untitled

a guest
Jan 16th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Fd = open("/dev/ttyUSB0", O_RDONLY | O_NOCTTY);
  2. if (Fd == -1) {
  3. printf("Could not open serial port: %sn", strerror(errno));
  4. return 1;
  5. }
  6.  
  7. fcntl(Fd, F_SETFL, 0);
  8.  
  9. char buf;
  10. while (1) {
  11. read(Fd, &buf, 1);
  12. printf("%c", buf);
  13. }
  14.  
  15. void signal_callback_handler(int signum) {
  16. printf("Caught SIGTERMn");
  17. close(Fd);
  18. exit(signum);
  19. }
  20.  
  21. signal(SIGINT, signal_callback_handler);
  22.  
  23. Boot.
  24. ^CTo send: Caught SIGTERM
  25.  
  26. struct termios port_settings; // structure to store the port settings in
  27. cfsetispeed(&port_settings, B115200); // set baud rates
  28. cfsetospeed(&port_settings, B115200);
  29. port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
  30. port_settings.c_cflag &= ~CSTOPB;
  31. port_settings.c_cflag &= ~CSIZE;
  32. port_settings.c_cflag |= CS8;
  33. tcsetattr(Fd, TCSANOW, &port_settings);// apply the settings to the port
Add Comment
Please, Sign In to add comment