Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAQmxGetDeviceAttribute - error with python 32bits (ok with python 64bits) #9

Open
rercek opened this issue Feb 24, 2014 · 2 comments

Comments

@rercek
Copy link

rercek commented Feb 24, 2014

Hello,

I'm currently using the function DAQmxGetDeviceAttribute to obtain device attribute. It works fine with python 64bits (anaconda package) but it doesn't work with python 32bits (under windows 7 64bits or windows xp 32bits) :

some examples

from PyDAQmx import *
dev='Dev1'
rate=(ctypes.c_double*1)()
#maximum input rate for all channels
DAQmxGetDeviceAttribute(dev,DAQmx_Dev_AI_MaxSingleChanRate,byref(rate)) 
from PyDAQmx import *
dev='Dev1'
chans=ctypes.create_string_buffer('',1024)
#obtain the analog input channel name
DAQmxGetDeviceAttribute(dev,DAQmx_Dev_AI_PhysicalChans,chans) 

I have the same errors :

DAQmxGetDeviceAttribute(dev,DAQmx_Dev_AI_MaxSingleChanRate,byrefrate)) #maxi
mum input rate for all channels
  File "<string>", line 2, in function
  File "C:\Anaconda\lib\site-packages\PyDAQmx\DAQmxFunctions.py", line 23, in ma
function
    error = f(*arg)
ValueError: Procedure probably called with too many arguments (12 bytes in exces
s)

If I correctly understand this error, it seems that the "address" of arguments are sent using a 64bits value in place of 32bits values (3x4bytes/32bits in excess). I don't know if this error can be avoided by calling these functions with other parameters or corrections have to be made in the pydaqmx package or another one ?

I have a similar error when using DAQmxGetSystemInfoAttribute (8 bytes in excess) e.g.

from PyDAQmx import *
dev=ctypes.create_string_buffer('',1024)
DAQmxGetSystemInfoAttribute(DAQmx_Sys_DevNames,dev)

Let us notice that the acquisition functions work fine. When I look at the protype of these 2 functions (in NIDAQmx.h), I remark that they are variadic functions ... Maybe it explains the origin of the error ...

Could you please have a look in this and tell me if I'm doing something wrong or is it a problem with a package ?

I thank you in advance,
Kind regards,
Rudy

edit : some further tests seem to focus the problem when using windll to run these functions with python 32bits BUT the acquisitions (class Task) do not work anymore if I replace windll by cdll in the DAQmxFunctions.py when using python 32bits (ValueError: Procedure called with not enough arguments (8 bytes missing) or wrong calling convention) No problem using python 64bits in both case (windll or cdll).

This example code works fine with python 64bits & python 32bits in windows 7 64bits (not yet tested with windows xp) :

from ctypes import *
lib_name="nicaiu"
DAQlib = cdll.LoadLibrary(lib_name)
dev=create_string_buffer("Dev1")
att=c_long(10636) #DAQmx_Dev_AI_MaxSingleChanRate
rate=(c_double*1)()
DAQlib.DAQmxGetDeviceAttribute(dev,att,rate)
print rate[0]
inf=c_int32(0x193B) #DAQmx_Sys_DevNames,dev
devi=create_string_buffer('',1024)
DAQlib.DAQmxGetSystemInfoAttribute(inf,devi)
print devi.value
@clade
Copy link
Owner

clade commented Feb 25, 2014

Dear

Thanks for posting this issue.

I arrived to the same conclusion. By using the cdll calling convention it works (on windows XP 32bits). But of course everything else is no longer working.

I have created a new branch (called variadic_function) which I think could solve the problem. I did not test it (and can only do it on Win XP). Can you test it on the different platforms you are using.

Regards.
Pierre

@rercek
Copy link
Author

rercek commented Feb 25, 2014

Dear,

Thank you very much for your reply, your tests, your patch and even more for your nidaqmx python wrapper :-)

I tried the new branch on windows xp 32bits & windows 7 64bits (python x32 & x64) and it seems to work fine now with all functions !

By the way, meanwhile, I found in the nidaqmx header that there is a function (not variadic) for every call of DAQmxGetAttribute. So, I replaced them with their equivalents (e.g. DAQmxGetDevAIMaxSingleChanRate ) which works everywhere by default with your master branch. The nidaqmx library documentation is really poor ...

If you need other tests or information, don't hesitate to contact me !

Thank you again for your help.
Best regards,
Rudy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants