Created
January 2, 2012 09:22
-
-
Save wrl/1550007 to your computer and use it in GitHub Desktop.
tty tester
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
/** | |
* $ 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