comedilib/demo/choose_routing.c
Frank Mori Hess fbdf65b4f5 Made parse_options() write options to a struct instead of passing
them through global variables.
2007-01-03 21:14:53 +00:00

70 lines
1.6 KiB
C

/*
* INSN_CONFIG_SET_ROUTING example
* Part of Comedilib
*
* Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
* Copyright (c) 2007 Frank Mori Hess <fmhess@users.sourceforge.net>
*
* 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 <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include "examples.h"
comedi_t *device;
int main(int argc, char *argv[])
{
unsigned period_ns;
int retval;
lsampl_t routing;
struct parsed_options options;
init_parsed_options(&options);
options.freq = 0.;
parse_options(&options, argc, argv);
device = comedi_open(options.filename);
if(!device){
comedi_perror(options.filename);
exit(-1);
}
if(options.freq > 0.)
period_ns = 1e9 / options.freq;
else
period_ns = 0;
routing = options.value;
printf("Selecting routing %d for channel %d on subdevice %d.\n", routing, options.channel, options.subdevice);
comedi_insn insn;
lsampl_t data[2];
memset(&insn, 0, sizeof(comedi_insn));
insn.insn = INSN_CONFIG;
insn.subdev = options.subdevice;
insn.chanspec = options.channel;
insn.data = data;
insn.n = sizeof(data) / sizeof(data[0]);
data[0] = INSN_CONFIG_SET_ROUTING;
data[1] = routing;
retval = comedi_do_insn(device, &insn);
if(retval < 0) comedi_perror("comedi_do_insn");
return retval;
}