Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2014 03:33
  • 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
Save anonymous/55ab3051827aeb698f95 to your computer and use it in GitHub Desktop.
#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!");
}
cfmakeraw(&tio);
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) {
printf("send\n");
write(fd, buf, strlen(buf));
printf("send done\n");
}
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment