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....@python.org] On 
Behalf Of Daniel Krause
Sent: Tuesday, January 15, 2013 12:42 PM
To: pythondotnet@python.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
_________________________________________________
Python.NET mailing list - PythonDotNet@python.org
http://mail.python.org/mailman/listinfo/pythondotnet

Reply via email to