-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))
$(CC) -o $(patsubst _bins_%,%,$@) $(patsubst _bins_%,%.o,$@) $(LDFLAGS)
clean:
- -rm *.o $(BINS) $(MBINS)
+ -rm -f *.o $(BINS) $(MBINS)
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
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
/*
- A little output demo
+ * Antialiasing Analog Output Demo
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * 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 <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
-
-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;
lsampl_t data;
int ret;
-#if 0
parse_options(argc,argv);
device=comedi_open(filename);
}
printf("%d\n",data);
-#endif
ao_antialias((1000<<16)+1000);
/*
- 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.
-
- 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.
+ * Asynchronous Analog Output Example
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * This file may be freely modified, distributed, and combined with
+ * other software, as long as proper attribution is given in the
+ * source code.
+ */
+
+/*
+ * 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 <stdio.h>
#include <getopt.h>
#include <ctype.h>
#include <math.h>
-
-#define dds_init dds_init_pseudocycloid
+#include "examples.h"
/* frequency of the sine wave to output */
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";
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;
-
- /* 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);
-
- /* pack the channel list */
- for(i=0;i<N_CHANS;i++){
- chan[i] = CR_PACK(channels[i], range, aref);
- }
+ 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;
+
+ cmd.chanlist = chanlist;
+ cmd.chanlist_len = 1;
+
+ chanlist[0] = CR_PACK(channel,range,aref);
dds_init();
printf("m=%d\n",m);
- if ((err = comedi_trigger(dev, &it)) < 0) {
+ if ((err = comedi_command(dev, &cmd)) < 0) {
perror("ioctl");
exit(1);
}
adder=waveform_frequency/update_frequency*(1<<16)*(1<<WAVEFORM_SHIFT);
- dds_init_sine();
+ dds_init_function();
/* this is due to a bug in the NI-E driver */
if(range){
}
}
+void dds_output(sampl_t *buf,int n)
+{
+ int i;
+ sampl_t *p=buf;
+
+ for(i=0;i<n;i++){
+ *p=waveform[(acc>>16)&WAVEFORM_MASK];
+ p++;
+ acc+=adder;
+ }
+}
+
+
void dds_init_sine(void)
{
int i;
/* 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;
}
}
-void dds_output(sampl_t *buf,int n)
-{
- int i;
- sampl_t *p=buf;
-
- for(i=0;i<n;i++){
- *p=waveform[(acc>>16)&WAVEFORM_MASK];
- p++;
- acc+=adder;
- }
-}
-
/*
- 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 <ds@schleef.org>
+ *
+ * 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 <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
+#include <string.h>
+#include "examples.h"
#define N_SCANS 10
#define N_CHANS 16
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[])
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;
* 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));
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));
#include <getopt.h>
#include <ctype.h>
#include <stdlib.h>
-
-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;
int len;
unsigned int *eeprom;
#include <unistd.h>
#include <sys/ioctl.h>
#include <errno.h>
+#include <string.h>
+#include "examples.h"
void get_command_stuff(comedi_t *it,int s);
}
}else{
printf("can't do timed?!?\n");
- return;
+ return -1;
}
if(cmd->stop_src&TRIG_COUNT){
cmd->stop_src=TRIG_COUNT;
cmd->stop_arg=0;
}else{
printf("can't find a good stop_src\n");
- return;
+ return -1;
}
ret=comedi_command_test(it,cmd);
+/*
+ * A very small one-shot input demo
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * 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
*/
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
-
-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;
+/*
+ * Multi-channel, multi-range one-shot input demo
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * 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
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
-
-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;
+/*
+ * Instruction example
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * 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.
#include <errno.h>
#include <sys/time.h>
#include <unistd.h>
-
-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;
/*
+ * This is a little helper function to parse options that
+ * are common to most of the examples.
*/
#include <stdio.h>
#include <getopt.h>
#include <ctype.h>
#include <malloc.h>
+#include "examples.h"
char *filename="/dev/comedi0";
+++ /dev/null
-/*
- 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 <stdio.h>
-#include <comedilib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <getopt.h>
-#include <ctype.h>
-
-#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;i<N_CHANS;i++){
- chan[i] = CR_PACK(channels[i], range, aref);
- }
-
- if ((err = comedi_trigger(dev, &it)) < 0) {
- perror("ioctl");
- exit(1);
- }
-
- m=0;
- while(1){
- if((n=read(comedi_fileno(dev),data,4096*sizeof(sampl_t)))<0){
- perror("read");
- exit(1);
- }
- if(n==0){
- perror("damn");
- exit(1);
- }
- n/=sizeof(sampl_t);
- m+=n;
- printf("read=%d total=%d data[0]=%d data[N-1]=%d\n",
- n,m,data[0],data[n-1]);
- }
-
- return 0;
-}
-
+++ /dev/null
-/*
- A little input demo for mode 3
-
- Mode 3 uses an external trigger to repeatedly trigger
- acquisition of samples. If you select n_chan>1, 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 <stdio.h>
-#include <comedilib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <getopt.h>
-#include <ctype.h>
-
-#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<N_CHANS;i++){
- chan[i] = CR_PACK(channels[i], range, aref);
- }
-
- if ((err = comedi_trigger(dev, &it)) < 0) {
- perror("ioctl");
- exit(1);
- }
-
- if((n=read(comedi_fileno(dev),data,N_SAMPLES*sizeof(sampl_t)))<0){
- perror("read");
- exit(1);
- }
- printf("number of samples read=%d\ndata[0]=%d\ndata[N-1]=%d\n",
- n/sizeof(sampl_t),data[0],data[N_SAMPLES-1]);
-
- return 0;
-}
-
+++ /dev/null
-/*
- 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 <stdio.h>
-#include <comedilib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <getopt.h>
-#include <ctype.h>
-
-#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<N_CHANS;i++){
- chan[i] = CR_PACK(channels[i], range, aref);
- }
-
- if ((err = comedi_trigger(dev, &it)) < 0) {
- perror("ioctl");
- exit(1);
- }
-
- if((n=read(comedi_fileno(dev),data,N_SAMPLES*sizeof(sampl_t)))<0){
- perror("read");
- exit(1);
- }
- printf("number of samples read=%d\ndata[0]=%d\ndata[N-1]=%d\n",
- n/sizeof(sampl_t),data[0],data[N_SAMPLES-1]);
-
- return 0;
-}
-
/*
- A little output demo
+ * A little output demo
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * 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 <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
-
-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;
+++ /dev/null
-
-
-# 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
-
+++ /dev/null
-
-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.
-
-
-
+++ /dev/null
-
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/version.h>
-#include <rtl_sched.h>
-#include <asm/rt_time.h>
-#include <comedi.h>
-
-
-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);
-}
-
-
+++ /dev/null
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/version.h>
-#include <rtl_sched.h>
-#include <rtl_compat.h>
-#include <rtl_printf.h>
-#include <asm/rt_time.h>
-#include <comedi.h>
-
-
-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);
-}
-
-
/*
- Demo of the comedi_sv_*() functions
+ * Demo of the comedi_sv_*() functions
+ *
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * This file may be freely modified, distributed, and combined with
+ * other software, as long as proper attribution is given in the
+ * source code.
*/
#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
-
-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;
+/*
+ * Tutorial example #1
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * This file may be freely modified, distributed, and combined with
+ * other software, as long as proper attribution is given in the
+ * source code.
+ */
#include <stdio.h> /* for printf() */
#include <comedilib.h>
+/*
+ * Tutorial example #2
+ * Part of Comedilib
+ *
+ * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
+ *
+ * This file may be freely modified, distributed, and combined with
+ * other software, as long as proper attribution is given in the
+ * source code.
+ */
#include <stdio.h> /* for printf() */
-#include <comedi.h> /* also included by comedilib.h */
-#include <comedilib.h> /* for comedi_get() */
+#include <comedilib.h>
-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[])
{