2 * This is a little helper function to parse options that
3 * are common to most of the examples.
18 static char * const default_filename = "/dev/comedi0";
20 void init_parsed_options(struct parsed_options *options)
22 memset(options, 0, sizeof(struct parsed_options));
23 options->filename = default_filename;
24 options->aref = AREF_GROUND;
26 options->n_scan = 1000;
27 options->freq = 1000.0;
28 options->physical = 0;
32 int parse_options(struct parsed_options *options, int argc, char *argv[])
36 while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:n:N:F:pvdgom"))) {
39 options->filename = optarg;
42 options->subdevice = strtoul(optarg, NULL, 0);
45 options->channel = strtoul(optarg, NULL, 0);
48 options->aref = strtoul(optarg, NULL, 0);
51 options->range = strtoul(optarg, NULL, 0);
54 options->n_chan = strtoul(optarg, NULL, 0);
57 options->n_scan = strtoul(optarg, NULL, 0);
60 options->freq = strtod(optarg, NULL);
63 options->physical = 1;
69 options->aref = AREF_DIFF;
72 options->aref = AREF_GROUND;
75 options->aref = AREF_OTHER;
78 options->aref = AREF_COMMON;
81 printf("bad option\n");
87 options->value = strtod(argv[optind++], NULL);
93 char *cmd_src(int src,char *buf)
97 if(src&TRIG_NONE)strcat(buf,"none|");
98 if(src&TRIG_NOW)strcat(buf,"now|");
99 if(src&TRIG_FOLLOW)strcat(buf, "follow|");
100 if(src&TRIG_TIME)strcat(buf, "time|");
101 if(src&TRIG_TIMER)strcat(buf, "timer|");
102 if(src&TRIG_COUNT)strcat(buf, "count|");
103 if(src&TRIG_EXT)strcat(buf, "ext|");
104 if(src&TRIG_INT)strcat(buf, "int|");
106 if(src&TRIG_OTHER)strcat(buf, "other|");
110 sprintf(buf,"unknown(0x%08x)",src);
112 buf[strlen(buf)-1]=0;
118 void dump_cmd(FILE *out,comedi_cmd *cmd)
122 fprintf(out,"start: %-8s %d\n",
123 cmd_src(cmd->start_src,buf),
126 fprintf(out,"scan_begin: %-8s %d\n",
127 cmd_src(cmd->scan_begin_src,buf),
128 cmd->scan_begin_arg);
130 fprintf(out,"convert: %-8s %d\n",
131 cmd_src(cmd->convert_src,buf),
134 fprintf(out,"scan_end: %-8s %d\n",
135 cmd_src(cmd->scan_end_src,buf),
138 fprintf(out,"stop: %-8s %d\n",
139 cmd_src(cmd->stop_src,buf),
143 int arm(comedi_t *device, unsigned subdevice, lsampl_t source)
149 memset(&insn, 0, sizeof(comedi_insn));
150 insn.insn = INSN_CONFIG;
151 insn.subdev = subdevice;
154 insn.n = sizeof(data) / sizeof(data[0]);
155 data[0] = INSN_CONFIG_ARM;
158 retval = comedi_do_insn(device, &insn);
161 fprintf(stderr, "%s: error:\n", __FUNCTION__);
162 comedi_perror("comedi_do_insn");
168 /* This resets the count to zero and disarms the counter. The counter output
170 int reset_counter(comedi_t *device, unsigned subdevice)
176 memset(&insn, 0, sizeof(comedi_insn));
177 insn.insn = INSN_CONFIG;
178 insn.subdev = subdevice;
181 insn.n = sizeof(data) / sizeof(data[0]);
182 data[0] = INSN_CONFIG_RESET;
184 retval = comedi_do_insn(device, &insn);
187 fprintf(stderr, "%s: error:\n", __FUNCTION__);
188 comedi_perror("comedi_do_insn");
194 int set_counter_mode(comedi_t *device, unsigned subdevice, lsampl_t mode_bits)
200 memset(&insn, 0, sizeof(comedi_insn));
201 insn.insn = INSN_CONFIG;
202 insn.subdev = subdevice;
205 insn.n = sizeof(data) / sizeof(data[0]);
206 data[0] = INSN_CONFIG_SET_COUNTER_MODE;
209 retval = comedi_do_insn(device, &insn);
212 fprintf(stderr, "%s: error:\n", __FUNCTION__);
213 comedi_perror("comedi_do_insn");
219 int set_clock_source(comedi_t *device, unsigned subdevice, lsampl_t clock, lsampl_t period_ns)
225 memset(&insn, 0, sizeof(comedi_insn));
226 insn.insn = INSN_CONFIG;
227 insn.subdev = subdevice;
230 insn.n = sizeof(data) / sizeof(data[0]);
231 data[0] = INSN_CONFIG_SET_CLOCK_SRC;
235 retval = comedi_do_insn(device, &insn);
238 fprintf(stderr, "%s: error:\n", __FUNCTION__);
239 comedi_perror("comedi_do_insn");
245 int set_gate_source(comedi_t *device, unsigned subdevice, lsampl_t gate_index, lsampl_t gate_source)
251 memset(&insn, 0, sizeof(comedi_insn));
252 insn.insn = INSN_CONFIG;
253 insn.subdev = subdevice;
256 insn.n = sizeof(data) / sizeof(data[0]);
257 data[0] = INSN_CONFIG_SET_GATE_SRC;
258 data[1] = gate_index;
259 data[2] = gate_source;
261 retval = comedi_do_insn(device, &insn);
264 fprintf(stderr, "%s: error:\n", __FUNCTION__);
265 comedi_perror("comedi_do_insn");