Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ncurses.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <termios.h>
- #include <signal.h>
- #include <unistd.h>
- #include <iostream>
- #include <signal.h>
- int open_port(void);
- int main()
- {
- char dato[1];
- int fd = 0;
- fd = open_port();
- while(1)
- {
- read(fd,dato,1);
- //~ if(dato == "B")
- //~ return 0;
- printf(dato);
- }
- }
- int open_port(void)
- {
- int fd; /* File descriptor for the port */
- //~ fd = open("/home/tomas/ttySV1", O_RDWR | O_NOCTTY | O_NDELAY);
- fd = open("/dev/ttyUSB0", O_RDWR | O_NDELAY);
- //~ fd = open("/dev/ttyUSB0", O_RDWR);
- if (fd == -1)
- {
- perror("open_port: No se pudo abrir el puerto: ");
- }
- else
- {
- struct termios options;
- /*
- * Get the current options for the port...
- */
- tcgetattr(fd, &options);
- /*
- * Set the baud rates to B9600...
- */
- cfsetispeed(&options, B9600);
- cfsetispeed(&options, B9600);
- /*
- * Enable the receiver and set local mode...
- */
- options.c_cflag |= (CLOCAL | CREAD);
- /*
- * Set the new options for the port...
- */
- tcsetattr(fd, TCSANOW, &options);
- options.c_cflag &= ~CSIZE; /* Mask the character size bits */
- options.c_cflag |= CS8; /* Select 8 data bits */
- options.c_cflag &= ~PARENB;
- options.c_cflag &= ~CSTOPB;
- options.c_cflag &= ~CSIZE;
- options.c_cflag |= CS8;
- //~ fcntl(fd, F_SETFL, 0);
- return (fd);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement