Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <termios.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8.  
  9. int main (int argc, char** argv)
  10. {
  11. char buffer [1000];
  12. struct termios options;
  13. int tty = NULL;
  14. int len;
  15. FILE* input = stdin;
  16.  
  17. if (argc > 1)
  18. {
  19. input = fopen (argv [1], "r");
  20. }
  21.  
  22. tty = open ("/dev/ttyS1", O_RDWR | O_NOCTTY);
  23. if (tty < 0)
  24. {
  25. printf ("Cannot open tty.\n");
  26. return 1;
  27. }
  28.  
  29. // assuming we have root
  30. tcgetattr (tty, &options);
  31. // setting BAUD to 50
  32. cfsetispeed (&options, B50);
  33. cfsetospeed (&options, B50);
  34. // turning off echo
  35. options.c_lflag &= ~ECHO;
  36. tcsetattr (tty, TCSANOW, &options);
  37.  
  38. while (read (tty, buffer, 1))
  39. {
  40. read (tty, buffer, len);
  41. if (buffer [0] != '\0')
  42. printf ("%c", buffer [0]);
  43. }
  44.  
  45. close (tty);
  46.  
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement