-CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes
+CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes -g
#CFLAGS += -I ../include -I . -Wall -Wstrict-prototypes -g
LDFLAGS = -L../lib/ -lcomedi -lm
command line options. Some options don't make sense with all programs.
The options are:
--a <aref> use analog reference <aref> (default: 0 == ground)
--c <chan> use channel <chan> (default: 0)
--s <subd> use subdevice <subd> (default: 0)
--r <index> use voltage range <index> (default: 0)
--f <file> use device file <file> (default: /dev/comedi0)
--v verbose
--d set analog reference to differential
--g set analog reference to ground
--o set analog reference to other
--m set analog reference to common
+ -a <aref> use analog reference <aref> (default: 0 == ground)
+ -c <chan> use channel <chan> (default: 0)
+ -s <subd> use subdevice <subd> (default: 0)
+ -r <index> use voltage range <index> (default: 0)
+ -f <file> use device file <file> (default: /dev/comedi0)
+ -n <value> use <value> for the number of channels in a scan
+ -N <value> use <value> for the number of scans
+ -F <freq> use <freq> as the scan frequency
+ -v verbose
+ -d set analog reference to differential
+ -g set analog reference to ground
+ -o set analog reference to other
+ -m set analog reference to common
}
data = value;
- if(verbose_flag){
+ if(verbose){
printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
data,filename,subdevice,channel,range,aref);
}
#ifndef _EXAMPLES_H
#define _EXAMPLES_H
+#include <stdio.h>
+
/*
* Definitions of some of the common code.
*/
extern int channel;
extern int aref;
extern int range;
+extern int verbose;
+extern int n_chan;
+extern int n_scan;
+extern double freq;
int parse_options(int argc, char *argv[]);
char *cmd_src(int src,char *buf);
-void dump_cmd(comedi_cmd *cmd);
+void dump_cmd(FILE *file,comedi_cmd *cmd);
#define sec_to_nsec(x) ((x)*1000000000)
exit(0);
}
- if(verbose_flag){
+ if(verbose){
printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
filename,subdevice,channel,range,aref);
}
exit(0);
}
- if(verbose_flag){
+ if(verbose){
printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
filename,subdevice,channel,range,aref);
}
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret=comedi_command_test(dev,cmd);
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret=comedi_command(dev,cmd);
#include <ctype.h>
#include <malloc.h>
#include <string.h>
+#include <stdlib.h>
#include "examples.h"
char *filename="/dev/comedi0";
-int verbose_flag;
+int verbose;
int value=0;
int subdevice=0;
int channel=0;
-int aref=0;
+int aref=AREF_GROUND;
int range=0;
+int n_chan=4;
+int n_scan=1000;
+double freq=1000.0;
int parse_options(int argc, char *argv[])
int c;
- while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:vdgom"))) {
+ while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:n:N:F:vdgom"))) {
switch (c) {
case 'f':
filename = optarg;
break;
case 's':
- sscanf(optarg,"%d",&subdevice);
+ subdevice = strtoul(optarg,NULL,0);
break;
case 'c':
- sscanf(optarg,"%d",&channel);
+ channel = strtoul(optarg,NULL,0);
break;
case 'a':
- sscanf(optarg,"%d",&aref);
+ aref = strtoul(optarg,NULL,0);
break;
case 'r':
- sscanf(optarg,"%d",&range);
+ range = strtoul(optarg,NULL,0);
+ break;
+ case 'n':
+ n_chan = strtoul(optarg,NULL,0);
+ break;
+ case 'N':
+ n_scan = strtoul(optarg,NULL,0);
+ break;
+ case 'F':
+ freq = strtoul(optarg,NULL,0);
break;
case 'v':
- verbose_flag = 1;
+ verbose = 1;
break;
case 'd':
- aref=AREF_DIFF;
+ aref = AREF_DIFF;
break;
case 'g':
- aref=AREF_GROUND;
+ aref = AREF_GROUND;
break;
case 'o':
- aref=AREF_OTHER;
+ aref = AREF_OTHER;
break;
case 'm':
- aref=AREF_COMMON;
+ aref = AREF_COMMON;
break;
default:
printf("bad option\n");
if(src&TRIG_COUNT)strcat(buf, "count|");
if(src&TRIG_EXT)strcat(buf, "ext|");
if(src&TRIG_INT)strcat(buf, "int|");
+#ifdef TRIG_OTHER
+ if(src&TRIG_OTHER)strcat(buf, "other|");
+#endif
if(strlen(buf)==0){
- sprintf(buf,"unknown(0x%02x)",src);
+ sprintf(buf,"unknown(0x%08x)",src);
}else{
buf[strlen(buf)-1]=0;
}
return buf;
}
-void dump_cmd(comedi_cmd *cmd)
+void dump_cmd(FILE *out,comedi_cmd *cmd)
{
char buf[100];
- printf("start: %s %d\n",
+ fprintf(out,"start: %-8s %d\n",
cmd_src(cmd->start_src,buf),
cmd->start_arg);
- printf("scan_begin: %s %d\n",
+ fprintf(out,"scan_begin: %-8s %d\n",
cmd_src(cmd->scan_begin_src,buf),
cmd->scan_begin_arg);
- printf("convert: %s %d\n",
+ fprintf(out,"convert: %-8s %d\n",
cmd_src(cmd->convert_src,buf),
cmd->convert_arg);
- printf("scan_end: %s %d\n",
+ fprintf(out,"scan_end: %-8s %d\n",
cmd_src(cmd->scan_end_src,buf),
cmd->scan_end_arg);
- printf("stop: %s %d\n",
+ fprintf(out,"stop: %-8s %d\n",
cmd_src(cmd->stop_src,buf),
cmd->stop_arg);
}
#define N_SCANS 10
#define N_CHANS 16
-double freq = 1000;
-
#define BUFSZ 1000
char buf[BUFSZ];
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret = comedi_command_test(dev,cmd);
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret = comedi_command(dev,cmd);
}
data = value;
- if(verbose_flag){
+ if(verbose){
printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
data,filename,subdevice,channel,range,aref);
}
#define N_SCANS 10
#define N_CHANS 16
-double freq = 1000;
-
#define BUFSZ 1000
sampl_t buf[BUFSZ];
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret=comedi_command_test(dev,cmd);
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret=comedi_command(dev,cmd);
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
cmd->chanlist = chanlist;
cmd->chanlist_len = n_chans;
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
cmd->chanlist = chanlist;
cmd->chanlist_len = n_chans;
#define N_SCANS 10
#define N_CHANS 16
-double freq = 1000;
-
#define BUFSZ 1000
sampl_t buf[BUFSZ];
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret=comedi_command_test(dev,cmd);
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret=comedi_command(dev,cmd);
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret=comedi_command_test(dev,cmd);
return;
}
- dump_cmd(cmd);
+ dump_cmd(stdout,cmd);
ret=comedi_command(dev,cmd);
exit(0);
}
- if(verbose_flag){
+ if(verbose){
printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
filename,subdevice,channel,range,aref);
}