Skip to content
Snippets Groups Projects
Unverified Commit fd6a5119 authored by Anton Tetov Johansson's avatar Anton Tetov Johansson
Browse files

upload of basic example

parent 1c767501
No related branches found
No related tags found
No related merge requests found
LIBS=-lcomedi -lm
BINS=test_jr3_comedi.c
all: $(BINS)
clean:
\rm -rf *.o $(BINS)
%: %.c
$(CC) -o $@ $(CFLAGS) $^ $(LIBS)
%.o: %.c
$(CC) -c -o $@ $(CFLAGS) $<
// ./test_JR3_comedi /dev/comedi1 0
// see /etc/comedi.conf for device, subdevices and channel
// Example
// configure /dev/comedi1 jr3_pci
// ain 100 /dev/comedi1 0:0
// (port 0:1-6 filter 0 fx..mz(order OK?))
// port 0:7-12 filter 1 fx..mz(??)
// Available: port 0 & 1, but not yet 3 & 4 of receiver card
//
#define CF_JR3 "/dev/comedi1"
#define JR3_PORT 0
#define NBR_CHAN 6
#define _POSIX_C_SOURCE 199309
#include <time.h>
#include <comedilib.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct {
float a[NBR_CHAN];
} jr3_data_t;
typedef struct {
double min;
double max;
double delta;
double maxdata;
} info_t;
int main(int argc, char *argv[])
{
comedi_t *cf_jr3;
int subdev;
if (argc>1){
cf_jr3 = comedi_open(argv[1]);
subdev = atoi(argv[2]);
}
else{
cf_jr3 = comedi_open(CF_JR3);
subdev = JR3_PORT;
}
if (cf_jr3) {
int n, chan;
comedi_range *range;
lsampl_t maxdata;
info_t info[NBR_CHAN];
jr3_data_t jr3data; // [fx,fy,fz,mx,my,mx] ????
for (chan = 0 ; chan < NBR_CHAN ; chan++) {
range = comedi_get_range(cf_jr3, subdev, chan, 0);
maxdata = comedi_get_maxdata(cf_jr3, subdev, chan);
info[chan].min = range->min;
info[chan].max = range->max;
info[chan].maxdata = maxdata;
info[chan].delta = (range->max - range->min) / maxdata;
printf("channel maxdata min max delta %d %d %f %f %f \n", chan, maxdata, range->min, range->max, info[chan].delta);
}
while (1) {
struct timespec delay;
lsampl_t data;
delay.tv_sec = 0;
delay.tv_nsec = 500000000;
for (chan = 0 ; chan < NBR_CHAN ; chan++) {
int err = comedi_data_read(cf_jr3, subdev, chan, 0, 0, &data);
if (err < 0) {
printf("comedi_data_read error: err=%d subdev=%d %d %d\n",
err, subdev, chan, data);
} else {
jr3data.a[chan] = info[chan].min + (double)data * info[chan].delta;
}
}
for (chan = 0 ; chan < NBR_CHAN ; chan++) {
printf(" %f ", 1000.0*jr3data.a[chan]);
}
printf("\n");
nanosleep(&delay, 0);
}
}
else{
printf("Failed to open device!\n");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment