/* * 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 "examples.h" int chan_dat = 1; int chan_clk = 0; int wait1 = usec_to_nsec(0); int wait2 = usec_to_nsec(0); comedi_t *device; void write_bits(int subdevice, int bits); int main(int argc, char *argv[]) { int ret; int stype; int i; struct parsed_options options; init_parsed_options(&options); options.subdevice = -1; parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ comedi_perror(options.filename); exit(-1); } if(options.subdevice < 0) { options.subdevice = comedi_find_subdevice_by_type(device, COMEDI_SUBD_DIO, 0); if(options.subdevice < 0){ fprintf(stderr,"No dio subdevice found.\n"); exit(-1); } } stype = comedi_get_subdevice_type(device, options.subdevice); if(stype != COMEDI_SUBD_DIO){ printf("%d is not a digital I/O subdevice\n", options.subdevice); exit(-1); } printf("configuring pin %d for output...\n", chan_dat); ret = comedi_dio_config(device, options.subdevice, chan_dat, COMEDI_OUTPUT); if(ret < 0){ comedi_perror("comedi_dio_config"); exit(-1); } printf("configuring pin %d for output...\n", chan_clk); ret = comedi_dio_config(device, options.subdevice, chan_clk, COMEDI_OUTPUT); if(ret < 0){ comedi_perror("comedi_dio_config"); exit(-1); } for(i = 0; i < 0x100; i++){ write_bits(options.subdevice, i); } //write_bits(0xa5); return 0; } void write_bits(int subdevice, int bits) { comedi_insnlist il; comedi_insn insn[5]; lsampl_t data[10]; int mask = (1<