Skip to content

Instantly share code, notes, and snippets.

@lategoodbye
Last active April 17, 2017 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lategoodbye/dd0d30af27b6f101b03d5923b279dbaa to your computer and use it in GitHub Desktop.
Save lategoodbye/dd0d30af27b6f101b03d5923b279dbaa to your computer and use it in GitHub Desktop.
//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