[CentralOH] PythonDotNet

Thomas Winningham winningham at gmail.com
Mon Feb 23 20:45:56 CET 2015


So I re-read your email, and my reply, and noticed I missed a subtlety,
you're trying to get a Python.NET callback to work with a .NET function.
This may not work unless the Python.NET allows you to override or somehow
annotate a function's accepted types. The "method signature" in Java
parlance means that whatever you write in Python is not going to appear
like a valid callback method, as the parameters may be of a different type
than what the callback allows. There *ought* to be a way to make a Python
function that appears to the .NET CLR as having this method signature, but
I'm not sure.

I guess the same advice applies, but if what I described above doesn't
exist, you may be in the C# world more if you can't find a way to
explicitly define the Python function's parameter types. Essentially, write
C# that can call your Python function, but that C# has to require
parameters with the types aligned with the original callback.

On Sun, Feb 22, 2015 at 7:56 PM, Thomas Winningham <winningham at gmail.com>
wrote:

> I had been thinking about this, and while I haven't messed with Python on
> .NET, I have messed with C# some, as well as other Python on top of another
> language type arrangements.
>
> There must be either one of two things you can do, but the details of
> which you may be on your own to investigate (sorry):
>
> 1. The Python.NET, being dynamically typed, must have some sort of
> functions to support the static (and more specific) types of the .NET
> system. This may be something that allows you to specifically create a C#
> compatible array of unsigned shorts like that second parameter of the
> function requires. I would imagine a study of the documentation for
> Python.NET may well reveal some kind of capability like this as a language
> support library or something similar. I know with say, Jython, it is called
> Java Interop, same with Clojure on the JVM.
>
> 2. You could approach this the other way, and write some C# to wrap this
> function in a function that does work with Python the way you want or
> however you can get it to work, then in this new C# function, coerce the
> types passed in to be an array of unsigned shorts, and pass that to the
> original function.
>
> Best of luck, and let us know if you find anything interesting.
>
> Thomas
>
>
> On Sat, Feb 21, 2015 at 10:10 PM, Mark Erbaugh <mark at microenh.com> wrote:
>
>> Greetings,
>>
>> I am struggling with a hobby project using PythonDotNet.  I have an API
>> for an external device written in C# and .NET.  I have the C# code. Rather
>> than using IronPython, I am trying to use PythonDotNet with CPython 2.7.9.
>> The C# code was not written with any special consideration of Python.
>>
>> The API implements callback functions. I have been able to write several
>> of the callback functions in Python and they work. But, now I've come
>> across something that I can't figure out, and perhaps it's not supported by
>> PythonDotNet. There is a callback routine that passes a C# array of
>> shorts.  the C# function signature is
>>
>>         public delegate void DataReadyEventHandler(Panadapter pan,
>> ushort[] data);
>>
>> No matter how I try to code my Python function, I am getting a runtime
>> exception from the PythonRuntime part of PythonDotNet.
>>
>> Is passing this array possible?
>>
>> Thanks,
>> Mark
>> _______________________________________________
>> CentralOH mailing list
>> CentralOH at python.org
>> https://mail.python.org/mailman/listinfo/centraloh
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20150223/5ab86d1f/attachment-0001.html>


More information about the CentralOH mailing list