fix internal trigger when testing write command, and fix test when
authorFrank Mori Hess <fmhess@speakeasy.net>
Sat, 24 Jul 2004 16:09:01 +0000 (16:09 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sat, 24 Jul 2004 16:09:01 +0000 (16:09 +0000)
write command uses stop_src==TRIG_NONE instead of TRIG_COUNT

testing/cmd_1.c
testing/comedi_test.h

index 6b16a514eb874cd6a1bdc6e4f98220c8ba7cf929..843f6722dfd6ff28f7e1ca89ebd1985f4ed75371 100644 (file)
@@ -161,7 +161,16 @@ int test_cmd_write_fast_1chan(void)
        int total=0;
        int ret;
        unsigned int flags = comedi_get_subdevice_flags(device,subdevice);
-
+       static const int num_samples = 100000;
+       int num_bytes;
+       
+       if((flags & SDF_LSAMPL))
+       {
+               num_bytes = num_samples * sizeof(lsampl_t);
+       }else
+       {
+               num_bytes = num_samples * sizeof(sampl_t);
+       }
        if(!(flags&SDF_CMD) || !(flags&SDF_WRITEABLE)){
                printf("not applicable\n");
                return 0;
@@ -175,7 +184,7 @@ int test_cmd_write_fast_1chan(void)
        if(realtime)cmd.flags |= TRIG_RT;
        cmd.chanlist = chanlist;
        cmd.scan_end_arg = 1;
-       cmd.stop_arg = 1000000;
+       cmd.stop_arg = num_samples;
        cmd.chanlist_len = 1;
        chanlist[0] = CR_PACK(0,0,0);
 
@@ -202,18 +211,13 @@ int test_cmd_write_fast_1chan(void)
                if(verbose)printf("write %d %d\n",ret,total);
        }
        
-       {
-               comedi_insn insn;
-               memset(&insn, 0, sizeof(comedi_insn));
-               insn.insn = INSN_INTTRIG;
-               insn.subdev = subdevice;
-               ret = comedi_do_insn(device, &insn);
-               if(ret<0){
-                       perror("comedi_inttrig");
-                       return 0;
-               }
-               if(verbose)printf("inttrig\n");
+       ret = comedi_internal_trigger(device, subdevice, 0);
+       if(ret<0){
+               perror("E: comedi_inttrig");
+               comedi_cancel(device, subdevice);
+               return 0;
        }
+       if(verbose)printf("inttrig\n");
 
        go=1;
        while(go){
@@ -230,9 +234,25 @@ int test_cmd_write_fast_1chan(void)
                }else{
                        total += ret;
                        if(verbose)printf("write %d %d\n",ret,total);
+                       //deal with case where output doesn't support stop_src=TRIG_COUNT
+                       if(total >= num_bytes)
+                       {
+                               go = 0;
+                       }
                }
        }
-
+       // make sure all samples have been written out
+       while(1)
+       {       
+               ret = comedi_get_buffer_contents(device, subdevice);
+               if(ret < 0)
+               {
+                       printf("E: comedi_get_buffer_contents() returned %i\n", ret);
+               }else if(ret == 0) break;
+       }
+       // cancel needed in the case of stop_src==TRIG_NONE
+       if(comedi_cancel(device, subdevice))
+               printf("E: comedi_cancel() failed");
        return 0;
 }
 
index 58f084d3ff382415100a3ddea7e74dff40fb8658..eab6e0aabe19495980a502556398fadf515b5014 100644 (file)
@@ -13,5 +13,8 @@ extern unsigned int capabilities;
 
 extern int realtime;
 
+extern int comedi_internal_trigger(comedi_t *device,unsigned int subdevice,
+       unsigned int trignum);
+
 #endif