Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
workshop:arduino [2009-06-24 00:38] equinox |
workshop:arduino [2015-09-16 12:41] (current) |
||
---|---|---|---|
Line 53: | Line 53: | ||
#include <time.h> | #include <time.h> | ||
#include <stdio.h> | #include <stdio.h> | ||
+ | #include <sys/select.h> | ||
#define STATE_OFF 0 | #define STATE_OFF 0 | ||
Line 68: | Line 69: | ||
main(int argc, char* argv[]) | main(int argc, char* argv[]) | ||
{ | { | ||
- | int fd; | ||
- | const struct timespec sleeptime = {0, 100000000}; // 100ms | ||
char* device = argc < 2 ? "/dev/ttyUSB0" : argv[1]; | char* device = argc < 2 ? "/dev/ttyUSB0" : argv[1]; | ||
- | + | int fd = open(device, O_RDWR); | |
- | fd = open(device, O_RDWR); | + | |
if (fd == 0) { | if (fd == 0) { | ||
fprintf(stderr, "Could not open %s\n", device); | fprintf(stderr, "Could not open %s\n", device); | ||
Line 79: | Line 77: | ||
| | ||
setDTRState(fd, STATE_ON); | setDTRState(fd, STATE_ON); | ||
- | nanosleep(&sleeptime, NULL); | + | struct timeval sleeptime = {0, 100000}; // 100ms |
+ | select(0, NULL, NULL, NULL, &sleeptime); | ||
setDTRState(fd, STATE_OFF); | setDTRState(fd, STATE_OFF); | ||
- | nanosleep(&sleeptime, NULL); | + | sleeptime.tv_sec = 0; |
+ | sleeptime.tv_usec = 100000; | ||
+ | select(0, NULL, NULL, NULL, &sleeptime); | ||
setDTRState(fd, STATE_ON); | setDTRState(fd, STATE_ON); | ||
close(fd); | close(fd); |
realraum Graz, Brockmanngasse 15, 8010 Graz, realraum - Verein für Technik in Kultur und Gesellschaft