Skip to content

Instantly share code, notes, and snippets.

@wrl
Created January 2, 2012 09:22
Show Gist options
  • Save wrl/1550007 to your computer and use it in GitHub Desktop.
Save wrl/1550007 to your computer and use it in GitHub Desktop.
tty tester
/**
* $ gcc artest.c -o artest
* $ ./artest /dev/ttyUSB0
*/
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <poll.h>
int main(int argc, char **argv)
{
uint8_t buf;
struct pollfd pfd;
int fd;
assert(argc > 1);
assert((fd = open(argv[1], O_RDONLY | O_NONBLOCK)) > 0);
pfd.fd = fd;
pfd.events = POLLIN;
do {
assert(poll(&pfd, 1, -1) > 0);
while (read(fd, &buf, 1) > 0)
printf("%02X ", buf);
printf("\n");
} while (1);
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment