Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2014 02:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <pthread.h>
#include <unistd.h>
#include <time.h>
#include <poll.h>
#include <string.h>
#include <errno.h>
#include <err.h>
#define TTY "/dev/ttyUSB0"
int main(void)
struct termios tio;
int fd;
char buf[] = "TESTING123\n";
fd = open(TTY, O_RDWR);
if (fd < 0) {
err(errno, "failed to open %s", TTY);
if (!isatty(fd)) {
err(errno, "not a tty!");
tio.c_cc[VMIN] = 0;
tio.c_cc[VTIME] = 1;
cfsetispeed(&tio, B19200);
cfsetospeed(&tio, B19200);
if (tcsetattr(fd, TCSANOW, &tio)) {
err(errno, "can't configure tty");
while (1) {
write(fd, buf, strlen(buf));
printf("send done\n");
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment