[Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle

Daniel Krause krausda at gmx.de
Mon Jan 14 20:55:06 CET 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20130114/d32eae53/attachment.html>


More information about the PythonDotNet mailing list