diff --git a/demo/Makefile b/demo/Makefile index d02789c..e93cca9 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -6,7 +6,7 @@ LDFLAGS = -L../lib/ -lcomedi -lm BINS=cmd tut1 tut2 -MBINS=inp inpn sv eeprom_dump info outp insn antialias ao_waveform +MBINS=inp inpn sv eeprom_dump info outp insn antialias ao_waveform dio all: $(patsubst %,_mbins_%,$(MBINS)) $(patsubst %,_bins_%,$(BINS)) diff --git a/demo/dio.c b/demo/dio.c new file mode 100644 index 0000000..2b3bdbc --- /dev/null +++ b/demo/dio.c @@ -0,0 +1,75 @@ +/* + * Digital I/O example + * Part of Comedilib + * + * Copyright (c) 1999,2000 David A. Schleef + * + * This file may be freely modified, distributed, and combined with + * other software, as long as proper attribution is given in the + * source code. + */ +/* + * Requirements: A board with a digital I/O subdevice. Not just + * a 'digital input' or 'digital output' subdevice, but one in + * which the channels can be configured between input and output. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "examples.h" + +comedi_t *device; + + +int main(int argc, char *argv[]) +{ + int ret; + int stype; + int i; + unsigned int mask; + unsigned int data; + + parse_options(argc,argv); + + device=comedi_open(filename); + if(!device){ + comedi_perror(filename); + exit(0); + } + + stype = comedi_get_subdevice_type(device,subdevice); + if(stype!=COMEDI_SUBD_DIO){ + printf("%d is not a digital I/O subdevice\n",subdevice); + exit(0); + } + + printf("configuring pin %d for output...\n",channel); + + ret=comedi_dio_config(device,subdevice,channel,COMEDI_OUTPUT); + + printf("toggling pin %d rapidly...\n",channel); + + for(i=0;i<10000;i++){ + comedi_dio_write(device,subdevice,channel,1); + comedi_dio_write(device,subdevice,channel,0); + } + + printf("toggling pin %d rapidly (using bitfield)...\n",channel); + + mask = 1<