Discussion:
[Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle
Daniel Krause
2013-01-15 20:41:51 UTC
Permalink
I am trying to use a dll to control a camera.
It is possible for me to use the dll with ironpython, but I fail to use it
with python for .NET (CLR 4.0).
(And I would like to use e.g. numpy as well, so I need python for .NET).

Below follow a short test script, the python / ironpython versions and
their console output when running the test script.

Any hints are welcome.
Thank you
Daniel

########################################################
#test script "testcam.py" #1 for python for .NET
import clr
import sys
sys.path.append("C:\\Users\\mdk\\workspace\\camera\\")
clr.AddReference("xiAPI40.NET")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name

###############
#console output showing the python version,
#installed is .NET-support with pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe
on Win7 64bit
PS C:\Users\mdk\workspace\camera> python.exe
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.


###############
#running test script #1 with python, console output
Traceback (most recent call last):
File "C:\Users\mdk\workspace\camera\testcam.py", line 8, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)

at xiApi.NET.xiCam.OpenDevice(Int32 DevID)

######################################################
#test script "testcam.py" #1 modified for ironpython, test script #2
import clr
import sys
sys.path.append("C:\\Users\\mdk\\camera\\")
clr.AddReference("xiAPI40.NET.dll")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name

###############
#console output showing the ironpython version
PS C:\Users\mdk\workspace\camera> ipy.exe
IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.17929
Type "help", "copyright", "credits" or "license" for more information.
##############
#running test script #2 with ironpython, console output
MQ013MG-E2
Tribble, Brett
2013-01-15 21:08:11 UTC
Permalink
I assume you don't have the source to the .dll?

If you do, you can add a line to use debug the error using System.Diagnostics.Debugger.Break():

http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx



From: PythonDotNet [mailto:pythondotnet-bounces+btribble=ea.com-+ZN9ApsXKcFQFI55V6+***@public.gmane.orgg] On Behalf Of Daniel Krause
Sent: Tuesday, January 15, 2013 12:42 PM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle

I am trying to use a dll to control a camera.
It is possible for me to use the dll with ironpython, but I fail to use it with python for .NET (CLR 4.0).
(And I would like to use e.g. numpy as well, so I need python for .NET).

Below follow a short test script, the python / ironpython versions and their console output when running the test script.

Any hints are welcome.
Thank you
Daniel

########################################################
#test script "testcam.py" #1 for python for .NET
import clr
import sys
sys.path.append("C:\\Users\\mdk\\workspace\\camera\\")
clr.AddReference("xiAPI40.NET")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name

###############
#console output showing the python version,
#installed is .NET-support with pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe on Win7 64bit
PS C:\Users\mdk\workspace\camera> python.exe
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.


###############
#running test script #1 with python, console output
Traceback (most recent call last):
File "C:\Users\mdk\workspace\camera\testcam.py", line 8, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)

at xiApi.NET.xiCam.OpenDevice(Int32 DevID)

######################################################
#test script "testcam.py" #1 modified for ironpython, test script #2
import clr
import sys
sys.path.append("C:\\Users\\mdk\\camera\\")
clr.AddReference("xiAPI40.NET.dll")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name

###############
#console output showing the ironpython version
PS C:\Users\mdk\workspace\camera> ipy.exe
IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.17929
Type "help", "copyright", "credits" or "license" for more information.
##############
#running test script #2 with ironpython, console output
MQ013MG-E2
Daniel Krause
2013-01-16 19:49:08 UTC
Permalink
Hi Brett,

to check your suggestion I added a print statement to the script (after
clr.AddReference("xiAPI40.NET"):

print sys.path

The result looks ok to me:

['C:\\Users\\mdk\\workspace\\camera\\',
'C:\\Python27\\lib\\site-packages\\distribute-
0.6.21-py2.7.egg', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib',
'C:\\Python27\\lib
\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27',
'C:\\Python27\\lib\\si
te-packages',
'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-inf
o',
'C:\\Users\\mdk\\.eclipse\\org.eclipse.platform_4.2.0_248562372\\plugins\\or
g.python.pydev_2.7.1.2012100913\\pysrc\\pydev_sitecustomize',
'C:\\Windows\\syst
em32\\python27.zip', 'C:\\Python27\\lib\\site-packages\\PIL',
'C:\\Python27\\lib
\\plat-win',
'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info
', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info',
'C:\\Wi
ndows\\Microsoft.NET\\Framework64\\v4.0.30319\\']

I also copied the folder to a temp folder and run the script from there
without adding the new path explicitly to the python path.

The new location is then automatically added to the path, and the console
output looks the similar.

C:\temp\camera> python.exe .\testcam.py
['C:\\temp\\camera',
'C:\\Python27\\lib\\site-packages\\distribute-0.6.21-py2.7.egg',
'C:\\Windows\\system32\\python27.z
ip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python2
7', 'C:\\Python27\\lib\\site-packages',
'C:\\Python27\\lib\\site-packages\\PIL',
'C:\\Python27\\lib\\site-packages\\setu
ptools-0.6c11-py2.7.egg-info',
'C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\',
'C:\\Users\\mdk\\workspace\\camera\\']
Traceback (most recent call last):
File ".\testcam.py", line 9, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)
at xiApi.NET.xiCam.OpenDevice(Int32 DevID)

Best regards
Daniel
You might try making and swapping in a simple assembly that opens a
command prompt so that you can inspect the environment variables. For me,
this is almost always a system path / current directory issue. Hopefully
I’m not leading you down a false road.****
** **
*Sent:* Tuesday, January 15, 2013 1:44 PM
*To:* Tribble, Brett
System.ApplicationException: Error 1: OpenDevice: Invalid handle****
** **
No, I don't have the source, only the dll.****
** **
But thanks for the sugggestion.****
Daniel****
** **
I assume you don’t have the source to the .dll?****
****
If you do, you can add a line to use debug the error using
System.Diagnostics.Debugger.Break():****
****
http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx
****
****
****
****
*From:* PythonDotNet [mailto:pythondotnet-bounces+btribble=
*Sent:* Tuesday, January 15, 2013 12:42 PM
System.ApplicationException: Error 1: OpenDevice: Invalid handle****
****
I am trying to use a dll to control a camera.****
It is possible for me to use the dll with ironpython, but I fail to use it
with python for .NET (CLR 4.0).****
(And I would like to use e.g. numpy as well, so I need python for .NET).**
**
****
Below follow a short test script, the python / ironpython versions and
their console output when running the test script.****
****
Any hints are welcome.****
Thank you****
Daniel****
****
########################################################****
#test script "testcam.py" #1 for python for .NET****
import clr****
import sys****
sys.path.append("C:\\Users\\mdk\\workspace\\camera\\")****
clr.AddReference("xiAPI40.NET")****
from xiApi.NET import *****
cam = xiCam()****
cam.OpenDevice(0)****
print cam.GetParamString(PRM.DEVICE_NAME) #print device name****
****
###############****
#console output showing the python version, ****
#installed is .NET-support with
pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe on Win7 64bit****
PS C:\Users\mdk\workspace\camera> python.exe****
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]
on win32****
Type "help", "copyright", "credits" or "license" for more information.****
****
****
###############****
#running test script #1 with python, console output****
Traceback (most recent call last):****
File "C:\Users\mdk\workspace\camera\testcam.py", line 8, in <module>****
cam.OpenDevice(0)****
System.ApplicationException: Error 1: OpenDevice: Invalid handle****
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)****
****
at xiApi.NET.xiCam.OpenDevice(Int32 DevID)****
****
######################################################****
#test script "testcam.py" #1 modified for ironpython, test script #2****
import clr****
import sys****
sys.path.append("C:\\Users\\mdk\\camera\\")****
clr.AddReference("xiAPI40.NET.dll")****
from xiApi.NET import *****
cam = xiCam()****
cam.OpenDevice(0) ****
print cam.GetParamString(PRM.DEVICE_NAME) #print device name****
****
###############****
#console output showing the ironpython version****
PS C:\Users\mdk\workspace\camera> ipy.exe****
IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.17929****
Type "help", "copyright", "credits" or "license" for more information.****
****
****
##############****
#running test script #2 with ironpython, console output****
MQ013MG-E2****
** **
Bradley Friedman
2013-01-16 21:21:09 UTC
Permalink
The invalid handle suggests you're already inside windows land when it excepts. Your python and .net are both 64 bit. What about the dll you are importing? There are ways to make .net incompatible between bitnesses. When you run in iron python, is it running 32 bit or 64 bit? Best verify bitness across your control fully, just to rule it out.

Sent from my iPad
Post by Daniel Krause
Hi Brett,
print sys.path
['C:\\Users\\mdk\\workspace\\camera\\', 'C:\\Python27\\lib\\site-packages\\distribute-
0.6.21-py2.7.egg', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib
\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\si
te-packages', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-inf
o', 'C:\\Users\\mdk\\.eclipse\\org.eclipse.platform_4.2.0_248562372\\plugins\\or
g.python.pydev_2.7.1.2012100913\\pysrc\\pydev_sitecustomize', 'C:\\Windows\\syst
em32\\python27.zip', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib
\\plat-win', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info
', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info', 'C:\\Wi
ndows\\Microsoft.NET\\Framework64\\v4.0.30319\\']
I also copied the folder to a temp folder and run the script from there without adding the new path explicitly to the python path.
The new location is then automatically added to the path, and the console output looks the similar.
C:\temp\camera> python.exe .\testcam.py
['C:\\temp\\camera', 'C:\\Python27\\lib\\site-packages\\distribute-0.6.21-py2.7.egg', 'C:\\Windows\\system32\\python27.z
ip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python2
7', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\setu
ptools-0.6c11-py2.7.egg-info', 'C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\', 'C:\\Users\\mdk\\workspace\\camera\\']
File ".\testcam.py", line 9, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)
at xiApi.NET.xiCam.OpenDevice(Int32 DevID)
Best regards
Daniel
You might try making and swapping in a simple assembly that opens a command prompt so that you can inspect the environment variables. For me, this is almost always a system path / current directory issue. Hopefully I’m not leading you down a false road.
Sent: Tuesday, January 15, 2013 1:44 PM
To: Tribble, Brett
Subject: Re: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle
No, I don't have the source, only the dll.
But thanks for the sugggestion.
Daniel
I assume you don’t have the source to the .dll?
http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx
Sent: Tuesday, January 15, 2013 12:42 PM
Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle
I am trying to use a dll to control a camera.
It is possible for me to use the dll with ironpython, but I fail to use it with python for .NET (CLR 4.0).
(And I would like to use e.g. numpy as well, so I need python for .NET).
Below follow a short test script, the python / ironpython versions and their console output when running the test script.
Any hints are welcome.
Thank you
Daniel
########################################################
#test script "testcam.py" #1 for python for .NET
import clr
import sys
sys.path.append("C:\\Users\\mdk\\workspace\\camera\\")
clr.AddReference("xiAPI40.NET")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name
###############
#console output showing the python version,
#installed is .NET-support with pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe on Win7 64bit
PS C:\Users\mdk\workspace\camera> python.exe
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
###############
#running test script #1 with python, console output
File "C:\Users\mdk\workspace\camera\testcam.py", line 8, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)
at xiApi.NET.xiCam.OpenDevice(Int32 DevID)
######################################################
#test script "testcam.py" #1 modified for ironpython, test script #2
import clr
import sys
sys.path.append("C:\\Users\\mdk\\camera\\")
clr.AddReference("xiAPI40.NET.dll")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name
###############
#console output showing the ironpython version
PS C:\Users\mdk\workspace\camera> ipy.exe
IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.17929
Type "help", "copyright", "credits" or "license" for more information.
##############
#running test script #2 with ironpython, console output
MQ013MG-E2
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
Daniel Krause
2013-01-17 17:54:13 UTC
Permalink
Hi Bradley,

the hint concerning the 32 or 64 bit did it.

When I use the 64bit.dll with python for .NET it is working. And with iron
python it is the 32bit.dll ...

Thanks a lot
Daniel
Post by Bradley Friedman
The invalid handle suggests you're already inside windows land when it
excepts. Your python and .net are both 64 bit. What about the dll you are
importing? There are ways to make .net incompatible between bitnesses.
When you run in iron python, is it running 32 bit or 64 bit? Best verify
bitness across your control fully, just to rule it out.
Sent from my iPad
Hi Brett,
to check your suggestion I added a print statement to the script (after
print sys.path
['C:\\Users\\mdk\\workspace\\camera\\',
'C:\\Python27\\lib\\site-packages\\distribute-
0.6.21-py2.7.egg', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib',
'C:\\Python27\\lib
\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27',
'C:\\Python27\\lib\\si
te-packages',
'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-inf
o',
'C:\\Users\\mdk\\.eclipse\\org.eclipse.platform_4.2.0_248562372\\plugins\\or
g.python.pydev_2.7.1.2012100913\\pysrc\\pydev_sitecustomize',
'C:\\Windows\\syst
em32\\python27.zip', 'C:\\Python27\\lib\\site-packages\\PIL',
'C:\\Python27\\lib
\\plat-win',
'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info
', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info', 'C:\\Wi
ndows\\Microsoft.NET\\Framework64\\v4.0.30319\\']
I also copied the folder to a temp folder and run the script from there
without adding the new path explicitly to the python path.
The new location is then automatically added to the path, and the console
output looks the similar.
C:\temp\camera> python.exe .\testcam.py
['C:\\temp\\camera',
'C:\\Python27\\lib\\site-packages\\distribute-0.6.21-py2.7.egg',
'C:\\Windows\\system32\\python27.z
ip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python2
7', 'C:\\Python27\\lib\\site-packages',
'C:\\Python27\\lib\\site-packages\\PIL',
'C:\\Python27\\lib\\site-packages\\setu
ptools-0.6c11-py2.7.egg-info', 'C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\',
'C:\\Users\\mdk\\workspace\\camera\\']
File ".\testcam.py", line 9, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)
at xiApi.NET.xiCam.OpenDevice(Int32 DevID)
Best regards
Daniel
You might try making and swapping in a simple assembly that opens a
command prompt so that you can inspect the environment variables. For me,
this is almost always a system path / current directory issue. Hopefully
I’m not leading you down a false road.****
** **
*Sent:* Tuesday, January 15, 2013 1:44 PM
*To:* Tribble, Brett
System.ApplicationException: Error 1: OpenDevice: Invalid handle****
** **
No, I don't have the source, only the dll.****
** **
But thanks for the sugggestion.****
Daniel****
** **
I assume you don’t have the source to the .dll?****
****
If you do, you can add a line to use debug the error using
System.Diagnostics.Debugger.Break():****
****
http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx
****
****
****
****
*From:* PythonDotNet [mailto:pythondotnet-bounces+btribble=
*Sent:* Tuesday, January 15, 2013 12:42 PM
System.ApplicationException: Error 1: OpenDevice: Invalid handle****
****
I am trying to use a dll to control a camera.****
It is possible for me to use the dll with ironpython, but I fail to use
it with python for .NET (CLR 4.0).****
(And I would like to use e.g. numpy as well, so I need python for .NET).*
***
****
Below follow a short test script, the python / ironpython versions and
their console output when running the test script.****
****
Any hints are welcome.****
Thank you****
Daniel****
****
########################################################****
#test script "testcam.py" #1 for python for .NET****
import clr****
import sys****
sys.path.append("C:\\Users\\mdk\\workspace\\camera\\")****
clr.AddReference("xiAPI40.NET")****
from xiApi.NET import *****
cam = xiCam()****
cam.OpenDevice(0)****
print cam.GetParamString(PRM.DEVICE_NAME) #print device name****
****
###############****
#console output showing the python version, ****
#installed is .NET-support with
pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe on Win7 64bit****
PS C:\Users\mdk\workspace\camera> python.exe****
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]
on win32****
Type "help", "copyright", "credits" or "license" for more information.***
*
****
****
###############****
#running test script #1 with python, console output****
Traceback (most recent call last):****
File "C:\Users\mdk\workspace\camera\testcam.py", line 8, in <module>***
*
cam.OpenDevice(0)****
System.ApplicationException: Error 1: OpenDevice: Invalid handle****
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)****
****
at xiApi.NET.xiCam.OpenDevice(Int32 DevID)****
****
######################################################****
#test script "testcam.py" #1 modified for ironpython, test script #2****
import clr****
import sys****
sys.path.append("C:\\Users\\mdk\\camera\\")****
clr.AddReference("xiAPI40.NET.dll")****
from xiApi.NET import *****
cam = xiCam()****
cam.OpenDevice(0) ****
print cam.GetParamString(PRM.DEVICE_NAME) #print device name****
****
###############****
#console output showing the ironpython version****
PS C:\Users\mdk\workspace\camera> ipy.exe****
IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.17929****
Type "help", "copyright", "credits" or "license" for more information.***
*
****
****
##############****
#running test script #2 with ironpython, console output****
MQ013MG-E2****
** **
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
Tribble, Brett
2013-01-16 21:40:42 UTC
Permalink
How does it differ from the working ironpython environment?

From: PythonDotNet [mailto:pythondotnet-bounces+btribble=ea.com-+ZN9ApsXKcFQFI55V6+***@public.gmane.orgg] On Behalf Of Daniel Krause
Sent: Wednesday, January 16, 2013 11:49 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: Re: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle

Hi Brett,

to check your suggestion I added a print statement to the script (after clr.AddReference("xiAPI40.NET"):

print sys.path

The result looks ok to me:

['C:\\Users\\mdk\\workspace\\camera\\', 'C:\\Python27\\lib\\site-packages\\distribute-
0.6.21-py2.7.egg', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib
\\plat-win<file:///\\plat-win>', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\si
te-packages', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-inf
o', 'C:\\Users\\mdk\\.eclipse\\org.eclipse.platform_4.2.0_248562372\\plugins\\or
g.python.pydev_2.7.1.2012100913\\pysrc\\pydev_sitecustomize', 'C:\\Windows\\syst
em32\\python27.zip', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib
\\plat-win<file:///\\plat-win>', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info
', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info', 'C:\\Wi
ndows\\Microsoft.NET\\Framework64\\v4.0.30319\\']

I also copied the folder to a temp folder and run the script from there without adding the new path explicitly to the python path.

The new location is then automatically added to the path, and the console output looks the similar.

C:\temp\camera> python.exe .\testcam.py
['C:\\temp\\camera', 'C:\\Python27\\lib\\site-packages\\distribute-0.6.21-py2.7.egg', 'C:\\Windows\\system32\\python27.z
ip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python2
7', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\setu
ptools-0.6c11-py2.7.egg-info', 'C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\', 'C:\\Users\\mdk\\workspace\\camera\\']
Traceback (most recent call last):
File ".\testcam.py", line 9, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)
at xiApi.NET.xiCam.OpenDevice(Int32 DevID)

Best regards
Daniel
2013/1/15 Tribble, Brett <btribble-***@public.gmane.org<mailto:btribble-***@public.gmane.org>>
You might try making and swapping in a simple assembly that opens a command prompt so that you can inspect the environment variables. For me, this is almost always a system path / current directory issue. Hopefully I'm not leading you down a false road.

From: m.daniel.krause-gM/Ye1E23mwN+***@public.gmane.org<mailto:m.daniel.krause-gM/Ye1E23mwN+***@public.gmane.org> [mailto:m.daniel.krause-gM/Ye1E23mwN+***@public.gmane.org<mailto:***@googlemail.com>] On Behalf Of Daniel Krause
Sent: Tuesday, January 15, 2013 1:44 PM
To: Tribble, Brett
Subject: Re: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle

No, I don't have the source, only the dll.

But thanks for the sugggestion.
Daniel

2013/1/15 Tribble, Brett <btribble-***@public.gmane.org<mailto:btribble-***@public.gmane.org>>
I assume you don't have the source to the .dll?

If you do, you can add a line to use debug the error using System.Diagnostics.Debugger.Break():

http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx



From: PythonDotNet [mailto:pythondotnet-bounces+btribble<mailto:pythondotnet-bounces%2Bbtribble>=ea.com-+ZN9ApsXKcEdnm+***@public.gmane.org<mailto:ea.com-+ZN9ApsXKcEdnm+***@public.gmane.org>] On Behalf Of Daniel Krause
Sent: Tuesday, January 15, 2013 12:42 PM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org<mailto:pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org>
Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle

I am trying to use a dll to control a camera.
It is possible for me to use the dll with ironpython, but I fail to use it with python for .NET (CLR 4.0).
(And I would like to use e.g. numpy as well, so I need python for .NET).

Below follow a short test script, the python / ironpython versions and their console output when running the test script.

Any hints are welcome.
Thank you
Daniel

########################################################
#test script "testcam.py" #1 for python for .NET
import clr
import sys
sys.path.append("C:\\Users\\mdk\\workspace\\camera\\")
clr.AddReference("xiAPI40.NET")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name

###############
#console output showing the python version,
#installed is .NET-support with pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe on Win7 64bit
PS C:\Users\mdk\workspace\camera> python.exe
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.


###############
#running test script #1 with python, console output
Traceback (most recent call last):
File "C:\Users\mdk\workspace\camera\testcam.py", line 8, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)

at xiApi.NET.xiCam.OpenDevice(Int32 DevID)

######################################################
#test script "testcam.py" #1 modified for ironpython, test script #2
import clr
import sys
sys.path.append("C:\\Users\\mdk\\camera\\")
clr.AddReference("xiAPI40.NET.dll")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name

###############
#console output showing the ironpython version
PS C:\Users\mdk\workspace\camera> ipy.exe
IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.17929
Type "help", "copyright", "credits" or "license" for more information.
##############
#running test script #2 with ironpython, console output
MQ013MG-E2
Daniel Krause
2013-01-14 19:55:06 UTC
Permalink
I am trying to use a dll to control a camera.
It is possible to use the dll with ironpython, but I fail to use it with
python for .NET (CLR 4.0).
(And I would like to use numpy as well, so I need python for .NET).

Below follow a short test script, the python / ironpython versions and
their console output when running the test script.

Any hints are welcome.
Thank you
Daniel

########################################################
#test script "testcam.py" #1 for python for .NET
import clr
import sys
sys.path.append("C:\\Users\\mdk\\workspace\\camera\\")
clr.AddReference("xiAPI40.NET")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name

###############
#console output showing the python version,
#installed is .NET-support with pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe
on Win7 64bit
PS C:\Users\mdk\workspace\camera> python.exe
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.


###############
#running test script #1 with python, console output
Traceback (most recent call last):
File "C:\Users\mdk\workspace\camera\testcam.py", line 8, in <module>
cam.OpenDevice(0)
System.ApplicationException: Error 1: OpenDevice: Invalid handle
at xiApi.NET.xiCam.throwException(Int32 errNum, String param)

at xiApi.NET.xiCam.OpenDevice(Int32 DevID)

######################################################
#test script "testcam.py" #1 modified for ironpython, test script #2
import clr
import sys
sys.path.append("C:\\Users\\mdk\\camera\\")
clr.AddReference("xiAPI40.NET.dll")
from xiApi.NET import *
cam = xiCam()
cam.OpenDevice(0)
print cam.GetParamString(PRM.DEVICE_NAME) #print device name

###############
#console output showing the ironpython version
PS C:\Users\mdk\workspace\camera> ipy.exe
IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.17929
Type "help", "copyright", "credits" or "license" for more information.
##############
#running test script #2 with ironpython, console output
MQ013MG-E2
Barton
2013-01-20 07:35:02 UTC
Permalink
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet

Loading...