Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> /* Standard input/output definitions */
- #include <string.h> /* String function definitions */
- #include <unistd.h> /* UNIX standard function definitions */
- #include <fcntl.h> /* File control definitions */
- #include <errno.h> /* Error number definitions */
- #include <termios.h> /* POSIX terminal control definitions */
- int main (void)
- {
- //open serial device
- int fd;
- fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
- if (fd == -1)
- {
- perror("open_port: Unable to open /dev/ttyS0 - ");
- }
- else
- fcntl(fd, F_SETFL, 0);
- //Set baudrate to 19200
- struct termios options;
- tcgetattr(fd, &options);
- cfsetispeed(&options, B19200);
- cfsetospeed(&options, B19200);
- options.c_cflag |= (CLOCAL | CREAD);
- tcsetattr(fd, TCSANOW, &options);
- //Write text
- int n;
- n = write(fd, "Hello world!\r", 13);
- if (n < 0)
- fputs("write() failed!\n", stderr);
- n = write(fd, "Printed using the VoCore v1.0\r", 30);
- if (n < 0)
- fputs("write() failed!\n", stderr);
- n = write(fd, ":)\r", 3);
- if (n < 0)
- fputs("write() failed!\n", stderr);
- //close connection
- close(fd);
- return printf("End\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement