Skip to content

Instantly share code, notes, and snippets.

@lategoodbye
Last active Apr 17, 2017
Embed
What would you like to do?
//usb_test.c
//compile: gcc usb_test.c -o usb_test
#include <fcntl.h> /* O_RDWR */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void open_port(char * portname) {
int fd;
printf("opening [%s]\n", portname);
fd = open(portname, O_RDWR);
if(fd == -1) {
printf("failed\n");
return;
}
printf("ok\n");
sleep(5);
}
int main() {
printf("idle \n");
open_port("/dev/ttyUSB0");
open_port("/dev/ttyUSB1");
open_port("/dev/ttyUSB2");
open_port("/dev/ttyUSB3");
open_port("/dev/ttyUSB4");
open_port("/dev/ttyUSB5");
open_port("/dev/ttyUSB6");
open_port("/dev/ttyUSB7");
open_port("/dev/ttyUSB8");
printf("idle 2\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment