Sending a buffer (pointer?) to a C# function

From their documentation it seems I need to send the following to grab a
Hello, I'm trying to use pythondotnet to communicate with a camera (from Xenics), it has a C# wrapper. frame: XCamera::GetFrame ( FrameType *type*, unsigned long *ulFlags*, void * *buffer*, unsigned int *size* ) In their C# example they create the buffer by: UInt32 frameSize = camera.FrameSize; frameBuffer = new ushort[frameSize / 2]; and call the function: GetFrame(FrameType.Native, XGetFrameFlags.Blocking, frameBuffer, frameSize); I've tried to emulate it by creating the buffer in python: frameSize = np.uint32(camera.FrameSize) frameBuffer = np.empty([int(frameSize/2), 1], dtype=np.ushort) However when I try to call the function (camera is an XCamera object from their dll, FrameType and XGetFlags are defined in their dll also. camera.GetFrame(FrameType.Native, XGetFrameFlags.Blocking, frameBuffer, frameSize) I get an error I'm not sending the right variables to the function: "TypeError: No method matches given arguments" Do I need to send the actual buffer pointer to the function? How to implement it in pythondotnet? Thank you!

Its been a while, but I think what you will need to do is create a GCHandle on your buffer to pin it, then call GCHandle.AddrOfPinnedObject(buffer) and pass the resulting IntPtr as the void * argument. On 3/9/17, 11:33 AM, "PythonDotNet on behalf of Aloter One" <pythondotnet-bounces+brian.d.lloyd=gmail.com@python.org on behalf of aloter@gmail.com> wrote:
Hello, I'm trying to use pythondotnet to communicate with a camera (from Xenics), it has a C# wrapper.
From their documentation it seems I need to send the following to grab a frame:
XCamera::GetFrame (FrameType type, unsigned long ulFlags, void * buffer, unsigned int size ) In their C# example they create the buffer by: UInt32 frameSize = camera.FrameSize; frameBuffer = new ushort[frameSize / 2];
and call the function: GetFrame(FrameType.Native, XGetFrameFlags.Blocking, frameBuffer, frameSize); I've tried to emulate it by creating the buffer in python:
frameSize = np.uint32(camera.FrameSize) frameBuffer = np.empty([int(frameSize/2), 1], dtype=np.ushort)
However when I try to call the function (camera is an XCamera object from their dll, FrameType and XGetFlags are defined in their dll also.
camera.GetFrame(FrameType.Native, XGetFrameFlags.Blocking, frameBuffer, frameSize)
I get an error I'm not sending the right variables to the function:
"TypeError: No method matches given arguments"
Do I need to send the actual buffer pointer to the function? How to implement it in pythondotnet?
Thank you!
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org https://mail.python.org/mailman/listinfo/pythondotnet

Can you open an issue on github.com/pythonnet/pythonnet? Please report your environment, such OS, versions of Python, .NET, pythonnet. You are trying to pass numpy array to .NET method that only accepts `ushort[frameSize / 2]`. Try creating the same .NET array from pythonnet and passing it instead. On Thu, Mar 9, 2017, 12:33 PM Aloter One <aloter@gmail.com> wrote:
Hello,
I'm trying to use pythondotnet to communicate with a camera (from Xenics), it has a C# wrapper.
From their documentation it seems I need to send the following to grab a frame:
XCamera::GetFrame ( FrameType *type*, unsigned long *ulFlags*, void * *buffer*, unsigned int *size* ) In their C# example they create the buffer by: UInt32 frameSize = camera.FrameSize; frameBuffer = new ushort[frameSize / 2]; and call the function: GetFrame(FrameType.Native, XGetFrameFlags.Blocking, frameBuffer, frameSize);
I've tried to emulate it by creating the buffer in python:
frameSize = np.uint32(camera.FrameSize) frameBuffer = np.empty([int(frameSize/2), 1], dtype=np.ushort)
However when I try to call the function (camera is an XCamera object from their dll, FrameType and XGetFlags are defined in their dll also.
camera.GetFrame(FrameType.Native, XGetFrameFlags.Blocking, frameBuffer, frameSize)
I get an error I'm not sending the right variables to the function:
"TypeError: No method matches given arguments"
Do I need to send the actual buffer pointer to the function? How to implement it in pythondotnet?
Thank you! _________________________________________________ Python.NET mailing list - PythonDotNet@python.org https://mail.python.org/mailman/listinfo/pythondotnet
participants (3)
-
Aloter One
-
Brian Lloyd
-
Denis Akhiyarov