/gist:55ab3051827aeb698f95 Secret
Created
February 17, 2014 03:33
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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