alsterane / pylibnidaqmx

Automatically exported from code.google.com/p/pylibnidaqmx
Other
0 stars 0 forks source link

Device.get_digital_input_lines() fails for NI USB-6509 #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
1. Attach a NI USB-6509 or set up a simulated one in NI MAX
2. Get the correct device from nidaqmx
3. Do device.get_digital_input_lines()

You get the following traceback:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)

C:\DOCUME~1\tester\MYDOCU~1\SMSC\nidaqmx\<ipython console> in <module>()

C:\DOCUME~1\tester\MYDOCU~1\SMSC\nidaqmx\nidaqmx\libnidaqmx.py in
get_digital_in
put_lines(self)
    316         buf_size = 1000
    317         buf = ctypes.create_string_buffer('\000' * buf_size)
--> 318         CALL ('GetDevDILines', self, ctypes.byref (buf), buf_size)
    319         names = [n.strip() for n in buf.value.split(',') if n.strip()]
    320         return names

C:\DOCUME~1\tester\MYDOCU~1\SMSC\nidaqmx\nidaqmx\libnidaqmx.py in
CALL(name, *ar
gs)
    164             new_args.append (a)
    165     r = func(*new_args)
--> 166     r = CHK(r, funcname, *new_args)
    167     return r
    168

C:\DOCUME~1\tester\MYDOCU~1\SMSC\nidaqmx\nidaqmx\libnidaqmx.py in
CHK(return_cod
e, funcname, *args)
    148             text = '\n  '.join(['']+textwrap.wrap(buf.value,
80)+['-'*10
])
    149             if return_code < 0:
--> 150                 raise RuntimeError('%s%s:%s' % (funcname,args, text))
    151             else:
    152                 sys.stderr.write('%s%s warning:%s\n' % (funcname, args,
text))

RuntimeError: DAQmxGetDevDILines('Dev1', <cparam 'P' (0149C338)>, 1000):
  Buffer is too small to fit the string.
  ----------

In [16]: s.devices[0].get_digital_output_lines()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)

C:\DOCUME~1\tester\MYDOCU~1\SMSC\nidaqmx\<ipython console> in <module>()

C:\DOCUME~1\tester\MYDOCU~1\SMSC\nidaqmx\nidaqmx\libnidaqmx.py in
get_digital_ou
tput_lines(self)
    338         buf_size = 1000
    339         buf = ctypes.create_string_buffer('\000' * buf_size)
--> 340         CALL ('GetDevDOLines', self, ctypes.byref (buf), buf_size)
    341         names = [n.strip() for n in buf.value.split(',') if n.strip()]
    342         return names

C:\DOCUME~1\tester\MYDOCU~1\SMSC\nidaqmx\nidaqmx\libnidaqmx.py in
CALL(name, *ar
gs)
    164             new_args.append (a)
    165     r = func(*new_args)
--> 166     r = CHK(r, funcname, *new_args)
    167     return r
    168

C:\DOCUME~1\tester\MYDOCU~1\SMSC\nidaqmx\nidaqmx\libnidaqmx.py in
CHK(return_cod
e, funcname, *args)
    148             text = '\n  '.join(['']+textwrap.wrap(buf.value,
80)+['-'*10
])
    149             if return_code < 0:
--> 150                 raise RuntimeError('%s%s:%s' % (funcname,args, text))
    151             else:
    152                 sys.stderr.write('%s%s warning:%s\n' % (funcname, args,
text))

RuntimeError: DAQmxGetDevDOLines('Dev1', <cparam 'P' (010FD6E0)>, 1000):
  Buffer is too small to fit the string.
  ----------

Increasing the buffer size in get_digital_input_lines() and
get_digital_output_lines() to 2500 works fine (actual response size is
probably about half of this).  A more general solution would be better.

Original issue reported on code.google.com by cwebster...@gtempaccount.com on 25 Feb 2010 at 7:44

GoogleCodeExporter commented 9 years ago
I am going to add buf_size=3000 kw argument to get_digital_input_lines and
other related methods so that user can increase the buffer size when
the default size turns out to be too small.

A general solution would be to have a loop that catches runtime errors
and increases the buffer size incrementally until the call succeeds.
But let's see if simpler solution works for users. I'll commit the
changes within an hour.

Original comment by pearu.peterson on 26 Feb 2010 at 8:33

GoogleCodeExporter commented 9 years ago
I have committed a patch (r28) with the following features:

1) libnidaqmx.py module has global variable default_buf_size
that can be increased in runtime when the default value 3000
turns out to be too small.

2) get_digital_input_lines and related functions have buf_size=None
kw argument that can be used to override default_buf_size for
a local method call.

Let me know if this solution work for your application.

Original comment by pearu.peterson on 26 Feb 2010 at 9:26