- From: Bernd Porr <BerndPorr_at_f2s.com>
- Date: Wed, 22 Sep 2004 23:08:22 +0100
Hi!
I think the only major problem was a ring buffer overflow in comedi. The
screen output is probably too slow that it can handle so much data.
Therefore the -EOVERFLOW. It is also not advisable to read just one byte
from the ring buffer. This might be also too slow.
Anyway. Here's the code bit which actually works. If you are sampling
continously the best thing is to check if the ring buffer actually has
data. You can also add a usleep in the outer while loop. This makes the
output a bit more bursty. In particular for higher rates this is
probably better.
Please post such questions in the future to the general comedi mailing
list. Other users also want to benefit from our discussions.
/Bernd
Michael Van Damme wrote:
>
> Sorry, I apparently forgot to attach my test program. I did some more
> test with it, and with the code snippet you provided. It seems that for
> some time, they both work, but it always takes a very long time (over 15
> seconds) before any output is produced. Then they print out around 35000
> samples, and stop (forever). dmesg shows:
>
> comedi0: usbdux: dux_commands: 03 00 00 18 2c 3c 4c 5c 6c 00 00 00 00
> 00 00 00 00 00 00 00 00 00 00 00 00 00
> comedi0: usbdux: dio_read: buffer[0]=255
> comedi0: usbdux_ai_cmdtest
> comedi0: usbdux_ai_cmdtest
> comedi0: usbdux_ai_cmd
> comedi0: adc command for ch 0 is 2
> comedi0: adc command for ch 1 is 8
> comedi 0: sending commands to the usb device: size=8
> comedi0: usbdux: dux_commands: 00 02 08 18 2c 3c 4c 5c 6c 00 00 00 00
> 00 00 00 00 00 00 00 00 00 00 00 00 00
> comedi0: usbdux: submitting in-urb[0]: dcc68000,dcce7200 intv=1
> comedi0: usbdux: submitting in-urb[1]: dcc68000,dcce7200 intv=1
> comedi0: usbdux: submitting in-urb[2]: dcc68000,dcce7200 intv=1
> comedi0: usbdux: submitting in-urb[3]: dcc68000,dcce7200 intv=1
> comedi0: usbdux: submitting in-urb[4]: dcc68000,dcce7200 intv=1
> Non-zero urb status received in ai intr context: -75
> comedi: usbdux_ai_stop
>
> Using dmesg before the output appears yields the same output except for
> the last two lines.
>
> Source for both programs:
> Original test program:
>
> #include <comedi.h>
> #include <comedilib.h>
> #include <stdio.h>
>
>
> int main() {
>
> comedi_t *dev;
> dev = comedi_open("/dev/comedi0");
>
> unsigned int chanlist[] = { CR_PACK(0,2,AREF_GROUND),
> CR_PACK(1,2,AREF_GROUND) };
>
> comedi_cmd cmd;
>
> cmd.subdev = 0;
> cmd.flags = 0;
> cmd.start_src = TRIG_NOW;
> cmd.start_arg = 0;
> cmd.scan_begin_src = TRIG_TIMER;
> cmd.scan_begin_arg = 1e6; /* 1e6 ns = 1ms */
> cmd.convert_src = TRIG_NOW;
> cmd.convert_arg = 0;
> cmd.scan_end_src = TRIG_COUNT;
> cmd.scan_end_arg = 2;
>
> // This works:
> // cmd.stop_src = TRIG_COUNT;
> // cmd.stop_arg = 10;
>
> // This doesn't work:
> cmd.stop_src = TRIG_NONE;
> cmd.stop_arg = 0;
>
> cmd.chanlist = chanlist;
> cmd.chanlist_len = 2;
>
> int ret = comedi_command_test(dev, &cmd);
> printf("comedi_command_test return value: %d\n", ret);
>
> ret = comedi_command(dev, &cmd);
> printf("comedi_command return value: %d\n", ret);
>
> sampl_t data[10];
> int i = 0;
> while(1) {
> int r = read(comedi_fileno(dev), data, 1*sizeof(sampl_t));
> if (r) printf("%d: %d\n", i++, data[0]);
> }
>
> return 0;
> }
>
>
> Modified program (with your snippet):
>
> #include <comedi.h>
> #include <comedilib.h>
> #include <stdio.h>
>
>
> int main() {
>
> comedi_t *dev;
> dev = comedi_open("/dev/comedi0");
>
> unsigned int chanlist[] = { CR_PACK(0,2,AREF_GROUND),
> CR_PACK(1,2,AREF_GROUND) };
>
> comedi_cmd cmd;
>
> // Start of snippet
>
> int r = comedi_get_cmd_generic_timed(dev,
> 0,
> &cmd,
> (int)(1e6));
> if(r<0){
> printf("comedi_get_cmd_generic_timed failed\n");
> exit(-1);
> }
>
> /* Modify parts of the command */
> cmd.chanlist = chanlist;
> cmd.chanlist_len = 2;
>
> cmd.scan_end_arg = 2;
>
> cmd.stop_src=TRIG_NONE;
> cmd.stop_arg=0;
>
> int ret = comedi_command_test(dev,&cmd);
> if(ret<0){
> comedi_perror("comedi_command_test");
> exit(-1);
> }
> fprintf(stderr,"first test returned %d\n",ret);
>
> ret = comedi_command_test(dev,&cmd);
> if(ret<0){
> comedi_perror("comedi_command_test");
> exit(-1);
> }
> fprintf(stderr,"second test returned %d\n",ret);
> if(ret!=0){
> fprintf(stderr,"Error preparing command\n");
> exit(-1);
> }
>
> comedi_set_global_oor_behavior( COMEDI_OOR_NUMBER );
>
> /* start the command */
> ret=comedi_command(dev,&cmd);
>
> // End of snippet
>
> sampl_t data[10];
> int i = 0;
> while(1) {
> int r = read(comedi_fileno(dev), data, 1*sizeof(sampl_t));
> if (r) printf("%d: %d\n", i++, data[0]);
> }
>
> return 0;
> }
>
>
> Thanks,
> Michael
>
> Bernd Porr wrote:
>
>> Michael Van Damme wrote:
>>
>>>
>>> Hi,
>>>
>>> I've finally found the time to start experimenting with my usb-dux
>>> device, and I've immediately hit a hard to solve (for me, that is!)
>>> problem. In a test program, I'm using a comedi command to do
>>> streaming acquisition. It works if I use stop_src=TRIG_COUNT, but is
>>> doesn't work with stop_src=TRIG_NONE. Any ideas on what is wrong?
>>>
>>> Thanks,
>>> Michael
>>>
>>>
>>>
>>
>>
>> Michael,
>>
>> it should!
>>
>> Here's a code snipplett:
>>
>> int r = comedi_get_cmd_generic_timed(dev,
>> subdevice,
>> cmd,
>> (int)(1e9/1000));
>> if(r<0){
>> printf("comedi_get_cmd_generic_timed failed\n");
>> exit(-1);
>> }
>>
>> /* Modify parts of the command */
>> cmd->chanlist = chanlist;
>> cmd->chanlist_len = n_chan;
>>
>> cmd->scan_end_arg = n_chan;
>>
>> cmd->stop_src=TRIG_NONE;
>> cmd->stop_arg=0;
>>
>> int ret = comedi_command_test(dev,cmd);
>> if(ret<0){
>> comedi_perror("comedi_command_test");
>> exit(-1);
>> }
>> fprintf(stderr,"first test returned %d\n",ret);
>>
>> ret = comedi_command_test(dev,cmd);
>> if(ret<0){
>> comedi_perror("comedi_command_test");
>> exit(-1);
>> }
>> fprintf(stderr,"second test returned %d\n",ret);
>> if(ret!=0){
>> fprintf(stderr,"Error preparing command\n");
>> exit(-1);
>> }
>>
>> comedi_set_global_oor_behavior( COMEDI_OOR_NUMBER );
>>
>> /* start the command */
>> ret=comedi_command(dev,cmd);
>>
>>
>>
>> It's from the oscilloscope program on the DUX web page. It's important
>> that you call comedi_command_test after you've modified the cmd
>> structure.
>>
>> If you still run into problems, please send me your syslog.
>>
>> /Bernd
>>
>>
>
>
Attachments
- text/x-csrc attachment: test.c
Received on 2004-09-22Z21:08:22