From helink at sandia.gov Wed Jan 2 18:35:54 2013 From: helink at sandia.gov (Link, Hamilton) Date: Wed, 2 Jan 2013 17:35:54 +0000 Subject: [Python.NET] unsubscribe Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeff at coderforlife.com Sat Jan 5 03:33:18 2013 From: jeff at coderforlife.com (Jeffrey Bush) Date: Fri, 4 Jan 2013 18:33:18 -0800 Subject: [Python.NET] Memory Type Problems Message-ID: Hi, I have a library in C for compression. I made Python script for testing it, called using ctypes. Now, I am working on a .NET library for something very similar and would like to test it in the same way. However, I am getting lost in how to do some of the things with your library. The function I need to call looks like: public static long Compress(Memory input, Memory output) The Memory class is a wrapper around either managed byte arrays, void* (for efficiency), or memory mapped files. This allows a unified system for accessing general chunks of memory regardless if they are managed, native, or on the filesystem. They are created through static functions: public static Memory From(MemoryStream s, bool all = true)public static Memory From(byte[] b, bool readOnly = false)public static Memory From(byte[] b, long offset, long size, bool readOnly = false)public unsafe static Memory From(UnmanagedMemoryStream s, bool all = true)public unsafe static Memory From(void* b, long size, bool readOnly = false)public unsafe static Memory From(IntPtr b, long size, bool readOnly = false)public static Memory FromFile(string file, bool readOnly = false)public static Memory OfSize(long size) The only ones I can easily use are the last two (OfSize and FromFile). I have not yet figured out how to call the other ones properly. I don't seem to be able to allocate byte arrays with Array[Byte](10), it complains that 10 cannot be converted to System.Byte[] so it seems that it believes I am casting instead of creating a new array. No overloads seem to exist. So now here are my questions and the ctypes answer: - How do I construct a byte array? (ctypes.create_string_buffer) - How do I take a Python list/array and pass it as a pointer? (ctypes has this conversion happen automatically) - How do I turn a byte array into a useful Python list/array? As-is I can't use the Python-style indexers (except negative numbers). (The ctypes buffer works directly as a list, but also supports ".raw" and ".value") - How do I convert a pointer into a useful Python list/array? (ctypes casting allows this to work) Last point, although this is probably a limitation of .NET, but just to make sure. The default argument values can't be used, but it is possible that this isn't even in the assembly information and only works for source in the same module. Thanks, Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From barton at bcdesignswell.com Sat Jan 5 22:57:04 2013 From: barton at bcdesignswell.com (Barton) Date: Sat, 05 Jan 2013 13:57:04 -0800 Subject: [Python.NET] Memory Type Problems In-Reply-To: References: Message-ID: <50E8A1B0.6060202@bcdesignswell.com> An HTML attachment was scrubbed... URL: From barton at bcdesignswell.com Sat Jan 5 23:07:58 2013 From: barton at bcdesignswell.com (Barton) Date: Sat, 05 Jan 2013 14:07:58 -0800 Subject: [Python.NET] Memory Type Problems In-Reply-To: References: Message-ID: <50E8A43E.8050207@bcdesignswell.com> An HTML attachment was scrubbed... URL: From jeff at coderforlife.com Tue Jan 8 09:31:21 2013 From: jeff at coderforlife.com (Jeffrey Bush) Date: Tue, 8 Jan 2013 00:31:21 -0800 Subject: [Python.NET] Memory Type Problems In-Reply-To: <50E8A43E.8050207@bcdesignswell.com> References: <50E8A43E.8050207@bcdesignswell.com> Message-ID: How about my other questions? Pass as a pointer (like ctypes would do)? Convert that pointer back? And I don't seem to be able to get the slices (":") to work with byte arrays. Thanks for the help getting the byte arrays started though. I am able to take the output from reading a file and send it right to the array constructor: import clr from System import Array, Byte with open("file.txt", 'rb') as f: input = f.read() a = Array[Byte](input) One problem though is that equality doesn't work (a==input is False). But maybe this is because one is a list of (unsigned) bytes and one is a list of (signed) characters. a[0] and input[0] display differently. Jeff On Sat, Jan 5, 2013 at 2:07 PM, Barton wrote: > Definitely more useful: > >>> import clr > >>> from System import Array, Byte > >>> g = (0 for i in range(10)) > >>> a = Array[Byte](list(i for i in g)) > > >>> a[5] > 0 > > On 01/04/2013 06:33 PM, Jeffrey Bush wrote: > > Hi, > > I have a library in C for compression. I made Python script for testing > it, called using ctypes. > > Now, I am working on a .NET library for something very similar and would > like to test it in the same way. However, I am getting lost in how to do > some of the things with your library. > > The function I need to call looks like: > > public static long Compress(Memory input, Memory output) > > The Memory class is a wrapper around either managed byte arrays, void* > (for efficiency), or memory mapped files. This allows a unified system for > accessing general chunks of memory regardless if they are managed, native, > or on the filesystem. They are created through static functions: > > public static Memory From(MemoryStream s, bool all = true)public static Memory From(byte[] b, bool readOnly = false)public static Memory From(byte[] b, long offset, long size, bool readOnly = false)public unsafe static Memory From(UnmanagedMemoryStream s, bool all = true)public unsafe static Memory From(void* b, long size, bool readOnly = false)public unsafe static Memory From(IntPtr b, long size, bool readOnly = false)public static Memory FromFile(string file, bool readOnly = false)public static Memory OfSize(long size) > > The only ones I can easily use are the last two (OfSize and FromFile). I > have not yet figured out how to call the other ones properly. I don't seem > to be able to allocate byte arrays with Array[Byte](10), it complains that > 10 cannot be converted to System.Byte[] so it seems that it believes I am > casting instead of creating a new array. No overloads seem to exist. > > So now here are my questions and the ctypes answer: > > - How do I construct a byte array? (ctypes.create_string_buffer) > - How do I take a Python list/array and pass it as a pointer? (ctypes > has this conversion happen automatically) > - How do I turn a byte array into a useful Python list/array? As-is I > can't use the Python-style indexers (except negative numbers). (The ctypes > buffer works directly as a list, but also supports ".raw" and ".value") > - How do I convert a pointer into a useful Python list/array? (ctypes > casting allows this to work) > > Last point, although this is probably a limitation of .NET, but just to > make sure. The default argument values can't be used, but it is possible > that this isn't even in the assembly information and only works for source > in the same module. > > Thanks, > Jeff > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From barton at bcdesignswell.com Tue Jan 8 10:51:58 2013 From: barton at bcdesignswell.com (Barton) Date: Tue, 08 Jan 2013 01:51:58 -0800 Subject: [Python.NET] Memory Type Problems In-Reply-To: References: <50E8A43E.8050207@bcdesignswell.com> Message-ID: <50EBEC3E.8070700@bcdesignswell.com> An HTML attachment was scrubbed... URL: From brad at fie.us Tue Jan 8 16:19:49 2013 From: brad at fie.us (Bradley Friedman) Date: Tue, 8 Jan 2013 10:19:49 -0500 Subject: [Python.NET] Memory Type Problems In-Reply-To: <50EBEC3E.8070700@bcdesignswell.com> References: <50E8A43E.8050207@bcdesignswell.com> <50EBEC3E.8070700@bcdesignswell.com> Message-ID: You can construct .net intptr objects from ints. So you need the address. You already provided the solution to that. In python, you get memory addresses by using ctypes. Be careful to handle it in a way that will support both 32 and 64 bit binaries. Sent from my iPad On Jan 8, 2013, at 4:51 AM, Barton wrote: > 1) Not being much of a C guy myself, I'm not sure what to make of all this pointer business. > Especially since the object reference is capable of being indexed (and SO much more [>>> help(a)]) > - Just don't try a.Address(0) like I just did - got a core dump on Mono - > > 2) C# type rules apply (except that python lets you try things like "a == input"); underneath Array.Equals(System.Array) is called. > hence Int32(7) == 7 is false. > - I tend to think of this package as a "wrist-friendly" (see Boo) wrapper over the Mono/.NET components more than a trying to be a type compatibility layer. > > 3) Slicing seems like something that is worth implementing. That would take a lot of typing out of > Array.Copy(a1, srcIndx, a2, dstIndx, len) > > Great fun, > Barton > > On 01/08/2013 12:31 AM, Jeffrey Bush wrote: >> How about my other questions? Pass as a pointer (like ctypes would do)? Convert that pointer back? And I don't seem to be able to get the slices (":") to work with byte arrays. >> >> Thanks for the help getting the byte arrays started though. I am able to take the output from reading a file and send it right to the array constructor: >> >> import clr >> from System import Array, Byte >> with open("file.txt", 'rb') as f: input = f.read() >> a = Array[Byte](input) >> >> One problem though is that equality doesn't work (a==input is False). But maybe this is because one is a list of (unsigned) bytes and one is a list of (signed) characters. a[0] and input[0] display differently. >> >> Jeff >> >> >> On Sat, Jan 5, 2013 at 2:07 PM, Barton wrote: >>> Definitely more useful: >>> >>> import clr >>> >>> from System import Array, Byte >>> >>> g = (0 for i in range(10)) >>> >>> a = Array[Byte](list(i for i in g)) >>> >>> >>> a[5] >>> 0 >>> >>> On 01/04/2013 06:33 PM, Jeffrey Bush wrote: >>>> Hi, >>>> >>>> I have a library in C for compression. I made Python script for testing it, called using ctypes. >>>> >>>> Now, I am working on a .NET library for something very similar and would like to test it in the same way. However, I am getting lost in how to do some of the things with your library. >>>> >>>> The function I need to call looks like: >>>> public static long Compress(Memory input, Memory output) >>>> The Memory class is a wrapper around either managed byte arrays, void* (for efficiency), or memory mapped files. This allows a unified system for accessing general chunks of memory regardless if they are managed, native, or on the filesystem. They are created through static functions: >>>> public static Memory From(MemoryStream s, bool all = true) >>>> public static Memory From(byte[] b, bool readOnly = false) >>>> public static Memory From(byte[] b, long offset, long size, bool readOnly = false) >>>> public unsafe static Memory From(UnmanagedMemoryStream s, bool all = true) >>>> public unsafe static Memory From(void* b, long size, bool readOnly = false) >>>> public unsafe static Memory From(IntPtr b, long size, bool readOnly = false) >>>> public static Memory FromFile(string file, bool readOnly = false) >>>> public static Memory OfSize(long size) >>>> The only ones I can easily use are the last two (OfSize and FromFile). I have not yet figured out how to call the other ones properly. I don't seem to be able to allocate byte arrays with Array[Byte](10), it complains that 10 cannot be converted to System.Byte[] so it seems that it believes I am casting instead of creating a new array. No overloads seem to exist. >>>> >>>> So now here are my questions and the ctypes answer: >>>> How do I construct a byte array? (ctypes.create_string_buffer) >>>> How do I take a Python list/array and pass it as a pointer? (ctypes has this conversion happen automatically) >>>> How do I turn a byte array into a useful Python list/array? As-is I can't use the Python-style indexers (except negative numbers). (The ctypes buffer works directly as a list, but also supports ".raw" and ".value") >>>> How do I convert a pointer into a useful Python list/array? (ctypes casting allows this to work) >>>> Last point, although this is probably a limitation of .NET, but just to make sure. The default argument values can't be used, but it is possible that this isn't even in the assembly information and only works for source in the same module. >>>> >>>> Thanks, >>>> Jeff >>>> >>>> >>>> _________________________________________________ >>>> Python.NET mailing list - PythonDotNet at python.org >>>> http://mail.python.org/mailman/listinfo/pythondotnet > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Wed Jan 9 18:47:39 2013 From: brad at fie.us (brad at fie.us) Date: Wed, 9 Jan 2013 12:47:39 -0500 Subject: [Python.NET] =?windows-1252?q?success=85_pythonnet_running_in_may?= =?windows-1252?q?a_on_osx64bit?= Message-ID: <5A88146A-265D-4A75-8789-CF9BC0E45BAB@fie.us> success? pythonnet running in maya on osx64bit It took a good amount of hacking. But it does work. I'm going to work on wrapping all my changes and fixes into a patch or two. However, some general notes: You need to build your own mono in 64 bit mode, because they don't ship a precompiled 64bit mono for OSX currently. I found it easiest to make a custom Portfile for macports, to do this. Basic instructions can be found on the mono project's website. pythonnet desperately needs a configure script. Most of what I've been doing is ripping out a lot of pkg-config stuff that is making assumptions about python and mono locations. Apparently, someone put a whole bunch of hard-coded ubuntu paths in there. Once I've finished doing that, I can actually do what I need to do. Which is tell the build system where my 64bit mono is, and which python to use. in my case that's: export PKG_CONFIG_PATH=/path/to/my/mono/pkgconfig make PYTHON=/Applications/Autodesk/maya2013/Maya.app/Contents/bin/mayapy The makefiles themselves should not be finding mono-2 and glib-2.0. They should assume them to be available to pkg-config already. Finding them is something for a configure script. And I'd argue it probably should set the python as well. I had to hack up Python.Runtime.dll.config and tell it to "link" to "maya" rather than some form of "python26." Python is statically linked into maya, as it is with a lot of 3rd party embedded python implementations. The symbols it wants to link to, are in the maya binary, not a shared library. So from a build system point of view, I'm thinking the two big takeaways are: it REALLY needs a configure script. Python.Runtime.dll.config probably needs to be generated as part of the build process and listen to the configure script as to where to point itself. If I know where to point it to, during the build, I should be able to configure that as part of the build process. Anyhow. Those are my thoughts. I'll try and send off some patches once I do some cleaning up. -brad From brad at fie.us Wed Jan 9 19:43:31 2013 From: brad at fie.us (brad at fie.us) Date: Wed, 9 Jan 2013 13:43:31 -0500 Subject: [Python.NET] =?windows-1252?q?success=85_pythonnet_running_in_may?= =?windows-1252?q?a_on_osx64bit?= In-Reply-To: <5A88146A-265D-4A75-8789-CF9BC0E45BAB@fie.us> References: <5A88146A-265D-4A75-8789-CF9BC0E45BAB@fie.us> Message-ID: <1D4D0316-8FC8-4CED-AF12-170225304F0F@fie.us> sorry? clarification: the .config needs to be set to "__Internal" if you set it to "maya" it will only work from running mayapy if you set it to "__Internal" it will work form both mayapy and maya. That's a mono thing. As an interesting fluke, you can use "maya" for mayapy and "mayapy" for maya. On Jan 9, 2013, at 12:47 PM, "brad at fie.us" wrote: > success? pythonnet running in maya on osx64bit > > It took a good amount of hacking. But it does work. > > I'm going to work on wrapping all my changes and fixes into a patch or two. > > However, some general notes: > > You need to build your own mono in 64 bit mode, because they don't ship a precompiled 64bit mono for OSX currently. I found it easiest to make a custom Portfile for macports, to do this. Basic instructions can be found on the mono project's website. > > pythonnet desperately needs a configure script. Most of what I've been doing is ripping out a lot of pkg-config stuff that is making assumptions about python and mono locations. Apparently, someone put a whole bunch of hard-coded ubuntu paths in there. Once I've finished doing that, I can actually do what I need to do. Which is tell the build system where my 64bit mono is, and which python to use. > > in my case that's: > > export PKG_CONFIG_PATH=/path/to/my/mono/pkgconfig > make PYTHON=/Applications/Autodesk/maya2013/Maya.app/Contents/bin/mayapy > > The makefiles themselves should not be finding mono-2 and glib-2.0. They should assume them to be available to pkg-config already. Finding them is something for a configure script. And I'd argue it probably should set the python as well. > > I had to hack up Python.Runtime.dll.config and tell it to "link" to "maya" rather than some form of "python26." Python is statically linked into maya, as it is with a lot of 3rd party embedded python implementations. The symbols it wants to link to, are in the maya binary, not a shared library. > > So from a build system point of view, I'm thinking the two big takeaways are: > > it REALLY needs a configure script. > > Python.Runtime.dll.config probably needs to be generated as part of the build process and listen to the configure script as to where to point itself. If I know where to point it to, during the build, I should be able to configure that as part of the build process. > > Anyhow. Those are my thoughts. I'll try and send off some patches once I do some cleaning up. > > -brad > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet From barton at bcdesignswell.com Sun Jan 13 00:14:23 2013 From: barton at bcdesignswell.com (Barton) Date: Sat, 12 Jan 2013 15:14:23 -0800 Subject: [Python.NET] =?windows-1252?q?success=85_pythonnet_running_in_may?= =?windows-1252?q?a_on_osx64bit?= In-Reply-To: <1D4D0316-8FC8-4CED-AF12-170225304F0F@fie.us> References: <5A88146A-265D-4A75-8789-CF9BC0E45BAB@fie.us> <1D4D0316-8FC8-4CED-AF12-170225304F0F@fie.us> Message-ID: <50F1EE4F.4090106@bcdesignswell.com> I've been working on the Linux and Windows build scripts. I'll happily add your work to the repo; just attach it (directly to me if that helps). Thanks, Barton On 01/09/2013 10:43 AM, brad at fie.us wrote: > sorry? clarification: > > the .config needs to be set to "__Internal" > > if you set it to "maya" it will only work from running mayapy > > if you set it to "__Internal" it will work form both mayapy and maya. That's a mono thing. As an interesting fluke, you can use "maya" for mayapy and "mayapy" for maya. > > > On Jan 9, 2013, at 12:47 PM, "brad at fie.us" wrote: > >> success? pythonnet running in maya on osx64bit >> >> It took a good amount of hacking. But it does work. >> >> I'm going to work on wrapping all my changes and fixes into a patch or two. >> >> However, some general notes: >> >> You need to build your own mono in 64 bit mode, because they don't ship a precompiled 64bit mono for OSX currently. I found it easiest to make a custom Portfile for macports, to do this. Basic instructions can be found on the mono project's website. >> >> pythonnet desperately needs a configure script. Most of what I've been doing is ripping out a lot of pkg-config stuff that is making assumptions about python and mono locations. Apparently, someone put a whole bunch of hard-coded ubuntu paths in there. Once I've finished doing that, I can actually do what I need to do. Which is tell the build system where my 64bit mono is, and which python to use. >> >> in my case that's: >> >> export PKG_CONFIG_PATH=/path/to/my/mono/pkgconfig >> make PYTHON=/Applications/Autodesk/maya2013/Maya.app/Contents/bin/mayapy >> >> The makefiles themselves should not be finding mono-2 and glib-2.0. They should assume them to be available to pkg-config already. Finding them is something for a configure script. And I'd argue it probably should set the python as well. >> >> I had to hack up Python.Runtime.dll.config and tell it to "link" to "maya" rather than some form of "python26." Python is statically linked into maya, as it is with a lot of 3rd party embedded python implementations. The symbols it wants to link to, are in the maya binary, not a shared library. >> >> So from a build system point of view, I'm thinking the two big takeaways are: >> >> it REALLY needs a configure script. >> >> Python.Runtime.dll.config probably needs to be generated as part of the build process and listen to the configure script as to where to point itself. If I know where to point it to, during the build, I should be able to configure that as part of the build process. >> >> Anyhow. Those are my thoughts. I'll try and send off some patches once I do some cleaning up. >> >> -brad >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From jeff at coderforlife.com Tue Jan 15 09:38:37 2013 From: jeff at coderforlife.com (Jeffrey Bush) Date: Tue, 15 Jan 2013 00:38:37 -0800 Subject: [Python.NET] Memory Type Problems In-Reply-To: References: <50E8A43E.8050207@bcdesignswell.com> <50EBEC3E.8070700@bcdesignswell.com> Message-ID: Thanks for all your input! With your help I have been able to get everything working as expected. Getting the address of a string with ctypes was a bit trickier than I expected, but I the end the following works (if anyone would like to know): import ctypes from System import IntPtr addr = ctypes.cast(ctypes.c_char_p(s), ctypes.c_void_p).value ptr = IntPtr.__overloads__[long](addr) That is for "str" objects. As a side note these should be treated as read-only due to Python optimizations with strings. For things that come from ctypes.create_string_bufffer() the ctypes.c_char_p(s) should be just s. These are not read-only. The last thing I would like to suggest to make things more "wrist friendly" as you put it is to make the need for __overloads__ less by making it smarter. Two examples come to mind. First is the example above. If I try IntPtr(5) or IntPtr(5L) it complains that "'int/long' value cannot be converted to System.IntPtr". It seems like it is trying to cast or something instead of call the constructor. Or maybe since ints and longs are both ValueTypes it can't choose which to use. Or maybe even just the fact they use the same number of arguments. Another example is later on when I am using Memory objects from my code. The Memory class is abstract and has two concrete implementations: ManagedMemory and UnmanagedMemory. I was trying to call a method that takes either one of these three along with any type of array of value-types. In this case all of Python crashes when it tries to convert the UnmanagedMemory object to an array (exception text is at the end of this message). This is something that should be determinable by the .NET bridge. For now I won't be needing to write much more than I have using Python for .NET, however it would be nice to make the system a little smarter with overloads. Thanks for the great work so far! Jeff Exception that crashes Python: Unhandled Exception: System.NotSupportedException: Cannot create arrays of TypedReference, ArgIterator, ByRef, or RuntimeArgumentHandle Objects. at System.Array.InternalCreate(Void* elementType, Int32 rank, Int32* pLengths, Int32* pLowerBounds) at System.Array.CreateInstance(Type elementType, Int32 length) at Python.Runtime.Converter.ToArray(IntPtr value, Type obType, Object& result, Boolean setError) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\converter.cs:line 648 at Python.Runtime.Converter.ToManagedValue(IntPtr value, Type obType, Object& result, Boolean set Error) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\converter.cs:line 263 at Python.Runtime.Converter.ToManaged(IntPtr value, Type type, Object& result, Boolean setError) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\converter.cs:line 201 at Python.Runtime.MethodBinder.Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\methodbinder.cs:line 278 at Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\methodbinder.cs:line 340 at Python.Runtime.MethodObject.Invoke(IntPtr target, IntPtr args, IntPtr kw, MethodBase info) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\methodobject.cs:line 63 at Python.Runtime.MethodBinding.tp_call(IntPtr ob, IntPtr args, IntPtr kw) in D:\Users\Barton\Documents\Visual Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\methodbinding.cs:line 135 On Tue, Jan 8, 2013 at 7:19 AM, Bradley Friedman wrote: > You can construct .net intptr objects from ints. So you need the address. > You already provided the solution to that. In python, you get memory > addresses by using ctypes. Be careful to handle it in a way that will > support both 32 and 64 bit binaries. > > Sent from my iPad > > On Jan 8, 2013, at 4:51 AM, Barton wrote: > > 1) Not being much of a C guy myself, I'm not sure what to make of all > this pointer business. > Especially since the object reference is capable of being indexed > (and SO much more [>>> help(a)]) > - Just don't try a.Address(0) like I just did - got a core dump on > Mono - > > 2) C# type rules apply (except that python lets you try things like "a == > input"); underneath Array.Equals(System.Array) is called. > hence Int32(7) == 7 is false. > - I tend to think of this package as a "wrist-friendly" (see > Boo) wrapper over the Mono/.NET components more than a trying to be a type > compatibility layer. > > 3) Slicing seems like something that is worth implementing. That would > take a lot of typing out of > Array.Copy(a1, srcIndx, a2, dstIndx, len) > > Great fun, > Barton > > On 01/08/2013 12:31 AM, Jeffrey Bush wrote: > > How about my other questions? Pass as a pointer (like ctypes would do)? > Convert that pointer back? And I don't seem to be able to get the slices > (":") to work with byte arrays. > > Thanks for the help getting the byte arrays started though. I am able to > take the output from reading a file and send it right to the array > constructor: > > import clr > from System import Array, Byte > with open("file.txt", 'rb') as f: input = f.read() > a = Array[Byte](input) > > One problem though is that equality doesn't work (a==input is False). > But maybe this is because one is a list of (unsigned) bytes and one is a > list of (signed) characters. a[0] and input[0] display differently. > > Jeff > > > On Sat, Jan 5, 2013 at 2:07 PM, Barton wrote: > >> Definitely more useful: >> >>> import clr >> >>> from System import Array, Byte >> >>> g = (0 for i in range(10)) >> >>> a = Array[Byte](list(i for i in g)) >> >> >>> a[5] >> 0 >> >> On 01/04/2013 06:33 PM, Jeffrey Bush wrote: >> >> Hi, >> >> I have a library in C for compression. I made Python script for testing >> it, called using ctypes. >> >> Now, I am working on a .NET library for something very similar and >> would like to test it in the same way. However, I am getting lost in how to >> do some of the things with your library. >> >> The function I need to call looks like: >> >> public static long Compress(Memory input, Memory output) >> >> The Memory class is a wrapper around either managed byte arrays, void* >> (for efficiency), or memory mapped files. This allows a unified system for >> accessing general chunks of memory regardless if they are managed, native, >> or on the filesystem. They are created through static functions: >> >> public static Memory From(MemoryStream s, bool all = true)public static Memory From(byte[] b, bool readOnly = false)public static Memory From(byte[] b, long offset, long size, bool readOnly = false)public unsafe static Memory From(UnmanagedMemoryStream s, bool all = true)public unsafe static Memory From(void* b, long size, bool readOnly = false)public unsafe static Memory From(IntPtr b, long size, bool readOnly = false)public static Memory FromFile(string file, bool readOnly = false)public static Memory OfSize(long size) >> >> The only ones I can easily use are the last two (OfSize and FromFile). >> I have not yet figured out how to call the other ones properly. I don't >> seem to be able to allocate byte arrays with Array[Byte](10), it complains >> that 10 cannot be converted to System.Byte[] so it seems that it believes I >> am casting instead of creating a new array. No overloads seem to exist. >> >> So now here are my questions and the ctypes answer: >> >> - How do I construct a byte array? (ctypes.create_string_buffer) >> - How do I take a Python list/array and pass it as a pointer? >> (ctypes has this conversion happen automatically) >> - How do I turn a byte array into a useful Python list/array? As-is I >> can't use the Python-style indexers (except negative numbers). (The ctypes >> buffer works directly as a list, but also supports ".raw" and ".value") >> - How do I convert a pointer into a useful Python list/array? (ctypes >> casting allows this to work) >> >> Last point, although this is probably a limitation of .NET, but just to >> make sure. The default argument values can't be used, but it is possible >> that this isn't even in the assembly information and only works for source >> in the same module. >> >> Thanks, >> Jeff >> >> >> _________________________________________________Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet >> >> >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From krausda at gmx.de Tue Jan 15 21:41:51 2013 From: krausda at gmx.de (Daniel Krause) Date: Tue, 15 Jan 2013 21:41:51 +0100 Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle Message-ID: 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 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From btribble at ea.com Tue Jan 15 22:08:11 2013 From: btribble at ea.com (Tribble, Brett) Date: Tue, 15 Jan 2013 13:08:11 -0800 Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle In-Reply-To: References: Message-ID: 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 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From krausda at gmx.de Wed Jan 16 20:49:08 2013 From: krausda at gmx.de (Daniel Krause) Date: Wed, 16 Jan 2013 20:49:08 +0100 Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle In-Reply-To: References: Message-ID: 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 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 > 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 **** > > 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 **** > > 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**** > > ** ** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Wed Jan 16 22:21:09 2013 From: brad at fie.us (Bradley Friedman) Date: Wed, 16 Jan 2013 17:21:09 -0400 Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle In-Reply-To: References: Message-ID: <6F45C452-8C77-45F8-A3FE-8FCFB9E0A3BB@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 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 > 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 >> 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 >> >> 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 >> >> 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: From btribble at ea.com Wed Jan 16 22:40:42 2013 From: btribble at ea.com (Tribble, Brett) Date: Wed, 16 Jan 2013 13:40:42 -0800 Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle In-Reply-To: References: Message-ID: How does it differ from the working ironpython environment? From: PythonDotNet [mailto:pythondotnet-bounces+btribble=ea.com at python.org] On Behalf Of Daniel Krause Sent: Wednesday, January 16, 2013 11:49 AM To: pythondotnet at python.org Subject: Re: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle 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 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 > 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 > 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 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From krausda at gmx.de Thu Jan 17 18:54:13 2013 From: krausda at gmx.de (Daniel Krause) Date: Thu, 17 Jan 2013 18:54:13 +0100 Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle In-Reply-To: <6F45C452-8C77-45F8-A3FE-8FCFB9E0A3BB@fie.us> References: <6F45C452-8C77-45F8-A3FE-8FCFB9E0A3BB@fie.us> Message-ID: 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 > 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 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 > 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 > >> 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 **** >> >> 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 *** >> * >> >> 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: From barton at bcdesignswell.com Fri Jan 18 07:15:29 2013 From: barton at bcdesignswell.com (Barton) Date: Thu, 17 Jan 2013 22:15:29 -0800 Subject: [Python.NET] Memory Type Problems In-Reply-To: References: <50E8A43E.8050207@bcdesignswell.com> <50EBEC3E.8070700@bcdesignswell.com> Message-ID: <50F8E881.4030505@bcdesignswell.com> An HTML attachment was scrubbed... URL: From jeff at coderforlife.com Fri Jan 18 07:34:46 2013 From: jeff at coderforlife.com (Jeffrey Bush) Date: Thu, 17 Jan 2013 22:34:46 -0800 Subject: [Python.NET] Memory Type Problems In-Reply-To: <50F8E881.4030505@bcdesignswell.com> References: <50E8A43E.8050207@bcdesignswell.com> <50EBEC3E.8070700@bcdesignswell.com> <50F8E881.4030505@bcdesignswell.com> Message-ID: I noticed the duality of the __overloads__ and Overloads. But I decided to follow the readme (http://pythonnet.sourceforge.net/readme.html). It is possible it should be updated. Also the array example is not so good... it led me done the right road for Array[Byte](...). Jeff On Thu, Jan 17, 2013 at 10:15 PM, Barton wrote: > __overloads__ has been deprecated for some time now. > I prefer the IP compatible Overloads. > > >>> import clr > >>> from System import Int32 > >>> help(Int32) > > | ---------------------------------------------------------------------- > | Data and other attributes defined here: > | > | __new__ = > | T.__new__(S, ...) -> a new object with type S, a subtype of T > | > | ---------------------------------------------------------------------- > | Data descriptors inherited from Object: > | > | Finalize > | Void Finalize() > | > | GetType > | System.Type GetType() > | > | MemberwiseClone > | System.Object MemberwiseClone() > | > | Overloads > | > | ReferenceEquals > | Boolean ReferenceEquals(System.Object, System.Object) > | > | __overloads__ > > As for the smarts behind it, it'll be fun to get back into the guts and > see if some improvements can be made. > > Oh boy; I just love those System.NotSupportedException(s)! > Thanks for the feedback. > > On 01/15/2013 12:38 AM, Jeffrey Bush wrote: > > Thanks for all your input! With your help I have been able to get > everything working as expected. Getting the address of a string > with ctypes was a bit trickier than I expected, but I the end the following > works (if anyone would like to know): > > import ctypes > from System import IntPtr > addr = ctypes.cast(ctypes.c_char_p(s), ctypes.c_void_p).value > ptr = IntPtr.[long](addr) > > That is for "str" objects. As a side note these should be treated as > read-only due to Python optimizations with strings. For things that come > from ctypes.create_string_bufffer() the ctypes.c_char_p(s) should be just > s. These are not read-only. > > The last thing I would like to suggest to make things more "wrist > friendly" as you put it is to make the need for __overloads__ less by > making it smarter. Two examples come to mind. First is the example above. > If I try IntPtr(5) or IntPtr(5L) it complains that "'int/long' value > cannot be converted to System.IntPtr". It seems like it is trying to cast > or something instead of call the constructor. Or maybe since ints and longs > are both ValueTypes it can't choose which to use. Or maybe even just the > fact they use the same number of arguments. > > Another example is later on when I am using Memory objects from my code. > The Memory class is abstract and has two concrete implementations: > ManagedMemory and UnmanagedMemory. I was trying to call a method that takes > either one of these three along with any type of array of value-types. In > this case all of Python crashes when it tries to convert the > UnmanagedMemory object to an array (exception text is at the end of this > message). This is something that should be determinable by the .NET bridge. > > For now I won't be needing to write much more than I have using Python > for .NET, however it would be nice to make the system a little smarter with > overloads. > > Thanks for the great work so far! > Jeff > > > > Exception that crashes Python: > > Unhandled Exception: System.NotSupportedException: Cannot create arrays > of TypedReference, ArgIterator, ByRef, or RuntimeArgumentHandle Objects. > at System.Array.InternalCreate(Void* elementType, Int32 rank, Int32* > pLengths, Int32* pLowerBounds) > at System.Array.CreateInstance(Type elementType, Int32 length) > at Python.Runtime.Converter.ToArray(IntPtr value, Type obType, Object& > result, Boolean setError) in D:\Users\Barton\Documents\Visual Studio > 2010\Projects\PySharp\trunk\pythonnet\src\runtime\converter.cs:line 648 > at Python.Runtime.Converter.ToManagedValue(IntPtr value, Type obType, > Object& result, Boolean set Error) in D:\Users\Barton\Documents\Visual > Studio 2010\Projects\PySharp\trunk\pythonnet\src\runtime\converter.cs:line > 263 > at Python.Runtime.Converter.ToManaged(IntPtr value, Type type, Object& > result, Boolean setError) in D:\Users\Barton\Documents\Visual Studio > 2010\Projects\PySharp\trunk\pythonnet\src\runtime\converter.cs:line 201 > at Python.Runtime.MethodBinder.Bind(IntPtr inst, IntPtr args, IntPtr > kw, MethodBase info, MethodInfo[] methodinfo) in > D:\Users\Barton\Documents\Visual Studio > 2010\Projects\PySharp\trunk\pythonnet\src\runtime\methodbinder.cs:line 278 > at Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr > kw, MethodBase info, MethodInfo[] methodinfo) in > D:\Users\Barton\Documents\Visual Studio > 2010\Projects\PySharp\trunk\pythonnet\src\runtime\methodbinder.cs:line 340 > at Python.Runtime.MethodObject.Invoke(IntPtr target, IntPtr args, > IntPtr kw, MethodBase info) in D:\Users\Barton\Documents\Visual Studio > 2010\Projects\PySharp\trunk\pythonnet\src\runtime\methodobject.cs:line 63 > at Python.Runtime.MethodBinding.tp_call(IntPtr ob, IntPtr args, IntPtr > kw) in D:\Users\Barton\Documents\Visual Studio > 2010\Projects\PySharp\trunk\pythonnet\src\runtime\methodbinding.cs:line 135 > > > > On Tue, Jan 8, 2013 at 7:19 AM, Bradley Friedman wrote: > >> You can construct .net intptr objects from ints. So you need the >> address. You already provided the solution to that. In python, you get >> memory addresses by using ctypes. Be careful to handle it in a way that >> will support both 32 and 64 bit binaries. >> >> Sent from my iPad >> >> On Jan 8, 2013, at 4:51 AM, Barton wrote: >> >> 1) Not being much of a C guy myself, I'm not sure what to make of all >> this pointer business. >> Especially since the object reference is capable of being indexed >> (and SO much more [>>> help(a)]) >> - Just don't try a.Address(0) like I just did - got a core dump >> on Mono - >> >> 2) C# type rules apply (except that python lets you try things like "a == >> input"); underneath Array.Equals(System.Array) is called. >> hence Int32(7) == 7 is false. >> - I tend to think of this package as a "wrist-friendly" (see >> Boo) wrapper over the Mono/.NET components more than a trying to be a type >> compatibility layer. >> >> 3) Slicing seems like something that is worth implementing. That would >> take a lot of typing out of >> Array.Copy(a1, srcIndx, a2, dstIndx, len) >> >> Great fun, >> Barton >> >> On 01/08/2013 12:31 AM, Jeffrey Bush wrote: >> >> How about my other questions? Pass as a pointer (like ctypes would do)? >> Convert that pointer back? And I don't seem to be able to get the slices >> (":") to work with byte arrays. >> >> Thanks for the help getting the byte arrays started though. I am able >> to take the output from reading a file and send it right to the array >> constructor: >> >> import clr >> from System import Array, Byte >> with open("file.txt", 'rb') as f: input = f.read() >> a = Array[Byte](input) >> >> One problem though is that equality doesn't work (a==input is False). >> But maybe this is because one is a list of (unsigned) bytes and one is a >> list of (signed) characters. a[0] and input[0] display differently. >> >> Jeff >> >> >> On Sat, Jan 5, 2013 at 2:07 PM, Barton wrote: >> >>> Definitely more useful: >>> >>> import clr >>> >>> from System import Array, Byte >>> >>> g = (0 for i in range(10)) >>> >>> a = Array[Byte](list(i for i in g)) >>> >>> >>> a[5] >>> 0 >>> >>> On 01/04/2013 06:33 PM, Jeffrey Bush wrote: >>> >>> Hi, >>> >>> I have a library in C for compression. I made Python script for >>> testing it, called using ctypes. >>> >>> Now, I am working on a .NET library for something very similar and >>> would like to test it in the same way. However, I am getting lost in how to >>> do some of the things with your library. >>> >>> The function I need to call looks like: >>> >>> public static long Compress(Memory input, Memory output) >>> >>> The Memory class is a wrapper around either managed byte arrays, void* >>> (for efficiency), or memory mapped files. This allows a unified system for >>> accessing general chunks of memory regardless if they are managed, native, >>> or on the filesystem. They are created through static functions: >>> >>> public static Memory From(MemoryStream s, bool all = true)public static Memory From(byte[] b, bool readOnly = false)public static Memory From(byte[] b, long offset, long size, bool readOnly = false)public unsafe static Memory From(UnmanagedMemoryStream s, bool all = true)public unsafe static Memory From(void* b, long size, bool readOnly = false)public unsafe static Memory From(IntPtr b, long size, bool readOnly = false)public static Memory FromFile(string file, bool readOnly = false)public static Memory OfSize(long size) >>> >>> The only ones I can easily use are the last two (OfSize and FromFile). >>> I have not yet figured out how to call the other ones properly. I don't >>> seem to be able to allocate byte arrays with Array[Byte](10), it complains >>> that 10 cannot be converted to System.Byte[] so it seems that it believes I >>> am casting instead of creating a new array. No overloads seem to exist. >>> >>> So now here are my questions and the ctypes answer: >>> >>> - How do I construct a byte array? (ctypes.create_string_buffer) >>> - How do I take a Python list/array and pass it as a pointer? >>> (ctypes has this conversion happen automatically) >>> - How do I turn a byte array into a useful Python list/array? As-is >>> I can't use the Python-style indexers (except negative numbers). (The >>> ctypes buffer works directly as a list, but also supports ".raw" and >>> ".value") >>> - How do I convert a pointer into a useful Python list/array? >>> (ctypes casting allows this to work) >>> >>> Last point, although this is probably a limitation of .NET, but just >>> to make sure. The default argument values can't be used, but it is possible >>> that this isn't even in the assembly information and only works for source >>> in the same module. >>> >>> Thanks, >>> Jeff >>> >>> >>> _________________________________________________Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet >>> >>> >>> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet >> >> > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From krausda at gmx.de Mon Jan 14 20:55:06 2013 From: krausda at gmx.de (Daniel Krause) Date: Mon, 14 Jan 2013 20:55:06 +0100 Subject: [Python.NET] Problem to use a dll: System.ApplicationException: Error 1: OpenDevice: Invalid handle Message-ID: I am trying to use a dll to control a camera. It is possible 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 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 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From barton at bcdesignswell.com Sun Jan 20 08:35:02 2013 From: barton at bcdesignswell.com (Barton) Date: Sat, 19 Jan 2013 23:35:02 -0800 Subject: [Python.NET] Problem to using [ximea xiApi.NET] In-Reply-To: References: Message-ID: <50FB9E26.7010706@bcdesignswell.com> An HTML attachment was scrubbed... URL: From m.daniel.krause at googlemail.com Sun Jan 20 20:40:49 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Sun, 20 Jan 2013 20:40:49 +0100 Subject: [Python.NET] How to use BitmapSource from System.Windows.Media.Imaging ? Message-ID: I want to use BitmapSource from System.Windows.Media.Imaging (Documentation here: http://msdn.microsoft.com/de-de/library/system.windows.media.imaging.bitmapsource(v=vs.100).aspx) It would be great if someone could help me with this, as I do not have yet much experience with python for .NET, and none at all with .NET itself. My test script: import clr clr.AddReference("System.Windows") import System.Windows bitmap = System.Windows.Media.Imaging.BitmapSource() The interpreter info is: Traceback (most recent call last): File "C:\Users\mdk\workspace\testbitmap.py", line 4, in bitmapsrc = System.Windows.Media.Imaging.BitmapSource() AttributeError: Media I tried also: import clr clr.AddReference("System.Windows.Media") import System.Windows bitmapsrc = System.Windows.Media.Imaging.BitmapSource() Traceback (most recent call last): File "C:\Users\mdk\workspace\testbitmap.py", line 2, in clr.AddReference("System.Windows.Media") System.IO.FileNotFoundException: Unable to find assembly 'System.Windows.Media'. bei Python.Runtime.CLRModule.AddReference(String name) And I also tried: import clr clr.AddReference("System.Windows") from System.Windows import Media bitmapsrc = Media.Imaging.BitmapSource() Traceback (most recent call last): File "C:\Users\mdk\workspace\lr_control\src\lr_control\camera\testbitmap.py", line 3, in from System.Windows import Media ImportError: cannot import name Media -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.daniel.krause at googlemail.com Mon Jan 21 20:10:57 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Mon, 21 Jan 2013 20:10:57 +0100 Subject: [Python.NET] How to use BitmapSource from System.Windows.Media.Imaging ? In-Reply-To: References: Message-ID: Hi Jojo, thanks for your help. The following code is running (64bit-Windows): import clr import sys sys.path.append("C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\WPF") clr.AddReference("PresentationCore") from System.Windows.Media.Imaging import BitmapSource bitmapsrc = BitmapSource print bitmapsrc Console output: Best regards Daniel 2013/1/21 Jojo Maquiling > Hi, > In C#, the System.Windows.Media can just be shown if you add the > "PresentationCore" as part of your reference. The path of > PresentationCore.dll is in C:\Program Files (x86)\Reference > Assemblies\Microsoft\Framework\v3.0 if you are using Visual Studio > 2008. I think that might help if you add that as your reference in > clr.AddReference. I found some explanation in here - > > http://social.msdn.microsoft.com/Forums/en-US/windowswic/thread/fdfff143-c1ae-41cd-bbeb-8ff6c1c879ec > I believe this will help you. > > HTH > > Thanks and best regards, > > Jojo Maquiling > > On Mon, Jan 21, 2013 at 3:40 AM, Daniel Krause > wrote: > > I want to use BitmapSource from System.Windows.Media.Imaging > > (Documentation here: > > > http://msdn.microsoft.com/de-de/library/system.windows.media.imaging.bitmapsource(v=vs.100).aspx > > ) > > > > It would be great if someone could help me with this, as I do not have > yet > > much experience with python for .NET, and none at all with .NET itself. > > > > My test script: > > > > import clr > > clr.AddReference("System.Windows") > > import System.Windows > > bitmap = System.Windows.Media.Imaging.BitmapSource() > > > > The interpreter info is: > > Traceback (most recent call last): > > File "C:\Users\mdk\workspace\testbitmap.py", line 4, in > > bitmapsrc = System.Windows.Media.Imaging.BitmapSource() > > AttributeError: Media > > > > I tried also: > > > > import clr > > clr.AddReference("System.Windows.Media") > > import System.Windows > > bitmapsrc = System.Windows.Media.Imaging.BitmapSource() > > > > > > Traceback (most recent call last): > > File "C:\Users\mdk\workspace\testbitmap.py", > > line 2, in > > clr.AddReference("System.Windows.Media") > > System.IO.FileNotFoundException: Unable to find assembly > > 'System.Windows.Media'. > > bei Python.Runtime.CLRModule.AddReference(String name) > > > > And I also tried: > > > > import clr > > clr.AddReference("System.Windows") > > from System.Windows import Media > > bitmapsrc = Media.Imaging.BitmapSource() > > > > Traceback (most recent call last): > > File > > "C:\Users\mdk\workspace\lr_control\src\lr_control\camera\testbitmap.py", > > line 3, in > > from System.Windows import Media > > ImportError: cannot import name Media > > > > _________________________________________________ > > Python.NET mailing list - PythonDotNet at python.org > > http://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Mon Jan 21 23:26:42 2013 From: brad at fie.us (brad at fie.us) Date: Mon, 21 Jan 2013 17:26:42 -0500 Subject: [Python.NET] How to use BitmapSource from System.Windows.Media.Imaging ? In-Reply-To: References: Message-ID: <70895C42-509F-4C35-8167-1E16DD419884@fie.us> You should be wary of that hard coded path. My best guess as to why the namespace is not provided is that the .net framework that is being loaded is pre .net 3.0. I think python.net compiles to 2.0 by default but I'd need to check that. That Windows.Media.Imaging namespace only became available in .net 3.0 onward. To do this properly, you'd likely be looking to compile or use python.net in a mode that brings in the standard libs for .net 3.0 or higher. Then it should just be available in the GAC for that .net version. Distributing a python script with .net dependencies can get rather ugly. -brad On Jan 21, 2013, at 2:10 PM, Daniel Krause wrote: > Hi Jojo, > > thanks for your help. > > The following code is running (64bit-Windows): > > import clr > import sys > sys.path.append("C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\WPF") > clr.AddReference("PresentationCore") > from System.Windows.Media.Imaging import BitmapSource > bitmapsrc = BitmapSource > print bitmapsrc > > Console output: > > > Best regards > Daniel > > > 2013/1/21 Jojo Maquiling > Hi, > In C#, the System.Windows.Media can just be shown if you add the > "PresentationCore" as part of your reference. The path of > PresentationCore.dll is in C:\Program Files (x86)\Reference > Assemblies\Microsoft\Framework\v3.0 if you are using Visual Studio > 2008. I think that might help if you add that as your reference in > clr.AddReference. I found some explanation in here - > http://social.msdn.microsoft.com/Forums/en-US/windowswic/thread/fdfff143-c1ae-41cd-bbeb-8ff6c1c879ec > I believe this will help you. > > HTH > > Thanks and best regards, > > Jojo Maquiling > > On Mon, Jan 21, 2013 at 3:40 AM, Daniel Krause > wrote: > > I want to use BitmapSource from System.Windows.Media.Imaging > > (Documentation here: > > http://msdn.microsoft.com/de-de/library/system.windows.media.imaging.bitmapsource(v=vs.100).aspx > > ) > > > > It would be great if someone could help me with this, as I do not have yet > > much experience with python for .NET, and none at all with .NET itself. > > > > My test script: > > > > import clr > > clr.AddReference("System.Windows") > > import System.Windows > > bitmap = System.Windows.Media.Imaging.BitmapSource() > > > > The interpreter info is: > > Traceback (most recent call last): > > File "C:\Users\mdk\workspace\testbitmap.py", line 4, in > > bitmapsrc = System.Windows.Media.Imaging.BitmapSource() > > AttributeError: Media > > > > I tried also: > > > > import clr > > clr.AddReference("System.Windows.Media") > > import System.Windows > > bitmapsrc = System.Windows.Media.Imaging.BitmapSource() > > > > > > Traceback (most recent call last): > > File "C:\Users\mdk\workspace\testbitmap.py", > > line 2, in > > clr.AddReference("System.Windows.Media") > > System.IO.FileNotFoundException: Unable to find assembly > > 'System.Windows.Media'. > > bei Python.Runtime.CLRModule.AddReference(String name) > > > > And I also tried: > > > > import clr > > clr.AddReference("System.Windows") > > from System.Windows import Media > > bitmapsrc = Media.Imaging.BitmapSource() > > > > Traceback (most recent call last): > > File > > "C:\Users\mdk\workspace\lr_control\src\lr_control\camera\testbitmap.py", > > line 3, in > > from System.Windows import Media > > ImportError: cannot import name Media > > > > _________________________________________________ > > Python.NET mailing list - PythonDotNet at python.org > > http://mail.python.org/mailman/listinfo/pythondotnet > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.daniel.krause at googlemail.com Tue Jan 22 19:33:59 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Tue, 22 Jan 2013 19:33:59 +0100 Subject: [Python.NET] How to use BitmapSource from System.Windows.Media.Imaging ? In-Reply-To: <70895C42-509F-4C35-8167-1E16DD419884@fie.us> References: <70895C42-509F-4C35-8167-1E16DD419884@fie.us> Message-ID: Thanks for the reminder, I will keep the path in mind. Python for .NET is installed using pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe. As I understand it, it uses .NET 4.0 as default? If that is true, it should work, but I had to add the path to get the script running. 2013/1/21 brad at fie.us > You should be wary of that hard coded path. > > My best guess as to why the namespace is not provided is that the .net > framework that is being loaded is pre .net 3.0. I think python.netcompiles to 2.0 by default but I'd need to check that. > > That Windows.Media.Imaging namespace only became available in .net 3.0 > onward. > > To do this properly, you'd likely be looking to compile or use python.netin a mode that brings in the standard libs for .net 3.0 or higher. Then it > should just be available in the GAC for that .net version. > > Distributing a python script with .net dependencies can get rather ugly. > > -brad > > On Jan 21, 2013, at 2:10 PM, Daniel Krause > wrote: > > Hi Jojo, > > thanks for your help. > > The following code is running (64bit-Windows): > > import clr > import sys > sys.path.append("C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\WPF > ") > clr.AddReference("PresentationCore") > from System.Windows.Media.Imaging import BitmapSource > bitmapsrc = BitmapSource > print bitmapsrc > > Console output: > > > Best regards > Daniel > > > 2013/1/21 Jojo Maquiling > >> Hi, >> In C#, the System.Windows.Media can just be shown if you add the >> "PresentationCore" as part of your reference. The path of >> PresentationCore.dll is in C:\Program Files (x86)\Reference >> Assemblies\Microsoft\Framework\v3.0 if you are using Visual Studio >> 2008. I think that might help if you add that as your reference in >> clr.AddReference. I found some explanation in here - >> >> http://social.msdn.microsoft.com/Forums/en-US/windowswic/thread/fdfff143-c1ae-41cd-bbeb-8ff6c1c879ec >> I believe this will help you. >> >> HTH >> >> Thanks and best regards, >> >> Jojo Maquiling >> >> On Mon, Jan 21, 2013 at 3:40 AM, Daniel Krause >> wrote: >> > I want to use BitmapSource from System.Windows.Media.Imaging >> > (Documentation here: >> > >> http://msdn.microsoft.com/de-de/library/system.windows.media.imaging.bitmapsource(v=vs.100).aspx >> > ) >> > >> > It would be great if someone could help me with this, as I do not have >> yet >> > much experience with python for .NET, and none at all with .NET itself. >> > >> > My test script: >> > >> > import clr >> > clr.AddReference("System.Windows") >> > import System.Windows >> > bitmap = System.Windows.Media.Imaging.BitmapSource() >> > >> > The interpreter info is: >> > Traceback (most recent call last): >> > File "C:\Users\mdk\workspace\testbitmap.py", line 4, in >> > bitmapsrc = System.Windows.Media.Imaging.BitmapSource() >> > AttributeError: Media >> > >> > I tried also: >> > >> > import clr >> > clr.AddReference("System.Windows.Media") >> > import System.Windows >> > bitmapsrc = System.Windows.Media.Imaging.BitmapSource() >> > >> > >> > Traceback (most recent call last): >> > File "C:\Users\mdk\workspace\testbitmap.py", >> > line 2, in >> > clr.AddReference("System.Windows.Media") >> > System.IO.FileNotFoundException: Unable to find assembly >> > 'System.Windows.Media'. >> > bei Python.Runtime.CLRModule.AddReference(String name) >> > >> > And I also tried: >> > >> > import clr >> > clr.AddReference("System.Windows") >> > from System.Windows import Media >> > bitmapsrc = Media.Imaging.BitmapSource() >> > >> > Traceback (most recent call last): >> > File >> > "C:\Users\mdk\workspace\lr_control\src\lr_control\camera\testbitmap.py", >> > line 3, in >> > from System.Windows import Media >> > ImportError: cannot import name Media >> > >> > _________________________________________________ >> > Python.NET mailing list - PythonDotNet at python.org >> > http://mail.python.org/mailman/listinfo/pythondotnet >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.daniel.krause at googlemail.com Tue Jan 22 20:58:05 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Tue, 22 Jan 2013 20:58:05 +0100 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll Message-ID: 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 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: Traceback (most recent call last): File "C:\Users\mdk\workspace\camera\testbitmap.py", line 17, in 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) -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Tue Jan 22 21:05:06 2013 From: brad at fie.us (brad at fie.us) Date: Tue, 22 Jan 2013 15:05:06 -0500 Subject: [Python.NET] How to use BitmapSource from System.Windows.Media.Imaging ? In-Reply-To: References: <70895C42-509F-4C35-8167-1E16DD419884@fie.us> Message-ID: <37C2699D-BC4B-455B-9E8E-CE534E8A309D@fie.us> As discussed here: http://stackoverflow.com/questions/8517159/how-to-detect-at-runtime-that-net-version-4-5-currently-running-your-code Things can get muddled. strictly speaking, using clr4.0 with a framework 2.0 profile would result in the absence of the namespace. It's probably best to try and confirm, regardless of the filename's suggestion. On Jan 22, 2013, at 1:33 PM, Daniel Krause wrote: > Thanks for the reminder, I will keep the path in mind. > > Python for .NET is installed using pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe. As I understand it, it uses .NET 4.0 as default? If that is true, it should work, but I had to add the path to get the script running. > > > 2013/1/21 brad at fie.us > You should be wary of that hard coded path. > > My best guess as to why the namespace is not provided is that the .net framework that is being loaded is pre .net 3.0. I think python.net compiles to 2.0 by default but I'd need to check that. > > That Windows.Media.Imaging namespace only became available in .net 3.0 onward. > > To do this properly, you'd likely be looking to compile or use python.net in a mode that brings in the standard libs for .net 3.0 or higher. Then it should just be available in the GAC for that .net version. > > Distributing a python script with .net dependencies can get rather ugly. > > -brad > > On Jan 21, 2013, at 2:10 PM, Daniel Krause wrote: > >> Hi Jojo, >> >> thanks for your help. >> >> The following code is running (64bit-Windows): >> >> import clr >> import sys >> sys.path.append("C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\WPF") >> clr.AddReference("PresentationCore") >> from System.Windows.Media.Imaging import BitmapSource >> bitmapsrc = BitmapSource >> print bitmapsrc >> >> Console output: >> >> >> Best regards >> Daniel >> >> >> 2013/1/21 Jojo Maquiling >> Hi, >> In C#, the System.Windows.Media can just be shown if you add the >> "PresentationCore" as part of your reference. The path of >> PresentationCore.dll is in C:\Program Files (x86)\Reference >> Assemblies\Microsoft\Framework\v3.0 if you are using Visual Studio >> 2008. I think that might help if you add that as your reference in >> clr.AddReference. I found some explanation in here - >> http://social.msdn.microsoft.com/Forums/en-US/windowswic/thread/fdfff143-c1ae-41cd-bbeb-8ff6c1c879ec >> I believe this will help you. >> >> HTH >> >> Thanks and best regards, >> >> Jojo Maquiling >> >> On Mon, Jan 21, 2013 at 3:40 AM, Daniel Krause >> wrote: >> > I want to use BitmapSource from System.Windows.Media.Imaging >> > (Documentation here: >> > http://msdn.microsoft.com/de-de/library/system.windows.media.imaging.bitmapsource(v=vs.100).aspx >> > ) >> > >> > It would be great if someone could help me with this, as I do not have yet >> > much experience with python for .NET, and none at all with .NET itself. >> > >> > My test script: >> > >> > import clr >> > clr.AddReference("System.Windows") >> > import System.Windows >> > bitmap = System.Windows.Media.Imaging.BitmapSource() >> > >> > The interpreter info is: >> > Traceback (most recent call last): >> > File "C:\Users\mdk\workspace\testbitmap.py", line 4, in >> > bitmapsrc = System.Windows.Media.Imaging.BitmapSource() >> > AttributeError: Media >> > >> > I tried also: >> > >> > import clr >> > clr.AddReference("System.Windows.Media") >> > import System.Windows >> > bitmapsrc = System.Windows.Media.Imaging.BitmapSource() >> > >> > >> > Traceback (most recent call last): >> > File "C:\Users\mdk\workspace\testbitmap.py", >> > line 2, in >> > clr.AddReference("System.Windows.Media") >> > System.IO.FileNotFoundException: Unable to find assembly >> > 'System.Windows.Media'. >> > bei Python.Runtime.CLRModule.AddReference(String name) >> > >> > And I also tried: >> > >> > import clr >> > clr.AddReference("System.Windows") >> > from System.Windows import Media >> > bitmapsrc = Media.Imaging.BitmapSource() >> > >> > Traceback (most recent call last): >> > File >> > "C:\Users\mdk\workspace\lr_control\src\lr_control\camera\testbitmap.py", >> > line 3, in >> > from System.Windows import Media >> > ImportError: cannot import name Media >> > >> > _________________________________________________ >> > Python.NET mailing list - PythonDotNet at python.org >> > http://mail.python.org/mailman/listinfo/pythondotnet >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Tue Jan 22 21:10:07 2013 From: brad at fie.us (brad at fie.us) Date: Tue, 22 Jan 2013 15:10:07 -0500 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: References: Message-ID: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@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 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 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: > > Traceback (most recent call last): > File "C:\Users\mdk\workspace\camera\testbitmap.py", > line 17, in > 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 mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet From m.daniel.krause at googlemail.com Tue Jan 22 22:10:37 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Tue, 22 Jan 2013 22:10:37 +0100 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@fie.us> References: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@fie.us> Message-ID: 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 brad at 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 > 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 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: > > > > Traceback (most recent call last): > > File "C:\Users\mdk\workspace\camera\testbitmap.py", > > line 17, in > > 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 mailing list - PythonDotNet at python.org > > http://mail.python.org/mailman/listinfo/pythondotnet > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From btribble at ea.com Tue Jan 22 23:51:07 2013 From: btribble at ea.com (Tribble, Brett) Date: Tue, 22 Jan 2013 14:51:07 -0800 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: References: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@fie.us> Message-ID: Did you try: from System.Windows.Media.Imaging import BitmapSource bitmapsrc = BitmapSource() # <- set to an instance of type BitmapSource, not the class. cam.GetImage(bitmapsrc, timeout) If you need to pass it a variable that is of type BitmapSource, but which is set to null, then you might be able to use System.Reflection to do this, but I haven't tried... From: PythonDotNet [mailto:pythondotnet-bounces+btribble=ea.com at python.org] On Behalf Of Daniel Krause Sent: Tuesday, January 22, 2013 1:11 PM To: pythondotnet at python.org Subject: Re: [Python.NET] Problem with System.ArgumentException in call to method from dll 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 brad at 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 > 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 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: > > Traceback (most recent call last): > File "C:\Users\mdk\workspace\camera\testbitmap.py", > line 17, in > 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 mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Wed Jan 23 02:00:30 2013 From: brad at fie.us (brad at fie.us) Date: Tue, 22 Jan 2013 20:00:30 -0500 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: References: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@fie.us> Message-ID: <0438B67D-F5B5-4587-AF51-B09EF1F1DBFD@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 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 brad at 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 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 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: > > > > Traceback (most recent call last): > > File "C:\Users\mdk\workspace\camera\testbitmap.py", > > line 17, in > > 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 mailing list - PythonDotNet at python.org > > http://mail.python.org/mailman/listinfo/pythondotnet > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From barton at bcdesignswell.com Wed Jan 23 11:52:39 2013 From: barton at bcdesignswell.com (Barton) Date: Wed, 23 Jan 2013 02:52:39 -0800 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: References: Message-ID: <50FFC0F7.8070508@bcdesignswell.com> The Python.Runtime is a bit tricky when it comes to out parameters: In C# DateTime.TryParse(String, out DateTime) becomes >>> d = DateTime(0) # just a dummy to call the method on >>> d2 = DateTime(0) # another dummy to satisfy the out parameter (could be the same instance, d) # d3 is were the result is passed out >>> result, d3 = d.TryParse("2013/01/22", d2) >>> d3.ToString() u'1/22/2013 12:00:00 AM' >>> # this is the same behavior as iPy I can't test this - I'm on Linux, but: Here you've given the type (class) 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: What you need is an instance, perhaps: bitmapsrc = BitmapSource() # or something to that effect. On 01/22/2013 11:58 AM, Daniel Krause wrote: > 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: > From m.daniel.krause at googlemail.com Wed Jan 23 07:08:09 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Wed, 23 Jan 2013 07:08:09 +0100 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: <0438B67D-F5B5-4587-AF51-B09EF1F1DBFD@fie.us> References: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@fie.us> <0438B67D-F5B5-4587-AF51-B09EF1F1DBFD@fie.us> Message-ID: @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 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 brad at 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 > 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 brad at 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.krause at 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 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: >> > >> > Traceback (most recent call last): >> > File "C:\Users\mdk\workspace\camera\testbitmap.py", >> > line 17, in >> > 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 mailing list - PythonDotNet at python.org >> > http://mail.python.org/mailman/listinfo/pythondotnet >> >> > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Wed Jan 23 15:23:00 2013 From: brad at fie.us (brad at fie.us) Date: Wed, 23 Jan 2013 09:23:00 -0500 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: <50FFC0F7.8070508@bcdesignswell.com> References: <50FFC0F7.8070508@bcdesignswell.com> Message-ID: <2BE84F3E-15AF-46F2-9BA2-8779421DAF57@fie.us> Out of curiosity Barton, could you pass "None" rather than constructing instances? Or does it truly need the argument to have a type in order to disambiguate overloaded methods? Also, it is my understanding that in iPy, out parameters are often omitted from the method's arguments. But in Python.Net they remain in the header. I assume this is because removing the out parameters potentially creates a lot of ambiguity between overloads? I'm wondering if it might be appropriate for PythonNet to define a type to make it possible to remove ambiguity. i.e.: c#: public bool DoJob(int data1, int data2, out string result) { ?} python: doer = Doer() doResult = doer.DoJob(1,2,clr.OutParam(string)) if (doResult[0]): print(doResult[1]) else: print("error") The key being: python net will never ever never let an OutParam object through to the clr. Therefore, the following should throw an exception. clr.OutParam(clr.OutParam) Therefore, you would never run into reflective ambiguity. On Jan 23, 2013, at 5:52 AM, Barton wrote: > The Python.Runtime is a bit tricky when it comes to out parameters: > In C# DateTime.TryParse(String, out DateTime) becomes > > >>> d = DateTime(0) # just a dummy to call the method on > >>> d2 = DateTime(0) # another dummy to satisfy the out parameter (could be the same instance, d) > # d3 is were the result is passed out > >>> result, d3 = d.TryParse("2013/01/22", d2) > >>> d3.ToString() > u'1/22/2013 12:00:00 AM' > >>> # this is the same behavior as iPy > > > > I can't test this - I'm on Linux, but: > Here you've given the type (class) > 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: > > > What you need is an instance, perhaps: > bitmapsrc = BitmapSource() # or something to that effect. > > On 01/22/2013 11:58 AM, Daniel Krause wrote: >> 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: >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet From btribble at ea.com Wed Jan 23 19:51:48 2013 From: btribble at ea.com (Tribble, Brett) Date: Wed, 23 Jan 2013 10:51:48 -0800 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: References: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@fie.us> <0438B67D-F5B5-4587-AF51-B09EF1F1DBFD@fie.us> Message-ID: 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.com at python.org] On Behalf Of Daniel Krause Sent: Tuesday, January 22, 2013 10:08 PM To: pythondotnet at 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 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 brad at 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 > 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 brad at 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 > 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 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: > > Traceback (most recent call last): > File "C:\Users\mdk\workspace\camera\testbitmap.py", > line 17, in > 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 mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet _________________________________________________ Python.NET mailing list - PythonDotNet at python.org http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.daniel.krause at googlemail.com Wed Jan 23 19:07:48 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Wed, 23 Jan 2013 19:07:48 +0100 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: <50FFC0F7.8070508@bcdesignswell.com> References: <50FFC0F7.8070508@bcdesignswell.com> Message-ID: I tried this approach: class PyBitmapSource(BitmapSource): pass bitmapsrc = PyBitmapSource() print bitmapsrc The console output does not really change: TypeError: cannot instantiate abstract class 2013/1/23 Barton > The Python.Runtime is a bit tricky when it comes to out parameters: > In C# DateTime.TryParse(String, out DateTime) becomes > > >>> d = DateTime(0) # just a dummy to call the method on > >>> d2 = DateTime(0) # another dummy to satisfy the out parameter (could > be the same instance, d) > # d3 is were the result is passed out > >>> result, d3 = d.TryParse("2013/01/22", d2) > >>> d3.ToString() > u'1/22/2013 12:00:00 AM' > >>> # this is the same behavior as iPy > > > > I can't test this - I'm on Linux, but: > Here you've given the type (class) > > 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: > > > What you need is an instance, perhaps: > bitmapsrc = BitmapSource() # or something to that effect. > > > On 01/22/2013 11:58 AM, Daniel Krause wrote: > >> 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: >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeff at coderforlife.com Wed Jan 23 21:08:47 2013 From: jeff at coderforlife.com (Jeffrey Bush) Date: Wed, 23 Jan 2013 12:08:47 -0800 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: References: <50FFC0F7.8070508@bcdesignswell.com> Message-ID: As previously said you have to probably do something like: from System.Windows.Media.Imaging import BitmapSource bitmapsrc = None 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 cam.GetImage.Overloads[BitmapSource, int](bitmapsrc, timeout) cam.StopAcquisition() On Wed, Jan 23, 2013 at 10:07 AM, Daniel Krause < m.daniel.krause at googlemail.com> wrote: > I tried this approach: > > class PyBitmapSource(BitmapSource): > pass > bitmapsrc = PyBitmapSource() > print bitmapsrc > > The console output does not really change: > TypeError: cannot instantiate abstract class > > > > 2013/1/23 Barton > >> The Python.Runtime is a bit tricky when it comes to out parameters: >> In C# DateTime.TryParse(String, out DateTime) becomes >> >> >>> d = DateTime(0) # just a dummy to call the method on >> >>> d2 = DateTime(0) # another dummy to satisfy the out parameter (could >> be the same instance, d) >> # d3 is were the result is passed out >> >>> result, d3 = d.TryParse("2013/01/22", d2) >> >>> d3.ToString() >> u'1/22/2013 12:00:00 AM' >> >>> # this is the same behavior as iPy >> >> >> >> I can't test this - I'm on Linux, but: >> Here you've given the type (class) >> >> 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: >> >> >> What you need is an instance, perhaps: >> bitmapsrc = BitmapSource() # or something to that effect. >> >> >> On 01/22/2013 11:58 AM, Daniel Krause wrote: >> >>> 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: >>> >>> >> >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.daniel.krause at googlemail.com Wed Jan 23 21:07:29 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Wed, 23 Jan 2013 21:07:29 +0100 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: References: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@fie.us> <0438B67D-F5B5-4587-AF51-B09EF1F1DBFD@fie.us> Message-ID: I could solve the problem using a subclass of BitmapSource: BitmapImage has a constructor. from System.Windows.Media.Imaging import BitmapImage bitmapsrc = BitmapImage() ... bitmapsrc = cam.GetImage(bitmapsrc, timeout) 2013/1/23 Tribble, Brett > 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.com at python.org] *On Behalf Of *Daniel Krause > *Sent:* Tuesday, January 22, 2013 10:08 PM > > *To:* pythondotnet at 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 > **** > > 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 brad at 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 > 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 brad at 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 > 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 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: > > > > Traceback (most recent call last): > > File "C:\Users\mdk\workspace\camera\testbitmap.py", > > line 17, in > > 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 mailing list - PythonDotNet at python.org > > http://mail.python.org/mailman/listinfo/pythondotnet**** > > ** ** > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet**** > > ** ** > > ** ** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From barton at bcdesignswell.com Thu Jan 24 11:44:59 2013 From: barton at bcdesignswell.com (Barton) Date: Thu, 24 Jan 2013 02:44:59 -0800 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: <0438B67D-F5B5-4587-AF51-B09EF1F1DBFD@fie.us> References: <0684FFE5-1B2A-44D5-9049-EADC0C9A3C01@fie.us> <0438B67D-F5B5-4587-AF51-B09EF1F1DBFD@fie.us> Message-ID: <510110AB.6080401@bcdesignswell.com> An HTML attachment was scrubbed... URL: From barton at bcdesignswell.com Thu Jan 24 11:52:52 2013 From: barton at bcdesignswell.com (Barton) Date: Thu, 24 Jan 2013 02:52:52 -0800 Subject: [Python.NET] Problem with System.ArgumentException in call to method from dll In-Reply-To: <2BE84F3E-15AF-46F2-9BA2-8779421DAF57@fie.us> References: <50FFC0F7.8070508@bcdesignswell.com> <2BE84F3E-15AF-46F2-9BA2-8779421DAF57@fie.us> Message-ID: <51011284.5060404@bcdesignswell.com> Two things spring instantly to mind (thanks for the reminder) 1) A patch has been submitted that tries very cleverly to allow out params to be omitted. This sounds like it's worth pursuing. 2) iPy's Reference type is something that I looked into implementing which would (or could) allow the wrapper to function more like (or just the same as) the C# being wrapped, writing the value directly on the given out param. Oh, boy; I'm starting to get excited by the possibilities. Thanks all, Barton On 01/23/2013 06:23 AM, brad at fie.us wrote: > Out of curiosity Barton, could you pass "None" rather than constructing instances? Or does it truly need the argument to have a type in order to disambiguate overloaded methods? > > Also, it is my understanding that in iPy, out parameters are often omitted from the method's arguments. But in Python.Net they remain in the header. I assume this is because removing the out parameters potentially creates a lot of ambiguity between overloads? > > I'm wondering if it might be appropriate for PythonNet to define a type to make it possible to remove ambiguity. > > i.e.: > c#: > public bool DoJob(int data1, int data2, out string result) { ?} > > python: > doer = Doer() > doResult = doer.DoJob(1,2,clr.OutParam(string)) > if (doResult[0]): > print(doResult[1]) > else: > print("error") > > The key being: python net will never ever never let an OutParam object through to the clr. Therefore, the following should throw an exception. > > clr.OutParam(clr.OutParam) > > Therefore, you would never run into reflective ambiguity. > > On Jan 23, 2013, at 5:52 AM, Barton wrote: > >> The Python.Runtime is a bit tricky when it comes to out parameters: >> In C# DateTime.TryParse(String, out DateTime) becomes >> >>>>> d = DateTime(0) # just a dummy to call the method on >>>>> d2 = DateTime(0) # another dummy to satisfy the out parameter (could be the same instance, d) >> # d3 is were the result is passed out >>>>> result, d3 = d.TryParse("2013/01/22", d2) >>>>> d3.ToString() >> u'1/22/2013 12:00:00 AM' >>>>> # this is the same behavior as iPy >> >> >> I can't test this - I'm on Linux, but: >> Here you've given the type (class) >> 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: >> >> >> What you need is an instance, perhaps: >> bitmapsrc = BitmapSource() # or something to that effect. >> >> On 01/22/2013 11:58 AM, Daniel Krause wrote: >>> 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: >>> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet > From m.daniel.krause at googlemail.com Thu Jan 24 21:11:29 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Thu, 24 Jan 2013 21:11:29 +0100 Subject: [Python.NET] How to pass a Type to a method? Message-ID: I would like to use System.Array. The following code is running with iron python import clr import System from System import Array from System import Int32 from clr import GetClrType rows = 1 columns = 2 #method: Array.CreateInstance(Type, Int32, Int32) array = Array.CreateInstance(GetClrType(Int32), rows, columns) print array.GetLength(0) print array.GetLength(1) ouptput: 1 2 The same code throws an import error in python for .NET from clr import GetClrType ImportError: cannot import name GetClrType Is another syntax for python for .Net necessary? Or is there perhaps another method to pass a Type to a method? -------------- next part -------------- An HTML attachment was scrubbed... URL: From btribble at ea.com Thu Jan 24 22:27:04 2013 From: btribble at ea.com (Tribble, Brett) Date: Thu, 24 Jan 2013 13:27:04 -0800 Subject: [Python.NET] How to pass a Type to a method? In-Reply-To: References: Message-ID: I don't think the python.net clr module supports most of the methods etc. that the IronPython one does: http://nullege.com/codes/search/clr Can you use the following instead? import System ... ... array = Array.CreateInstance(System.Int32, rows, columns) From: PythonDotNet [mailto:pythondotnet-bounces+btribble=ea.com at python.org] On Behalf Of Daniel Krause Sent: Thursday, January 24, 2013 12:11 PM To: pythondotnet at python.org Subject: [Python.NET] How to pass a Type to a method? I would like to use System.Array. The following code is running with iron python import clr import System from System import Array from System import Int32 from clr import GetClrType rows = 1 columns = 2 #method: Array.CreateInstance(Type, Int32, Int32) array = Array.CreateInstance(GetClrType(Int32), rows, columns) print array.GetLength(0) print array.GetLength(1) ouptput: 1 2 The same code throws an import error in python for .NET from clr import GetClrType ImportError: cannot import name GetClrType Is another syntax for python for .Net necessary? Or is there perhaps another method to pass a Type to a method? -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.daniel.krause at googlemail.com Thu Jan 24 22:36:32 2013 From: m.daniel.krause at googlemail.com (Daniel Krause) Date: Thu, 24 Jan 2013 22:36:32 +0100 Subject: [Python.NET] How to pass a Type to a method? In-Reply-To: References: Message-ID: Wow, I tried so many different variants, but this I must have missed! Thanks, it works! 2013/1/24 Tribble, Brett > I don?t think the python.net clr module supports most of the methods etc. > that the IronPython one does:**** > > ** ** > > http://nullege.com/codes/search/clr**** > > ** ** > > Can you use the following instead?**** > > ** ** > > import System**** > > ?**** > > ** ** > > ?**** > > array = Array.CreateInstance(System.Int32, rows, columns)**** > > ** ** > > *From:* PythonDotNet [mailto:pythondotnet-bounces+btribble= > ea.com at python.org] *On Behalf Of *Daniel Krause > *Sent:* Thursday, January 24, 2013 12:11 PM > *To:* pythondotnet at python.org > *Subject:* [Python.NET] How to pass a Type to a method?**** > > ** ** > > I would like to use System.Array.**** > > ** ** > > The following code is running with iron python**** > > ** ** > > import clr**** > > import System**** > > from System import Array**** > > from System import Int32**** > > from clr import GetClrType**** > > rows = 1**** > > columns = 2**** > > #method: Array.CreateInstance(Type, Int32, Int32)**** > > array = Array.CreateInstance(GetClrType(Int32), rows, columns)**** > > print array.GetLength(0)**** > > print array.GetLength(1)**** > > ** ** > > ouptput:**** > > 1**** > > 2**** > > ** ** > > The same code throws an import error in python for .NET**** > > from clr import GetClrType**** > > ImportError: cannot import name GetClrType**** > > ** ** > > Is another syntax for python for .Net necessary?**** > > Or is there perhaps another method to pass a Type to a method?**** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pierre-yves at strub.nu Mon Jan 28 17:05:44 2013 From: pierre-yves at strub.nu (Pierre-Yves Strub) Date: Mon, 28 Jan 2013 17:05:44 +0100 Subject: [Python.NET] Dynamic types of returns PyObject from the runtime Message-ID: <5106A1D8.4040703@strub.nu> Hi, While playing with the .NET python runtime (see code bellow), I have been surprised to see that the dynamic type of all values returned by the runtime is PyObject. For instance, in the latter example, I would expect "sum" to be of dynamic type PyInt and to be able to write (sum :?> PyInt) instead of (PyInt.AsInt sum). Is it a "feature" of the runtime binding ? let entry () = PythonEngine.Initialize () use lock = new PythonEngineLock () in use builtin = PythonEngine.ImportModule ("__builtin__") in use data = new PyList (data |> Array.map (fun i -> new PyInt (i) :> PyObject)) in use sum = builtin.GetAttr("sum").Invoke([|data :> PyObject|]) in printfn "%A" (sum.GetType ()); printfn "%A" (sum.GetPythonType ()) Best, Pierre-Yves. From barton at bcdesignswell.com Tue Jan 29 12:03:22 2013 From: barton at bcdesignswell.com (Barton) Date: Tue, 29 Jan 2013 03:03:22 -0800 Subject: [Python.NET] Dynamic types of returns PyObject from the runtime In-Reply-To: <5106A1D8.4040703@strub.nu> References: <5106A1D8.4040703@strub.nu> Message-ID: <5107AC7A.2030409@bcdesignswell.com> python dynamically typed: Yes C# dynamically typed: No, strongly typed. It uses lots of overloads to return the required type. I suppose some embedder somewhere has a neat way of applying the type info on the PyObject to some sort of wrapper. What language is that, anyway? It looks sort of interesting. Barton On 01/28/2013 08:05 AM, Pierre-Yves Strub wrote: > Hi, > > While playing with the .NET python runtime (see code bellow), I have > been surprised to see that the dynamic type of all values returned by > the runtime is PyObject. For instance, in the latter example, I would > expect "sum" to be of dynamic type PyInt and to be able to write (sum > :?> PyInt) instead of (PyInt.AsInt sum). Is it a "feature" of the > runtime binding ? > > let entry () = > PythonEngine.Initialize () > use lock = new PythonEngineLock () in > use builtin = PythonEngine.ImportModule ("__builtin__") in > use data = > new PyList > (data |> Array.map (fun i -> new PyInt (i) :> PyObject)) in > use sum = builtin.GetAttr("sum").Invoke([|data :> PyObject|]) in > > printfn "%A" (sum.GetType ()); > printfn "%A" (sum.GetPythonType ()) > > > Best, > Pierre-Yves. > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From pierre-yves at strub.nu Tue Jan 29 14:23:42 2013 From: pierre-yves at strub.nu (Pierre-Yves Strub) Date: Tue, 29 Jan 2013 14:23:42 +0100 Subject: [Python.NET] Dynamic types of returns PyObject from the runtime In-Reply-To: <5107AC7A.2030409@bcdesignswell.com> References: <5106A1D8.4040703@strub.nu> <5107AC7A.2030409@bcdesignswell.com> Message-ID: <5107CD5E.5060205@strub.nu> Hi, Not going to a jargon war, I was not speaking about the "dynamic type system" of C#, but the dynamic type of an object (or runtime type if you prefer) as opposed to its static one. Moreover, C# 4.0 is dynamically typed too: namespace Test { class Program { static void plop(string _s) { } static void Main(string[] args) { dynamic foo = 0; foo.callMyMethod(0); Program.plop(foo); } } } Coming back to my initial mail, I would be surprised that returning the lowest type in the Python.Runtime.Py* hierarchy adds such an overhead (meaning, it only has to happen when crossing the Python -> .NET border and is a single switch - for instance PyQt is doing such a work and does not suffer from performance problems). Anyway, I would be perfectly happy with some (kind of) downcast function in PyObject that I could call on the returned managed python values. Currently, I added such a function using F# type extensions, but I can create patches against the current trunk if you accept them. Pierre-Yves. On 01/29/2013 12:03 PM, Barton wrote: > python dynamically typed: Yes > C# dynamically typed: No, strongly typed. It uses lots of overloads to > return the required type. > I suppose some embedder somewhere has a neat way of applying the type > info on the PyObject to some sort of wrapper. > > What language is that, anyway? It looks sort of interesting. > Barton > > On 01/28/2013 08:05 AM, Pierre-Yves Strub wrote: >> Hi, >> >> While playing with the .NET python runtime (see code bellow), I have >> been surprised to see that the dynamic type of all values returned by >> the runtime is PyObject. For instance, in the latter example, I would >> expect "sum" to be of dynamic type PyInt and to be able to write (sum >> :?> PyInt) instead of (PyInt.AsInt sum). Is it a "feature" of the >> runtime binding ? >> >> let entry () = >> PythonEngine.Initialize () >> use lock = new PythonEngineLock () in >> use builtin = PythonEngine.ImportModule ("__builtin__") in >> use data = >> new PyList >> (data |> Array.map (fun i -> new PyInt (i) :> PyObject)) in >> use sum = builtin.GetAttr("sum").Invoke([|data :> PyObject|]) in >> >> printfn "%A" (sum.GetType ()); >> printfn "%A" (sum.GetPythonType ()) >> >> >> Best, >> Pierre-Yves. >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet >> > From pierre-yves at strub.nu Tue Jan 29 14:25:58 2013 From: pierre-yves at strub.nu (Pierre-Yves Strub) Date: Tue, 29 Jan 2013 14:25:58 +0100 Subject: [Python.NET] Dynamic types of returns PyObject from the runtime In-Reply-To: <5107AC7A.2030409@bcdesignswell.com> References: <5106A1D8.4040703@strub.nu> <5107AC7A.2030409@bcdesignswell.com> Message-ID: <5107CDE6.6030706@strub.nu> On 01/29/2013 12:03 PM, Barton wrote: > What language is that, anyway? It looks sort of interesting. I forgot to answer that question: this is F#, which is now officially supported by Microsoft (i.e. part of Visual Studio installer) http://research.microsoft.com/en-us/projects/fsharp/ Pierre-Yves. From pierre-yves at strub.nu Wed Jan 30 10:08:36 2013 From: pierre-yves at strub.nu (Pierre-Yves Strub) Date: Wed, 30 Jan 2013 10:08:36 +0100 Subject: [Python.NET] Generics registration in the root namespace leads to exception Message-ID: <5108E314.1000409@strub.nu> Hi, I hit a bug while using Python.NET in presence of generics in the root namespace (See attached C# file). I here attach a patch that solved the issue in my case. Bests, Pierre-Yves. -------------- next part -------------- A non-text attachment was scrubbed... Name: python-dot-net.patch Type: text/x-patch Size: 2475 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Program.cs Type: text/x-csharp Size: 767 bytes Desc: not available URL: From barton at bcdesignswell.com Wed Jan 30 14:56:54 2013 From: barton at bcdesignswell.com (Barton) Date: Wed, 30 Jan 2013 05:56:54 -0800 Subject: [Python.NET] Dynamic types of returns PyObject from the runtime In-Reply-To: <5107CD5E.5060205@strub.nu> References: <5106A1D8.4040703@strub.nu> <5107AC7A.2030409@bcdesignswell.com> <5107CD5E.5060205@strub.nu> Message-ID: <510926A6.9070702@bcdesignswell.com> I'm excited to find ways to make the Python.Runtime more useful/usable. I'll gladly accept and apply patches. I'll not pick up on the whole "dynamic type" thing. I do get your point. Again, pray tell, what (computer) language did the original post demonstrate? Thanks, Barton On 01/29/2013 05:23 AM, Pierre-Yves Strub wrote: > Hi, > > Not going to a jargon war, I was not speaking about the "dynamic type > system" of C#, but the dynamic type of an object (or runtime type if > you prefer) as opposed to its static one. Moreover, C# 4.0 is > dynamically typed too: > > namespace Test { > class Program { > static void plop(string _s) { > } > > static void Main(string[] args) { > dynamic foo = 0; > > foo.callMyMethod(0); > Program.plop(foo); > } > } > } > > Coming back to my initial mail, I would be surprised that returning > the lowest type in the Python.Runtime.Py* hierarchy adds such an > overhead (meaning, it only has to happen when crossing the Python -> > .NET border and is a single switch - for instance PyQt is doing such a > work and does not suffer from performance problems). > > Anyway, I would be perfectly happy with some (kind of) downcast > function in PyObject that I could call on the returned managed python > values. Currently, I added such a function using F# type extensions, > but I can create patches against the current trunk if you accept them. > > Pierre-Yves. > > On 01/29/2013 12:03 PM, Barton wrote: >> python dynamically typed: Yes >> C# dynamically typed: No, strongly typed. It uses lots of overloads to >> return the required type. >> I suppose some embedder somewhere has a neat way of applying the type >> info on the PyObject to some sort of wrapper. >> >> What language is that, anyway? It looks sort of interesting. >> Barton >> >> On 01/28/2013 08:05 AM, Pierre-Yves Strub wrote: >>> Hi, >>> >>> While playing with the .NET python runtime (see code bellow), I have >>> been surprised to see that the dynamic type of all values returned by >>> the runtime is PyObject. For instance, in the latter example, I would >>> expect "sum" to be of dynamic type PyInt and to be able to write (sum >>> :?> PyInt) instead of (PyInt.AsInt sum). Is it a "feature" of the >>> runtime binding ? >>> >>> let entry () = >>> PythonEngine.Initialize () >>> use lock = new PythonEngineLock () in >>> use builtin = PythonEngine.ImportModule ("__builtin__") in >>> use data = >>> new PyList >>> (data |> Array.map (fun i -> new PyInt (i) :> PyObject)) in >>> use sum = builtin.GetAttr("sum").Invoke([|data :> >>> PyObject|]) in >>> >>> printfn "%A" (sum.GetType ()); >>> printfn "%A" (sum.GetPythonType ()) >>> >>> >>> Best, >>> Pierre-Yves. >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.org >>> http://mail.python.org/mailman/listinfo/pythondotnet >>> >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From barton at bcdesignswell.com Wed Jan 30 15:11:17 2013 From: barton at bcdesignswell.com (Barton) Date: Wed, 30 Jan 2013 06:11:17 -0800 Subject: [Python.NET] Generics registration in the root namespace leads to exception In-Reply-To: <5108E314.1000409@strub.nu> References: <5108E314.1000409@strub.nu> Message-ID: <51092A05.1000307@bcdesignswell.com> An HTML attachment was scrubbed... URL: