pearu / pylibnidaqmx

a Python wrapper to libnidaqmx library
Other
10 stars 9 forks source link

a hardcoded path should not be used to find NIDAQmx.h #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Install 32-bit NIDAQ on a 64-bit Windows system
2. Verify that nidaqmx does not have the nidaqmx_h_x_x.py file corresponding to 
the version of NIDAQ that is installed.
3. Try to import nidaqmx.

What is the expected output? What do you see instead?

It should generate the nidaqmx_h_x_x.py for the corresponding version of 
NIDAQmx.  Since the NIDAQ header is in ...\Program Files (x86)\... pylibnidaqmx 
will crash because the file it's looking for doesn't exist.

What version of the product are you using? On what operating system?

SVN r38, Win7 64

Attached patch uses programfiles environment variable, which should do the 
Right Thing.

Also attached is the autogenerated file for version 9.3.

Original issue reported on code.google.com by jpko...@gmail.com on 30 Mar 2012 at 10:06

Attachments:

GoogleCodeExporter commented 9 years ago
This is a more correct patch, because it works with 32- and 64-bit python on 64 
bit platforms.  The previous one only works with 32-bit python.

Original comment by jpko...@gmail.com on 4 Apr 2012 at 12:20

Attachments:

GoogleCodeExporter commented 9 years ago
Wouldn't it be better to use the location that National Instruments populates 
in the registry? Then you're not presuming anything (what if the user didn't 
install to program files?). On 64bit windows, 32bit software gets redirected to 
Wow6432Node branches in the registry, but if we have 32bit python on 64bit 
Windows, all we know is our platform is 32bit (I don't know if 
platform.machine() returns the CPU platform, or the OS platform...). Currently, 
we know all NI DAQ stuff is 32bit, but in the future it might be 64bit. The 
below should work in all cases.

import _winreg as winreg
regpath = r'SOFTWARE\National Instruments\NI-DAQmx\CurrentVersion\Path'
reg6432path = r'SOFTWARE\Wow6432Node\National 
Instruments\NI-DAQmx\CurrentVersion\Path'

try:
    regkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, regpath)
except WindowsError:
    regkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg6432path)

include_nidaqmx_h = winreg.QueryValueEx(regkey, 'Path')
regkey.Close()

ansi_c_dev = os.path.join(include_nidaqmx_h, r'National 
Instruments\NI-DAQ\DAQmx ANSI C Dev')

and then 
include_nidaqmx_h = os.path.join(ansi_c_dev, r'include\NIDAQmx.h')
lib = os.path.join(ansi_c_dev, r'lib\nicaiu.dll')

Original comment by bobp...@gmail.com on 4 Apr 2012 at 1:39

GoogleCodeExporter commented 9 years ago
shoot... that should be:
regpath = r'SOFTWARE\National Instruments\NI-DAQmx\CurrentVersion'
reg6432path = r'SOFTWARE\Wow6432Node\National 
Instruments\NI-DAQmx\CurrentVersion'

Original comment by bobp...@gmail.com on 4 Apr 2012 at 3:38

GoogleCodeExporter commented 9 years ago
I have added autogenerated header file for version 9.3 to svn repo.

jpkotta, can you try out bobpaul suggestion on using winreg to acquire
proper include and library paths and send a new patch? If you don't
have time for it, let me know, then I'll apply the current patch
as I cannot test bobpaul suggestion myself (we are running on Linux here).

Or, bobpaul, perhaps you have already tried your suggestion and it works.
In that case, I can just copy the code in and hope that it will work for
others as well.

In any case, I would prefer that patches are tested before applying to
svn.

Original comment by pearu.peterson on 9 Apr 2012 at 8:41

GoogleCodeExporter commented 9 years ago
I worked it into a proper patch and tested it on 32bit XP and 64bit Win7.

Original comment by bobp...@gmail.com on 9 Apr 2012 at 8:47

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks! Patch applied to svn.

Original comment by pearu.peterson on 10 Apr 2012 at 10:30

GoogleCodeExporter commented 9 years ago
This issue is related to Issue 23.

Original comment by pearu.peterson on 19 Apr 2012 at 9:47