From aloter at gmail.com Thu Mar 9 11:33:42 2017 From: aloter at gmail.com (Aloter One) Date: Thu, 9 Mar 2017 11:33:42 -0500 Subject: [Python.NET] Sending a buffer (pointer?) to a C# function Message-ID: 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! -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.d.lloyd at gmail.com Thu Mar 9 13:46:51 2017 From: brian.d.lloyd at gmail.com (Brian Lloyd) Date: Thu, 09 Mar 2017 13:46:51 -0500 Subject: [Python.NET] Sending a buffer (pointer?) to a C# function In-Reply-To: References: Message-ID: 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" 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 at python.org >https://mail.python.org/mailman/listinfo/pythondotnet From denis.akhiyarov at gmail.com Thu Mar 9 13:46:55 2017 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Thu, 09 Mar 2017 18:46:55 +0000 Subject: [Python.NET] Sending a buffer (pointer?) to a C# function In-Reply-To: References: Message-ID: 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 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 at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Thu Mar 16 05:18:48 2017 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Thu, 16 Mar 2017 04:18:48 -0500 Subject: [Python.NET] pythonnet (Python.NET) version 2.3.0 released! Message-ID: pythonnet (Python.NET) version 2.3.0 released! https://github.com/pythonnet/pythonnet/wiki/Installation *Release notes:* Added - Added Code Coverage (#345 ) - Added PySys_SetArgvEx (#347 ) - Added XML Documentation (#349 ) - Added Embedded_Tests on AppVeyor (#224 )(#353 ) - Added Embedded_Tests on Travis (#224 )(#391 ) - Added PY3 settings to solution configuration-manager (#346 ) - Added Slack (#384 )( #383 )(#386 ) - Added function of passing an arbitrary .NET object as the value of an attribute of PyObject (#370 )(#373 ) - Added Coverity scan (#390 ) - Added bumpversion for version control (#319 )(#398 ) - Added tox for local testing (#345 ) - Added requirements.txt - Added to PythonEngine methods Eval and Exec (#389 ) - Added implementations of ICustomMarshal (#407 ) - Added docker images (#322 ) - Added hooks in pyinstaller and cx_freeze for pythonnet (#66 ) - Added nuget packages (#165 ) Changed - Refactored python unittests (#329 ) - Refactored python setup.py (#337 ) - Refactored remaining of Build Directives on runtime.cs (#339 ) - Refactored Embedded_Tests to make easier to write tests (#369 ) - Changed unittests to pytest (#368 ) - Upgraded NUnit framework from 2.6.3 to 3.5.0 (#341 ) - Downgraded NUnit framework from 3.5.0 to 2.6.4 (#353 ) - Upgraded NUnit framework from 2.6.4 to 3.6.0 (#371 ) - Unfroze Mono version on Travis (#345 ) - Changed conda.recipe build to only pull-requests (#345 ) - Combine Py_DEBUG and PYTHON_WITH_PYDEBUG flags (#362 ) Deprecated - Deprecated RunString (#401 ) Fixed - Fixed crash during Initialization (#262 )(#343 ) - Fixed crash during Shutdown (#365 ) - Fixed multiple build warnings - Fixed method signature match for Object Type (#203 )(#377 ) - Fixed outdated version number in AssemblyInfo (#398 ) - Fixed wrong version number in conda.recipe (#398 ) - Fixed fixture location for Python tests and Embedded_Tests - Fixed PythonException crash during Shutdown (#400 ) - Fixed AppDomain unload during GC (#397 )(#400 ) - Fixed Py_Main & PySys_SetArgvEx no mem error on UCS4/PY3 (#399 ) - Fixed Python.Runtime.dll.config on macOS (#120 ) - Fixed crash on PythonEngine.Version (#413 ) - Fixed PythonEngine.PythonPath issues (#179 )(#414 )(#415 ) Removed - Removed six dependency for unittests (#329 ) - Removed Mono.Unix dependency for UCS4 (#360 ) - Removed need for Python.Runtime.dll.config - Removed PY32 build option PYTHON_WITH_WIDE_UNICODE (#417 ) -------------- next part -------------- An HTML attachment was scrubbed... URL: