Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <termios.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- int main (int argc, char** argv)
- {
- char buffer [1000];
- struct termios options;
- int tty = NULL;
- int len;
- FILE* input = stdin;
- if (argc > 1)
- {
- input = fopen (argv [1], "r");
- }
- tty = open ("/dev/ttyS1", O_RDWR | O_NOCTTY);
- if (tty < 0)
- {
- printf ("Cannot open tty.\n");
- return 1;
- }
- // assuming we have root
- tcgetattr (tty, &options);
- // setting BAUD to 50
- cfsetispeed (&options, B50);
- cfsetospeed (&options, B50);
- // turning off echo
- options.c_lflag &= ~ECHO;
- tcsetattr (tty, TCSANOW, &options);
- while (read (tty, buffer, 1))
- {
- read (tty, buffer, len);
- if (buffer [0] != '\0')
- printf ("%c", buffer [0]);
- }
- close (tty);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement