workshop:arduino

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
workshop:arduino [2009-06-23 22:38] equinoxworkshop:arduino [2025-11-09 09:25] (current) – external edit 127.0.0.1
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);
  • /srv/dokuwiki/data/attic/workshop/arduino.1245796682.txt.gz
  • Last modified: 2025-11-09 09:24
  • (external edit)