comedi_command problems

Hello all,
      Sorry to bother the list again, but I was getting pretty far on my 
project until yesterday when I ran into problems.  I'm trying to get data 
from a time of flight camera that's connected to an NI PCI-MIO-16E 
card.  The camera is sending data over channels 1 and 8, and uses PFI pins 
0 and 2 for triggering.  One frame is 64x200 pixels.  I had a program that 
seemed to be working, which was based on cmd.c from the comedi demos, but 
it stopped working yesterday (The camera still works, we verified this with 
the Windows software).  I combined just the necessary stuff from cmd.c, 
examples.h and common.c to create something that should work, but it 
doesn't.  Here's the code:

#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

#define BUFSZ 25600
//64x200x2channels
char buf[BUFSZ];

int main()
{
   char *filename="/dev/comedi0";
   //int verbose_flag;
   comedi_t *device;

   int value=0;
   int subdevice=0;
   int channel=0;
   int aref=AREF_GROUND;
   int range=11; // 0 - 2V
   int n_chan=2; // Channels 0 and 8
   int n_scan=12800; //64x200
   //double freq;

   char *cmdtest_messages[]={
         "success",
         "invalid source",
         "source conflict",
         "invalid argument",
         "argument conflict",
         "invalid chanlist",
   };

   unsigned int chanlist[n_chan];

   comedi_t *dev;
   comedi_cmd c,*cmd=&c;
   int ret;
   int total=0;
   int i;
   struct timeval start,end;

   dev=comedi_open(filename);
   if (!dev) {
     comedi_perror(filename);
     exit(1);
   }

   chanlist[0]=CR_PACK(0,range,aref); //channel 0
   chanlist[1]=CR_PACK(8,range,aref); //channel 8

   cmd = new comedi_cmd;
   cmd->subdev=subdevice;
   cmd->flags=0;
   cmd->start_src=TRIG_NOW;
   cmd->start_arg=0;
   cmd->scan_begin_src = TRIG_EXT;
   cmd->scan_begin_arg = 0; // PFI Pin 0
   cmd->convert_src = TRIG_EXT;
   cmd->convert_arg = 2; // PFI Pin 2
   cmd->scan_end_src = TRIG_COUNT;
   cmd->scan_end_arg = n_chan;
   cmd->stop_src = TRIG_COUNT;
   cmd->stop_arg = n_scan;
   cmd->chanlist = chanlist;
   cmd->chanlist_len = n_chan;

   ret=comedi_command_test(dev,cmd);
   fprintf(stderr, "command test returned %d 
(%s)\n",ret,cmdtest_messages[ret]);

   printf("sending command...\n");
   ret=comedi_command(dev,cmd);
   printf("command sent\n");
   if(ret<0){
     comedi_perror("comedi_command");
     exit(1);
   }

   ret=read(comedi_fileno(dev),buf,BUFSZ);
   printf("ret equals %d\n", ret);

   if(ret<0){
     /* some error occurred */
     perror("read");
   }
   else if(ret==0){
     /* reached stop condition */
     printf("stop\n");
   }
   else{
     static int col = 0;
     total+=ret;
     fprintf(stderr,"read %d %d\n",ret,total);
     for(i=0;i<ret/2;i++){
       printf("%d ",((sampl_t *)buf)[i]);
       col++;
       if(col==n_chan){
         printf("\n");
         col=0;
       }
     }
   }


}

The comedi_command_test returns 0, then it is able to send the command, but 
just sits there waiting for data when it gets to the read.  The camera is 
turned on and everything, we checked all the connections and stuff like 
that.  Any ideas?

Thanks,
Justin

Received on 2003-07-09Z18:38:38