From 4cdf1b09a98a064a54ac3eb28ef808ac8277ca3b Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 23 Oct 2006 19:35:24 +0000 Subject: [PATCH] Added choose_clock and choose_routing demo programs. Synced comedi.h with comedi. Made dio demo simply configure the line direction based on the command line argument. --- demo/Makefile.am | 11 ++++++- demo/README | 26 ++++++++++----- demo/choose_clock.c | 70 +++++++++++++++++++++++++++++++++++++++++ demo/choose_routing.c | 63 +++++++++++++++++++++++++++++++++++++ demo/dio.c | 41 +++++------------------- include/comedi.h | 73 ++++++++++++++++++++++++------------------- 6 files changed, 210 insertions(+), 74 deletions(-) create mode 100644 demo/choose_clock.c create mode 100644 demo/choose_routing.c diff --git a/demo/Makefile.am b/demo/Makefile.am index 5dc2871..d93ced8 100644 --- a/demo/Makefile.am +++ b/demo/Makefile.am @@ -1,6 +1,7 @@ noinst_PROGRAMS = \ - antialias ao_waveform ao_mmap apply_cal cmd dio eeprom_dump board_info \ + antialias ao_waveform ao_mmap apply_cal choose_clock \ + choose_routing cmd dio eeprom_dump board_info \ inp inpn insn ledclock mmap outp poll receiver select \ sender sigio sv tut1 tut2 @@ -22,6 +23,14 @@ apply_cal_SOURCES = apply_cal.c common.c apply_cal_CFLAGS = $(COMEDILIB_CFLAGS) apply_cal_LDADD = $(COMEDILIB_LIBS) +choose_clock_SOURCES = choose_clock.c common.c +choose_clock_CFLAGS = $(COMEDILIB_CFLAGS) +choose_clock_LDADD = $(COMEDILIB_LIBS) + +choose_routing_SOURCES = choose_routing.c common.c +choose_routing_CFLAGS = $(COMEDILIB_CFLAGS) +choose_routing_LDADD = $(COMEDILIB_LIBS) + cmd_SOURCES = cmd.c common.c cmd_CFLAGS = $(COMEDILIB_CFLAGS) cmd_LDADD = $(COMEDILIB_LIBS) diff --git a/demo/README b/demo/README index 3a35519..2c4ab6c 100644 --- a/demo/README +++ b/demo/README @@ -25,29 +25,39 @@ ao_waveform: which currently is some of the members of the NI AT-MIO and PCI-MIO E series. Creates a sine wave on an analog output channel. +board_info: + Displays some information that Comedi knows about a device. + +choose_clock: + Selects a master clock source. The subdevice must support + INSN_CONFIG_CLOCK_SRC. The command-line argument specifies + the clock source, and the optional -F option specifies the clock's + frequency. + common: This is not an example. The file common.c just contains some code that is common to many of the examples. -cmd: +cmd: An example for directly using Comedi commands. Comedi commands are used for asynchronous acquisition, with the timing controlled by on-board timers or external events. If this demo doesn't work with your hardware, read the comments in the source. Hint: data is written to stdout, comments to stderr. - + dio: 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. + Configures the specified channel as an output if passed a + nonzero argument. Otherwise, the channel is configured as + an input. Once the channel's direction has been configured, + you can read/write to it with the inp/outp demo programs. eeprom_dump: Dumps the EEPROM of a card, if it has one. Useful for debugging devices/drivers. -board_info: - Displays some information that Comedi knows about a device. - inp: Simple input: Reads one sample from one channel on one subdevice. @@ -60,8 +70,8 @@ insn: Example showing how to use instructions directly. Not recommended for beginners: use higher-level functions such as comedi_data_read(), comedi_data_write(), etc., as demonstrated - in the inp, outp, and dio examples. - + in the inp, outp, and dio examples. + ledclock: This demo requires a Fantazein clock modified to be directly controlled by the parallel port on a computer. The original @@ -84,7 +94,7 @@ receiver: requires a digital output subdevice. When the clock and data pins are connected between the sending and receiving devices, one should be able to send bits over the link. - + select: An example for using select() with asynchronous input. This example requires an asynchronous input subdevice that can diff --git a/demo/choose_clock.c b/demo/choose_clock.c new file mode 100644 index 0000000..77f176c --- /dev/null +++ b/demo/choose_clock.c @@ -0,0 +1,70 @@ +/* + * 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 subdevice that supports + * INSN_CONFIG_CLOCK_SRC + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "examples.h" + + +comedi_t *device; + +int main(int argc, char *argv[]) +{ + freq = 0.; + parse_options(argc,argv); + + device=comedi_open(filename); + if(!device){ + comedi_perror(filename); + exit(0); + } + unsigned period_ns; + if(freq > 0.) + period_ns = 1e9 / freq; + else + period_ns = 0; + printf("Selecting master clock %d on subdevice %d.\n", value, subdevice); + if(period_ns) + { + printf("Clock period = %d nanoseconds.\n", period_ns); + }else + { + printf("Clock period unspecified.\n"); + } + comedi_insn insn; + lsampl_t data[3]; + memset(&insn, 0, sizeof(comedi_insn)); + insn.insn = INSN_CONFIG; + insn.subdev = subdevice; + insn.data = data; + insn.n = sizeof(data) / sizeof(data[0]); + data[0] = INSN_CONFIG_SET_CLOCK_SRC; + data[1] = value; + data[2] = period_ns; + + int retval = comedi_do_insn(device, &insn); + if(retval < 0) comedi_perror("comedi_do_insn"); + return retval; +} + diff --git a/demo/choose_routing.c b/demo/choose_routing.c new file mode 100644 index 0000000..b283ab7 --- /dev/null +++ b/demo/choose_routing.c @@ -0,0 +1,63 @@ +/* + * 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 subdevice that supports + * INSN_CONFIG_SET_ROUTING + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "examples.h" + + +comedi_t *device; + +int main(int argc, char *argv[]) +{ + freq = 0.; + parse_options(argc,argv); + + device=comedi_open(filename); + if(!device){ + comedi_perror(filename); + exit(0); + } + unsigned period_ns; + if(freq > 0.) + period_ns = 1e9 / freq; + else + period_ns = 0; + printf("Selecting routing %d for channel %d on subdevice %d.\n", value, channel, subdevice); + comedi_insn insn; + lsampl_t data[2]; + memset(&insn, 0, sizeof(comedi_insn)); + insn.insn = INSN_CONFIG; + insn.subdev = subdevice; + insn.chanspec = channel; + insn.data = data; + insn.n = sizeof(data) / sizeof(data[0]); + data[0] = INSN_CONFIG_SET_ROUTING; + data[1] = value; + + int retval = comedi_do_insn(device, &insn); + if(retval < 0) comedi_perror("comedi_do_insn"); + return retval; +} + diff --git a/demo/dio.c b/demo/dio.c index 02beb2b..51425af 100644 --- a/demo/dio.c +++ b/demo/dio.c @@ -46,41 +46,16 @@ int main(int argc, char *argv[]) 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); - - comedi_dio_write(device,subdevice,channel,1); -#if 0 - for(i=0;i<10000;i++){ - usleep(1000000); - comedi_dio_write(device,subdevice,channel,1); - printf("1\n"); - usleep(1000000); - comedi_dio_write(device,subdevice,channel,0); - printf("0\n"); - } -#endif - -#if 0 + printf("configuring pin %d or subdevice %d ", channel, subdevice); + if(value) { - unsigned int mask; - unsigned int data; - - printf("toggling pin %d rapidly (using bitfield)...\n",channel); - - mask = 1<