My personal solution would be to wrap the camera code in a very thin assembly 
that manages this stuff and provides a clean interface for python.net to hook 
into. I'm lazy that way though...

From: PythonDotNet [mailto:pythondotnet-bounces+btribble=ea....@python.org] On 
Behalf Of Daniel Krause
Sent: Tuesday, January 22, 2013 10:08 PM
To: pythondotnet@python.org
Subject: Re: [Python.NET] Problem with System.ArgumentException in call to 
method from dll

@Brett

When I try

bitmapsrc = BitmapSource()

I get the following error:

Traceback (most recent call last):
  File "C:\Users\mdk\workspace\\camera\testbitmap.py", line 8, in <module>
    bitmapsrc = BitmapSource()
TypeError: cannot instantiate abstract class

I will have a look at System.Reflection, thanks for the hint.

@Brad
The documentation does not say anything about "safe" or "unsafe". I do not have 
the source for the dll, only for the examples shipped with the dll. If you 
would like to have a look at them, I could send them to you.


Daniel

2013/1/23 b...@fie.us<mailto:b...@fie.us> <b...@fie.us<mailto:b...@fie.us>>
Just to clarify: neither version of the methods you are calling are marked 
"unsafe" in the proper c# .net manner are they?  I would not be surprised to 
find PythonNet not providing access to "unsafe" methods.  I would need to take 
a trip through the source to verify.

On Jan 22, 2013, at 4:10 PM, Daniel Krause 
<m.daniel.kra...@googlemail.com<mailto:m.daniel.kra...@googlemail.com>> wrote:


That is right, I want to get the value of the output parameter.

The following variant looks much more logical to me, but than I get another 
error:
bitmapsrc = cam.GetImage(timeout)
TypeError: No method matches given arguments

So it seems that I have to pass the "out"-parameter to the method as well, but 
that was not working either.


2013/1/22 b...@fie.us<mailto:b...@fie.us> <b...@fie.us<mailto:b...@fie.us>>
You are setting the bitmapsrc variable to be equal to the class BitmapSource.  
I assume you mean to get the value of an output parameter, rather than pass a 
class object into the method.

Though I do not speak german.  But I think that's it.

On Jan 22, 2013, at 2:58 PM, Daniel Krause 
<m.daniel.kra...@googlemail.com<mailto:m.daniel.kra...@googlemail.com>> wrote:

> I want to use a method from an API to control a camera (xiApi.NETX64.dll).
>
> The method is described in two ways:
> //
> void GetImage( out WriteableBitmap image, int timeout)
> Description : This function acquires image and returns fills WritableBitmap 
> object. Supports UNSAFE buffer policy mode.
> Parameters :
> out WriteableBitmap image : WPF BitmapSource to be filled.
> int timeout : Time interval required to wait for the image (in milliseconds).
> //
> void GetImage(WriteableBitmap image, int timeout)
> Description : This function acquires image and returns fills WritableBitmap 
> object. Supports SAFE buffer policy mode.
> Parameters :
> WriteableBitmap image : WPF BitmapSource to be filled.
> int timeout : Time interval required to wait for the image (in milliseconds).
> //
>
> The code in a c#-sample looks like this (I skipped the initialisation of 
> myCam, but if it helps I can provide the complete code):
> //
> using System.Windows.Media.Imaging;
> int timeout = 10000;
> BitmapSource myBitmapSrc;
> myCam.GetImage(out myBitmapSrc, timeout);
> //
> This code I can compile, and it is working.
>
> I tried to keep the python code as close as possible, but I get errors I do 
> not understand:
> ##
> import clr
> import sys
> sys.path.append("C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\WPF")
> clr.AddReference("PresentationCore")
> clr.AddReference("xiAPI.NETX64")
> from xiApi.NET<http://xiApi.NET> import *
> from System.Windows.Media.Imaging import BitmapSource
> bitmapsrc = BitmapSource
> print bitmapsrc
> cam = xiCam()
> cam.OpenDevice(0)
> cam.SetParam(PRM.BUFFER_POLICY, BUFF_POLICY.SAFE)
> cam.SetParam(PRM.IMAGE_DATA_FORMAT,  IMG_FORMAT.MONO8)
> cam.StartAcquisition()
> timeout = 1000
> bitmapsrc = cam.GetImage(bitmapsrc, timeout)
> cam.StopAcquisition()
> ##
>
> Console output:
> <class 'System.Windows.Media.Imaging.BitmapSource'>
> Traceback (most recent call last):
>   File "C:\Users\mdk\workspace\camera\testbitmap.py",
> line 17, in <module>
>     bitmapsrc = cam.GetImage(bitmapsrc, timeout)
> System.ArgumentException: Das Objekt mit dem Typ "System.RuntimeType" kann 
> nicht
>  in den Typ "System.Drawing.Bitmap&" konvertiert werden.
>    bei System.RuntimeType.TryChangeType(Object value, Binder binder, 
> CultureInfo
>  culture, Boolean needsSpecialCast)
>
>    bei System.Reflection.MethodBase.CheckArguments(Object[] parameters, 
> Binder b
> inder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
>
>    bei System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, 
> Bind
> ingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
>
>    bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags 
> invok
> eAttr, Binder binder, Object[] parameters, CultureInfo culture)
>
>    bei Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr 
> kw, M
> ethodBase info, MethodInfo[] methodinfo)
> _________________________________________________
> Python.NET<http://Python.NET> mailing list - 
> PythonDotNet@python.org<mailto:PythonDotNet@python.org>
> http://mail.python.org/mailman/listinfo/pythondotnet

_________________________________________________
Python.NET<http://Python.NET> mailing list - 
PythonDotNet@python.org<mailto:PythonDotNet@python.org>
http://mail.python.org/mailman/listinfo/pythondotnet


_________________________________________________
Python.NET mailing list - PythonDotNet@python.org
http://mail.python.org/mailman/listinfo/pythondotnet

Reply via email to