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

Daniel Krause krausda at gmx.de
Thu Jan 17 18:54:13 CET 2013


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


2013/1/16 Bradley Friedman <brad at fie.us>

> 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
>
> On Jan 16, 2013, at 3:49 PM, Daniel Krause <krausda at gmx.de> wrote:
>
> 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
>
> 2013/1/15 Tribble, Brett <btribble at ea.com>
>
>> 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 at googlemail.com [mailto:
>> m.daniel.krause at 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 at ea.com>****
>>
>> 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 at python.org] *On Behalf Of *Daniel Krause
>> *Sent:* Tuesday, January 15, 2013 12:42 PM
>> *To:* pythondotnet at 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 at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20130117/3f821650/attachment-0001.html>


More information about the PythonDotNet mailing list