Skip to content

Instantly share code, notes, and snippets.

Created Feb 17, 2014
Embed
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!");
}
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