- From: David Carr <dc_at_dcarr.org>
- Date: Thu, 01 Apr 2004 14:51:14 -0600
Sorry to bug the list once again...
Has anyone had any difficulties with "indefinate" commands stopping? I
give my card a command with no stop trigger but after 65536 (same number
every time-2^16) calls to read(comedi_fileno(dev),(void *)data,8192) the
call seems to hand indefinitely with no error. This effectively limits
capture length. I'll attach my code below. Has anyone experienced this
before? It sounds like some 16bit counter overflow somewhere. If
anyone has indefinate reads working with NI series cards could you
please post your configuration/versions? Thanks for your help,
David Carr
read.c:
---
#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <math.h>
#define DEVICE_NAME "/dev/comedi0"
#define SUBDEVICE 0
#define CHANNEL 0
#define RANGE 6
#define AREF AREF_GROUND
/* ns between samples */
double timer_val = 2000;
/* read buffer size */
#define BUF_LEN 32768
sampl_t data[BUF_LEN];
int main(int argc, char *argv[])
{
comedi_cmd cmd;
int err;
int m;
int n_chan;
int aref, range, channel, subdevice;
comedi_t *dev;
unsigned int chanlist[16];
FILE* datafile;
/*Set a few options*/
channel = CHANNEL;
aref = AREF;
range = RANGE;
subdevice = SUBDEVICE;
/* Force n_chan to be 1 */
n_chan = 1;
dev = comedi_open(DEVICE_NAME);
if(dev == NULL){
fprintf(stderr, "error opening %s\n", DEVICE_NAME);
return -1;
}
datafile = fopen("dataout","w");
memset(&cmd,0,sizeof(cmd));
cmd.subdev = subdevice;
cmd.flags = TRIG_RT;
cmd.start_src = TRIG_NOW;
cmd.start_arg = 0;
cmd.scan_begin_src = TRIG_TIMER;
cmd.scan_begin_arg = timer_val;
cmd.convert_src = TRIG_TIMER;
cmd.convert_arg = 2000;
cmd.scan_end_src = TRIG_COUNT;
cmd.scan_end_arg = n_chan;
cmd.stop_src = TRIG_NONE;
cmd.stop_arg = 0;
cmd.chanlist = chanlist;
cmd.chanlist_len = n_chan;
chanlist[0] = CR_PACK(channel,range,aref);
if ((err = comedi_command(dev, &cmd)) < 0) {
comedi_perror("comedi_command");
exit(1);
}
while(1)
{
m=read(comedi_fileno(dev),(void *)data,8192);
fwrite((void *)data,2,m/2,datafile);
if(m<0)
{
perror("write");
exit(0);
}
printf("m=%d sample=%d\n",m,(short)data[0] );
}
return 0;
}
Received on 2004-04-01Z19:51:14