From 79a511162dbd55a147a85d5a50bc5e105948bc83 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Thu, 19 Oct 2000 06:28:27 +0000 Subject: [PATCH] Cleanup of example programs --- demo/Makefile | 10 +-- demo/README | 16 +---- demo/antialias.c | 40 ++++++++--- demo/ao_waveform.c | 163 ++++++++++++++++++++++++--------------------- demo/cmd.c | 37 +++++----- demo/eeprom_dump.c | 10 +-- demo/info.c | 6 +- demo/inp.c | 18 +++-- demo/inpn.c | 19 +++--- demo/insn.c | 18 +++-- demo/main.c | 3 + demo/mode2.c | 95 -------------------------- demo/mode3.c | 79 ---------------------- demo/mode4.c | 91 ------------------------- demo/outp.c | 21 +++--- demo/rt/Makefile | 23 ------- demo/rt/README | 16 ----- demo/rt/ai.c | 97 --------------------------- demo/rt/it.c | 80 ---------------------- demo/sv.c | 19 +++--- demo/tut1.c | 10 +++ demo/tut2.c | 21 ++++-- 22 files changed, 233 insertions(+), 659 deletions(-) delete mode 100644 demo/mode2.c delete mode 100644 demo/mode3.c delete mode 100644 demo/mode4.c delete mode 100644 demo/rt/Makefile delete mode 100644 demo/rt/README delete mode 100644 demo/rt/ai.c delete mode 100644 demo/rt/it.c diff --git a/demo/Makefile b/demo/Makefile index 238c79a..eeb939b 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -1,12 +1,12 @@ -CFLAGS +=-I ../include -I . -O2 -LDFLAGS=-L../lib/ -lcomedi -lm +CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes +LDFLAGS = -L../lib/ -lcomedi -lm -BINS=mode4 mode3 mode2 ao_waveform tut2 cmd tut1 antialias -MBINS=inp inpn sv eeprom_dump info outp insn +BINS=cmd tut1 +MBINS=inp inpn sv eeprom_dump info outp insn antialias ao_waveform all: $(patsubst %,_mbins_%,$(MBINS)) $(patsubst %,_bins_%,$(BINS)) @@ -17,4 +17,4 @@ $(patsubst %,_bins_%,$(BINS)) : $(patsubst %,%.o,$(BINS)) $(CC) -o $(patsubst _bins_%,%,$@) $(patsubst _bins_%,%.o,$@) $(LDFLAGS) clean: - -rm *.o $(BINS) $(MBINS) + -rm -f *.o $(BINS) $(MBINS) diff --git a/demo/README b/demo/README index f454121..f6b2f66 100644 --- a/demo/README +++ b/demo/README @@ -3,13 +3,12 @@ Examples ao_waveform: - You need a device (and driver) capable of streaming analog output, 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. cmd: - Example of how to use the new 0.8 command structure. + Asynchronous input. eeprom_dump: Dumps the EEPROM of a card, if it has one. Useful for debugging @@ -29,19 +28,6 @@ inpn: insn: Example showing how to use instructions directly. -mode1: - Doesn't work. - -mode2: - Demo for streaming analog input. Only works for boards/drivers - with that capability. - -mode3: - Doesn't work. - -mode4: - Same as mode2, except using an external trigger. - sv: Similar to inp, but measures the input using the comedi_sv_*() functions, which average many samples to try to get a more accurate diff --git a/demo/antialias.c b/demo/antialias.c index 01583cf..1a0b127 100644 --- a/demo/antialias.c +++ b/demo/antialias.c @@ -1,5 +1,32 @@ /* - A little output demo + * Antialiasing Analog Output Demo + * 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. + */ + +/* Not functional */ + +/* + * Requirements: an analog output subdevice that is capable + * of ansynchronous output. + * + * Normally, the resolution of analog output channels is limited by + * the resolution of the D/A converter. However, if you limit the + * bandwith of the D/A converter by using a low-pass filter, you + * can trade some of the bandwidth for additional resolution. This + * is done by changing the output rapidly between two adjacent + * values: a signal of an alternating 0,1,0,1,0,1 sequence will + * look like 0.5 after an appropriate low-pass filter. + * + * The disadvantage, of course, is that you lose bandwidth. Worse, + * the simple technique demonstrated here will cause predictable + * noise in the stop band. More complicated techniques will allow + * you to tune the spectrum of the noise in the stop band. */ #include @@ -10,14 +37,7 @@ #include #include #include - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern int value; -extern char *filename; +#include "examples.h" comedi_t *device; @@ -28,7 +48,6 @@ int main(int argc, char *argv[]) lsampl_t data; int ret; -#if 0 parse_options(argc,argv); device=comedi_open(filename); @@ -50,7 +69,6 @@ int main(int argc, char *argv[]) } printf("%d\n",data); -#endif ao_antialias((1000<<16)+1000); diff --git a/demo/ao_waveform.c b/demo/ao_waveform.c index 6aeb4ee..945611b 100644 --- a/demo/ao_waveform.c +++ b/demo/ao_waveform.c @@ -1,36 +1,50 @@ /* - This demo uses an analog output subdevice in timed - mode (mode 2) to generate a waveform. The waveform - in this example is a sine wave (surprise!), but this - can be easily changed to make a general function - generator. + * Asynchronous Analog Output 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. + */ - The function generation algorithm is the same as - what is typically used in digital function generators. - A 32-bit accumulator is incremented by a phase factor, - which is the amount (in radians) that the generator - advances each time step. The accumulator is then - shifted right by 20 bits, to get a 12 bit offset into - a lookup table. The value in the lookup table at - that offset is then put into a buffer for output to - the DAC. - - [ Actually, the accumulator is only 26 bits, for some - reason. I'll fix this sometime. ] - - On the comedi side of things, the setup for mode 2 - is similar to analog input, except for the TRIG_WRITE - flag. Once you have issued the command, comedi then - expects you to keep the buffer full of data to output - to the DAC. This is done by write(). Since there - may be a delay between the ioctl() and a subsequent - write(), you should fill the buffer using write() before - you call ioctl(), as is done here. - - Also NOTE! The lseek() to offset 1 is used to tell - comedi that you want to write to subdevice 1. This - is not needed for analog input, since AI is usually on - subdevice 0. +/* + * Requirements: Analog output device capable of + * asynchronous commands. + * + * This demo uses an analog output subdevice with an + * asynchronous command to generate a waveform. The + * waveform in this example is a sine wave (surprise!), + * but this can be easily changed to make a generic + * function generator. + * + * The function generation algorithm is the same as + * what is typically used in digital function generators. + * A 32-bit accumulator is incremented by a phase factor, + * which is the amount (in radians) that the generator + * advances each time step. The accumulator is then + * shifted right by 20 bits, to get a 12 bit offset into + * a lookup table. The value in the lookup table at + * that offset is then put into a buffer for output to + * the DAC. + * + * [ Actually, the accumulator is only 26 bits, for some + * reason. I'll fix this sometime. ] + * + * On the Comedi side of things, the setup for mode 2 + * is similar to analog input, except for the TRIG_WRITE + * flag. Once you have issued the command, comedi then + * expects you to keep the buffer full of data to output + * to the DAC. This is done by write(). Since there + * may be a delay between the ioctl() and a subsequent + * write(), you should fill the buffer using write() before + * you call ioctl(), as is done here. + * + * Also NOTE! The lseek() to offset 1 is used to tell + * comedi that you want to write to subdevice 1. This + * is not needed for analog input, since AI is usually on + * subdevice 0. */ #include @@ -43,8 +57,7 @@ #include #include #include - -#define dds_init dds_init_pseudocycloid +#include "examples.h" /* frequency of the sine wave to output */ @@ -65,35 +78,33 @@ double offset = 2048; inefficient */ #define BUF_LEN 4096 - -#define N_SCANS 0 -#define N_CHANS 1 - int subdevice; -int channels[] = { 0 }; -int range = 0; -int aref = AREF_GROUND; int external_trigger_number = 0; sampl_t data[BUF_LEN]; void dds_output(sampl_t *buf,int n); +void dds_init(void); + +/* This define determines which waveform to use. */ +#define dds_init_function dds_init_sine + void dds_init_sine(void); void dds_init_pseudocycloid(void); +void dds_init_sawtooth(void); int main(int argc, char *argv[]) { char *fn = NULL; - comedi_trig it; + comedi_cmd cmd; int err; - int n,m,i; + int n,m; int total=0; comedi_t *dev; - double actual_freq; - unsigned int chan[N_CHANS]; + unsigned int chanlist[1]; if(argc>=2){ - waveform_frequency=atof(argv[1]); + waveform_frequency=strtod(argv[1],NULL); } fn = "/dev/comedi0"; @@ -102,23 +113,24 @@ int main(int argc, char *argv[]) subdevice = comedi_find_subdevice_by_type(dev,COMEDI_SUBD_AO,0); - it.subdev = subdevice; - it.mode = 2; - it.flags = TRIG_WRITE; - it.n_chan = N_CHANS; - it.chanlist = chan; - it.data = NULL; - it.n = N_SCANS; - it.trigsrc = 0; + memset(&cmd,0,sizeof(cmd)); + cmd.subdev = subdevice; + cmd.flags = 0; + cmd.start_src = TRIG_NOW; + cmd.start_arg = 0; + cmd.scan_begin_src = TRIG_TIMER; + cmd.scan_begin_arg = 1e9/update_frequency; + cmd.convert_src = TRIG_TIMER; + cmd.convert_arg = 0; + cmd.scan_end_src = TRIG_COUNT; + cmd.scan_end_arg = 1; + cmd.stop_src = TRIG_NONE; + cmd.stop_arg = 0; - /* convert the frequency into a timer value */ - comedi_get_timer(dev,subdevice,update_frequency,&it.trigvar,&actual_freq); - fprintf(stderr,"primary actual frequency=%g timer value=%d\n",actual_freq,it.trigvar); + cmd.chanlist = chanlist; + cmd.chanlist_len = 1; - /* pack the channel list */ - for(i=0;i>16)&WAVEFORM_MASK]; + p++; + acc+=adder; + } +} + + void dds_init_sine(void) { int i; @@ -193,7 +218,7 @@ void dds_init_sine(void) /* Yes, I know this is not the proper equation for a cycloid. Fix it. */ -void dds_init_cycloid(void) +void dds_init_pseudocycloid(void) { int i; double t; @@ -217,15 +242,3 @@ void dds_init_sawtooth(void) } } -void dds_output(sampl_t *buf,int n) -{ - int i; - sampl_t *p=buf; - - for(i=0;i>16)&WAVEFORM_MASK]; - p++; - acc+=adder; - } -} - diff --git a/demo/cmd.c b/demo/cmd.c index 3181d9e..ea544e4 100644 --- a/demo/cmd.c +++ b/demo/cmd.c @@ -1,7 +1,18 @@ /* - 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. + * Example of using commands - asynchronous input + * 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. + */ + +/* + * 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. */ #include @@ -12,6 +23,8 @@ #include #include #include +#include +#include "examples.h" #define N_SCANS 10 #define N_CHANS 16 @@ -26,9 +39,9 @@ double freq = 1000; char buf[BUFSZ]; -static void do_cmd_1(comedi_t *dev); -static void do_cmd_2(comedi_t *dev); -static void do_cmd(comedi_t *dev,comedi_cmd *cmd); +void do_cmd_1(comedi_t *dev); +void do_cmd_2(comedi_t *dev); +void do_cmd(comedi_t *dev,comedi_cmd *cmd); void dump_cmd(comedi_cmd *cmd); int main(int argc, char *argv[]) @@ -51,7 +64,7 @@ int main(int argc, char *argv[]) return 0; } -static void do_cmd(comedi_t *dev,comedi_cmd *cmd) +void do_cmd(comedi_t *dev,comedi_cmd *cmd) { unsigned int *chanlist; int n_chans; @@ -124,13 +137,10 @@ static void do_cmd(comedi_t *dev,comedi_cmd *cmd) * of scans measured is 10. This is analogous to the old mode2 * acquisition. */ -static void do_cmd_1(comedi_t *dev) +void do_cmd_1(comedi_t *dev) { comedi_cmd cmd; unsigned int chanlist[4]; - int total=0; - int ret; - int go; memset(&cmd,0,sizeof(cmd)); @@ -204,13 +214,10 @@ static void do_cmd_1(comedi_t *dev) do_cmd(dev,&cmd); } -static void do_cmd_2(comedi_t *dev) +void do_cmd_2(comedi_t *dev) { comedi_cmd cmd; unsigned int chanlist[4]; - int total=0; - int ret; - int go; memset(&cmd,0,sizeof(cmd)); diff --git a/demo/eeprom_dump.c b/demo/eeprom_dump.c index 570be98..e4b6510 100644 --- a/demo/eeprom_dump.c +++ b/demo/eeprom_dump.c @@ -11,13 +11,7 @@ #include #include #include - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern char *filename; +#include "examples.h" comedi_t *device; @@ -27,8 +21,6 @@ void dump_eeprom(unsigned int *eeprom,int len); int main(int argc, char *argv[]) { - lsampl_t data; - int ret; int len; unsigned int *eeprom; diff --git a/demo/info.c b/demo/info.c index e60c9e8..a597556 100644 --- a/demo/info.c +++ b/demo/info.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include "examples.h" void get_command_stuff(comedi_t *it,int s); @@ -179,7 +181,7 @@ int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd) } }else{ printf("can't do timed?!?\n"); - return; + return -1; } if(cmd->stop_src&TRIG_COUNT){ cmd->stop_src=TRIG_COUNT; @@ -189,7 +191,7 @@ int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd) cmd->stop_arg=0; }else{ printf("can't find a good stop_src\n"); - return; + return -1; } ret=comedi_command_test(it,cmd); diff --git a/demo/inp.c b/demo/inp.c index a3e810d..391a43e 100644 --- a/demo/inp.c +++ b/demo/inp.c @@ -1,3 +1,13 @@ +/* + * A very small one-shot input demo + * 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. + */ /* A little input demo */ @@ -10,13 +20,7 @@ #include #include #include - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern char *filename; +#include "examples.h" comedi_t *device; diff --git a/demo/inpn.c b/demo/inpn.c index 009e3c4..e503d27 100644 --- a/demo/inpn.c +++ b/demo/inpn.c @@ -1,3 +1,13 @@ +/* + * Multi-channel, multi-range one-shot input demo + * 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. + */ /* This demo opens /dev/comedi0 and looks for an analog input subdevice. If it finds one, it measures one sample on each @@ -13,20 +23,13 @@ #include #include #include - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern char *filename; +#include "examples.h" comedi_t *device; int main(int argc, char *argv[]) { - int n_subdevs; int n_chans,chan; int n_ranges; int range; diff --git a/demo/insn.c b/demo/insn.c index 2df4707..9c3cfb0 100644 --- a/demo/insn.c +++ b/demo/insn.c @@ -1,3 +1,13 @@ +/* + * Instruction 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. + */ /* This example shows how to use instructions, i.e., comedi_insns. @@ -17,13 +27,7 @@ #include #include #include - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern char *filename; +#include "examples.h" comedi_t *device; diff --git a/demo/main.c b/demo/main.c index 06e6737..0c9ab46 100644 --- a/demo/main.c +++ b/demo/main.c @@ -1,4 +1,6 @@ /* + * This is a little helper function to parse options that + * are common to most of the examples. */ #include @@ -10,6 +12,7 @@ #include #include #include +#include "examples.h" char *filename="/dev/comedi0"; diff --git a/demo/mode2.c b/demo/mode2.c deleted file mode 100644 index c57d1a3..0000000 --- a/demo/mode2.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - A little input demo for mode 4 - - Mode 4 uses an external trigger to repeatedly trigger a - scan of samples. (This is different from mode 3, which - triggers an individual sample.) Thus, for each external - trigger, n_chan samples are converted. - - If you have multiple external trigger lines, the - particular trigger line is selected by trigval. - - The time between samples in a scan is selected - by trigval1. Conversion from seconds or Hz is done - using the standard timer routines. - - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define N_SCANS 4 -#define N_CHANS 4 - -int subdevice = 0; -int channels[N_CHANS] = { 0, 1, 2, 3 }; -double freq = 1000; -int range = 0; -int aref = 3; -int external_trigger_number = 0; - -#define N_SAMPLES (N_CHANS*N_SCANS) - -sampl_t data[4096]; - - -int main(int argc, char *argv[]) -{ - char *fn = NULL; - comedi_trig it; - int err; - int n,i,m; - comedi_t *dev; - double actual_freq; - unsigned int chan[N_CHANS]; - - fn = "/dev/comedi0"; - - dev = comedi_open(fn); - - it.subdev = 0; - it.mode = 2; - it.flags = 0; - it.n_chan = 1; - it.chanlist = chan; - it.data = data; - it.n = 0; //N_SCANS; - it.trigsrc = 0; - it.trigvar = 10000; - it.trigvar1 = 10000; - - /* pack the channel list */ - for(i=0;i1, then - a different channel is captured at each external trigger. - - If you have multiple external trigger lines, the - particular trigger line is selected by trigval. - - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define N_SAMPLES 100 -#define N_CHANS 4 - -int subdevice = 0; -int channels[N_CHANS] = { 0, 1, 2, 3 }; -double freq = 100000; -int range = 0; -int aref = 3; -int external_trigger_number = 0; - -sampl_t data[N_SAMPLES]; - - -int main(int argc, char *argv[]) -{ - char *fn = NULL; - comedi_trig it; - int err; - int n,i; - comedi_t *dev; - unsigned int chan[N_CHANS]; - - fn = "/dev/comedi0"; - - dev = comedi_open(fn); - - it.subdev = 0; - it.mode = 3; - it.flags = 0; - it.n_chan = N_CHANS; - it.chanlist = chan; - it.data = data; - it.n = N_SAMPLES/N_CHANS; - it.trigsrc = 0; - - /* external trigger number */ - it.trigvar = external_trigger_number; - - /* pack the channel list */ - for(i=0;i -#include -#include -#include -#include -#include -#include -#include - -#define N_SCANS 4 -#define N_CHANS 4 - -int subdevice = 0; -int channels[N_CHANS] = { 0, 1, 2, 3 }; -double freq = 1000; -int range = 0; -int aref = 3; -int external_trigger_number = 0; - -#define N_SAMPLES (N_CHANS*N_SCANS) - -sampl_t data[N_SAMPLES]; - - -int main(int argc, char *argv[]) -{ - char *fn = NULL; - comedi_trig it; - int err; - int n,i; - comedi_t *dev; - double actual_freq; - unsigned int chan[N_CHANS]; - - fn = "/dev/comedi0"; - - dev = comedi_open(fn); - - it.subdev = 0; - it.mode = 4; - it.flags = 0; - it.n_chan = N_CHANS; - it.chanlist = chan; - it.data = data; - it.n = N_SCANS; - it.trigsrc = 0; - - /* external trigger number */ - it.trigvar = external_trigger_number; - - /* convert the frequency into a timer value */ - comedi_get_timer(dev,subdevice,freq,&it.trigvar1,&actual_freq); - printf("actual frequency=%g timer value=%d\n",actual_freq,it.trigvar1); - - /* pack the channel list */ - for(i=0;i + * + * This file may be freely modified, distributed, and combined with + * other software, as long as proper attribution is given in the + * source code. + */ +/* + * A little output demo */ #include @@ -10,14 +20,7 @@ #include #include #include - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern int value; -extern char *filename; +#include "examples.h" comedi_t *device; diff --git a/demo/rt/Makefile b/demo/rt/Makefile deleted file mode 100644 index 64ded71..0000000 --- a/demo/rt/Makefile +++ /dev/null @@ -1,23 +0,0 @@ - - -# change this to your rtlinux include directory. -# I don't have RTLinux installed on the computer -# that I use to compile, so I need this: - -LINUXDIR := /d/ds/cvs/rtl/linux22 -RTINCDIR := /usr/include/rtlinux - -CFLAGS = -O2 -Wall -D__KERNEL__ -DMODULE -CFLAGS += -I $(LINUXDIR)/include -CFLAGS += -I $(RTINCDIR) -O2 -Wall -D__RTL__ -CFLAGS += -D__SMP__ -CFLAGS += -DMODVERSIONS -include $(LINUXDIR)/include/linux/modversions.h - -all: it.o ai.o - -it.o: it.c - $(CC) $(CFLAGS) -o it.o -c it.c - -ai.o: ai.c - $(CC) $(CFLAGS) -o ai.o -c ai.c - diff --git a/demo/rt/README b/demo/rt/README deleted file mode 100644 index c6e39f3..0000000 --- a/demo/rt/README +++ /dev/null @@ -1,16 +0,0 @@ - -I'm using Linux-2.0.36/RTLinux 9J - - -it.o toggles a digital output bit, like the rectangle demo -in the RTLinux source - -ai.o does a timed acquisition on an analog input subdevice, -utilizing a callback function to copy the analog input value -to the analog output channel, in effect, creating a "follower". - -Both demos are configured for an NI AT-MIO E series board. -To use another driver/board, the source will need to be edited. - - - diff --git a/demo/rt/ai.c b/demo/rt/ai.c deleted file mode 100644 index a2ec179..0000000 --- a/demo/rt/ai.c +++ /dev/null @@ -1,97 +0,0 @@ - - -#include -#include -#include -#include -#include -#include - - -RT_TASK mytask; - -/* this is the dev,subdev for analog input on my atmio-E board */ -unsigned int ai_dev=0; -unsigned int ai_subdev=0; -unsigned int ai_chan[2]={CR_PACK(6,0,0),CR_PACK(1,0,0)}; - -comedi_trig ai_trig; - -/* this is the dev,subdev for analog output on my atmio-E board */ -unsigned int ao_dev=0; -unsigned int ao_subdev=1; -unsigned int ao_chan=CR_PACK(0,0,0); - -comedi_trig ao_trig; - -sampl_t data2=0; - -sampl_t data[2]; - - -int callback(void *arg) -{ - data2^=0x800; - data[0]^=0x800; - data[0]&=0xfff; - - comedi_trig_ioctl(ao_dev,ao_subdev,&ao_trig); - - /* returning 1 is a little hack to reset user_ptr */ - return 1; -} - -int init_module(void) -{ - int ret; - - /* set up input structure */ - ai_trig.subdev=ai_subdev; - ai_trig.mode=2; - ai_trig.flags=0; - ai_trig.n_chan=2; - ai_trig.chanlist=ai_chan; - ai_trig.data=data; - ai_trig.n=2000; - ai_trig.trigsrc=0; - ai_trig.trigvar=99999; - ai_trig.trigvar1=1999; - - /* IMPORTANT next step: lock the subdevice */ - comedi_lock_ioctl(ai_dev,ai_subdev); - - /* register our callback function */ - ret=comedi_register_callback(ai_dev,ai_subdev,COMEDI_CB_EOS,callback,(void *)0); - printk("comedi_register_callback() returned %d\n",ret); - - /* set up output structure */ - ao_trig.subdev=ao_subdev; - ao_trig.mode=0; - ao_trig.flags=0; - ao_trig.n_chan=1; - ao_trig.chanlist=&ao_chan; - ao_trig.data=data; - ao_trig.n=1; - ao_trig.trigsrc=0; - ao_trig.trigvar=0; - ao_trig.trigvar1=0; - - /* IMPORTANT next step: lock the subdevice */ - comedi_lock_ioctl(ao_dev,ao_subdev); - - /* start acq. */ - ret=comedi_trig_ioctl(ai_dev,ai_subdev,&ai_trig); - printk("comedi_trig_ioctl() returned %d\n",ret); - - return 0; -} - -void cleanup_module(void) -{ - comedi_cancel_ioctl(ai_dev,ai_subdev); - - comedi_unlock_ioctl(ai_dev,ai_subdev); - comedi_unlock_ioctl(ao_dev,ao_subdev); -} - - diff --git a/demo/rt/it.c b/demo/rt/it.c deleted file mode 100644 index 276f601..0000000 --- a/demo/rt/it.c +++ /dev/null @@ -1,80 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include - - -RT_TASK mytask; - -/* this is the dev,subdev for digital I/O on my atmio-E board */ -unsigned int dev=0; -unsigned int subdev=2; - -unsigned int channel; -sampl_t data; -comedi_trig trig; - -void do_comedi_toggle(int t) -{ - while(1){ - data^=1; - comedi_trig_ioctl(dev,subdev,&trig); - rt_task_wait(); - } -} - -int init_module(void) -{ - int ret; - RTIME now=rt_get_time(); - - /* set up trigger structure */ - trig.subdev=subdev; - trig.mode=0; - trig.flags=0; - trig.n_chan=1; - trig.chanlist=&channel; - trig.data=&data; - trig.data_len=1; - trig.n=1; - trig.trigsrc=0; - trig.trigvar=0; - trig.trigvar1=0; - - channel=CR_PACK(0,0,0); - - /* IMPORTANT next step: lock the subdevice */ - comedi_lock_ioctl(dev,subdev); - - /* configure DIO 0 for output */ - trig.flags=TRIG_CONFIG|TRIG_WRITE; - data=COMEDI_OUTPUT; - ret=comedi_trig_ioctl(dev,subdev,&trig); - printk("comedi_trig_ioctl() returned %d\n",ret); - trig.flags=TRIG_WRITE; - data=1; - - /* a little test */ - ret=comedi_trig_ioctl(dev,subdev,&trig); - printk("comedi_trig_ioctl() returned %d\n",ret); - - rt_task_init(&mytask,do_comedi_toggle, 0xffff, 3000, 4); - - rt_task_make_periodic(&mytask,now+3000,1000); - - return 0; -} - -void cleanup_module(void) -{ - rt_task_delete(&mytask); - - comedi_unlock_ioctl(dev,subdev); -} - - diff --git a/demo/sv.c b/demo/sv.c index 1f1a9b8..7ebecbb 100644 --- a/demo/sv.c +++ b/demo/sv.c @@ -1,5 +1,13 @@ /* - Demo of the comedi_sv_*() functions + * Demo of the comedi_sv_*() functions + * + * 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. */ #include @@ -10,20 +18,13 @@ #include #include #include - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern char *filename; +#include "examples.h" comedi_t *device; int main(int argc, char *argv[]) { - lsampl_t data; int ret; comedi_sv_t sv; double volts; diff --git a/demo/tut1.c b/demo/tut1.c index 15dcd6a..5e2b5bd 100644 --- a/demo/tut1.c +++ b/demo/tut1.c @@ -1,3 +1,13 @@ +/* + * Tutorial example #1 + * 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. + */ #include /* for printf() */ #include diff --git a/demo/tut2.c b/demo/tut2.c index d01c64a..25d1105 100644 --- a/demo/tut2.c +++ b/demo/tut2.c @@ -1,12 +1,21 @@ +/* + * Tutorial example #2 + * 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. + */ #include /* for printf() */ -#include /* also included by comedilib.h */ -#include /* for comedi_get() */ +#include -int subdev = 0; /* change this to your input subdevice */ -int chan = 0; /* change this to your channel */ -int range = 3; /* more on this later */ -int aref = 0; /* more on this later */ +int subdev = 0; /* change this to your input subdevice */ +int chan = 0; /* change this to your channel */ +int range = 0; /* more on this later */ +int aref = AREF_GROUND; /* more on this later */ int main(int argc,char *argv[]) {