// 1 int main(int argc,char *argv[]) { int d = dio_open(""); dio_set(d,"RED_LED",1); sleep(1); dio_set(d,"RED_LED",0); sleep(1); dio_set(d,"GREEN_LED",1); sleep(1); dio_set(d,"GREEN_LED",0); } // 2 int main(int argc,char *argv[]) { int d = dio_open("192.168.0.218"); printf("Red LED is %s\n",dio_get(d,"RLED")?"ON":"OFF"); printf("Green LED is %s\n",dio_get(d,"GLED")?"ON":"OFF"); dio_close(d); } // 3 int main(int argc,char *argv[]) { int d = dio_open("192.168.0.218"); int gled,rled; gled = dio_lookup(d,"GLED"); rled = dio_lookup(d,"RLED"); printf("Red LED is %s\n",dio_getpin(d,rled)?"ON":"OFF"); printf("Green LED is %s\n",dio_getpin(d,gled)?"ON":"OFF"); dio_setpin(d,rled,1); sleep(1); dio_setpin(d,rled,0); sleep(1); dio_setpin(d,gled,1); sleep(1); dio_setpin(d,gled,0); dio_close(d); } // 4 int main(int argc,char *argv[]) { int d = dio_open("192.168.0.218"); char *name; int val; while (dio_names(d,&name,&val) != -1) { printf("%s=%d\n",name,val); } dio_close(d); } // 5 int main(int argc,char *argv[]) { int d = dio_open("192.168.0.218"); int group; int block=1; int i; struct timeval tv; group = dio_groupinit(d); dio_groupadd(d,group,"GLED"); dio_groupadd(d,group,"RLED"); if (block) { printf("Waiting for LEDs...\n"); dio_grouplock(d,group); dio_getcurrenttime(d,&tv); printf("Done waiting\n"); // do something to actually wait for lock to occur // otherwise we will queue all our requests and when // the lock occurs they will all be done at once without // the required delays! } else { if (!dio_grouptrylock(d,group)) { printf("LED(s) busy\n"); return 0; } } for (i=0;i<5;i++) { dio_set(d,"RLED",1); dio_groupsync(d,group); sleep(1); dio_set(d,"RLED",0); dio_groupsync(d,group); sleep(1); dio_set(d,"GLED",1); dio_groupsync(d,group); sleep(1); dio_set(d,"GLED",0); dio_groupsync(d,group); if (i<4) sleep(1); } dio_groupunlock(d,group); dio_close(d); } // 6 int main(int argc,char *argv[]) { int d = dio_open("192.168.0.218"); int i,group,gled,rled; group = dio_groupinit(d); dio_groupadd(d,group,"GLED"); dio_groupadd(d,group,"RLED"); if (dio_grouptrylock(d,group)) { printf("Driving LEDs\n"); while (1) { dio_set(d,"RLED",1); dio_groupsync(d,group); sleep(1); dio_set(d,"RLED",0); dio_groupsync(d,group); sleep(1); dio_set(d,"GLED",1); dio_groupsync(d,group); sleep(1); dio_set(d,"GLED",0); dio_groupsync(d,group); sleep(1); } } else { printf("Watching LEDs\n"); dio_groupisync(d,group); while (1) { gled = !dio_get(d,"GLED"); rled = !dio_get(d,"RLED"); dio_groupwaitirq(d,group,(gled?1:0)+(rled?2:0),3); if (dio_get(d,"GLED") == gled) { printf("GLED turned %s\n",gled?"ON":"OFF"); } if (dio_get(d,"RLED") == rled) { printf("RLED turned %s\n",rled?"ON":"OFF"); } } } dio_close(d); }