[Python.NET] Re: "TypeError: No method matches given arguments" Error - please help!

2021-08-14 Thread Slide
When calling a .NET method that has out parameters, you have to supply
dummy arguments for the out parameters, can you try something like:

result, response, errString = ESP301Device.SR_Get(1, 0.0, '')

The values don't seem to matter, but they must be there from what I have
seen in my usage.


On Fri, Aug 13, 2021 at 9:03 PM LOST _  wrote:

> Hi Matt,
>
>
>
> From the description this looks like a bug in pythonnet. Can you tell
> which version of pythonnet are you using?
>
>
>
> Regards,
>
> Victor
>
>
>
>
>
> *From: *mysf...@gmail.com
> *Sent: *Friday, August 13, 2021 8:59 PM
> *To: *pythonnet@python.org
> *Subject: *[Python.NET] "TypeError: No method matches given arguments"
> Error - please help!
>
>
>
> This seems to come up semi-regularly from a web search, but I have been
> unable to converge on a solution. I am using Python 3.8 and pythonnet to
> try to control a Newport ESP301 motion controller. The supplied .NET
> assembly contains this command:
>
>
>
> public int SR_Get(int axisNumber, out double limit, out string errstring)
>
>   {
>
>errstring = string.Empty;
>
>limit = double.MinValue;
>
>string text = string.Format("{0}{1}",
> axisNumber.ToString(), "SR");
>
>string text2 = text + "?";
>
>string empty = string.Empty;
>
>StringBuilder sbBuffer = new StringBuilder();
>
>int num = m_COM.Query(text2, ref sbBuffer);
>
>empty = sbBuffer.ToString();
>
>empty = empty.Trim();
>
>errstring = checkReturnCodeAndResponse(text2,
> num, empty);
>
>if (num == 0 && string.IsNullOrEmpty(errstring))
>
>{
>
>  decodeDoubleFromResponse(text,
> empty, out limit);
>
>}
>
>if (!string.IsNullOrEmpty(errstring))
>
>{
>
>  return -1;
>
>}
>
>return 0;
>
>   }
>
>
>
> I am unable to get this command to run successfully using Pythonnet. Here
> is my code:
>
> import sys
>
> print("Adding location of Newport.ESP301.CommandInterface.dll to sys.path")
>
>
> sys.path.append(r'C:\Windows\Microsoft.NET\assembly\GAC_64\Newport.ESP301.CommandInterface\v4.0_2.0.0.3__9f994642f5b48132')
>
>
>
> import clr
>
> clr.AddReference("Newport.ESP301.CommandInterface")
>
> from CommandInterfaceESP301 import *
>
>
>
> import System
>
>
>
> #=
>
>
>
> # Instrument Initialization
>
> instrument="COM3"
>
> BAUDRATE = 921600
>
> print('Instrument Key=>', instrument)
>
>
>
> # create an ESP301 instance
>
> ESP301Device = ESP301()
>
>
>
> # Open communication
>
> ret = ESP301Device.OpenInstrument(instrument, BAUDRATE);
>
> if ret == 0:
>
> print("Instrument successfully opened!")
>
> else:
>
> print("Error!")
>
> # Get positive software limit
>
> result, response, errString = ESP301Device.SR_Get(1)
>
> if result == 0:
>
> print('positive software limit=>', response)
>
> else:
>
> print('Error=>', errString)
>
>
>
> If I try to execute this code, I get the following error:
>
> == RESTART: C:\Users\Laser\Documents\Python Programs\esp301_python.py
> ==
>
> Adding location of Newport.ESP301.CommandInterface.dll to sys.path
>
> Instrument Key=> COM3
>
> Instrument successfully opened!
>
> Traceback (most recent call last):
>
>   File "C:\Users\Laser\Documents\Python Programs\esp301_python.py", line
> 57, in 
>
> result, response, errString = ESP301Device.SR_Get(1)
>
> TypeError: No method matches given arguments for SR_Get: ()
>
>
>
>
>
> I thought this was originally a problem with int64 vs. int32 but I have
> tried several methods for converting between these and all give the same
> error. FWIW, I have no trouble getting this to work in Matlab:
>
> clear
>
> % Add Assembly
>
>
> NET.addAssembly('C:\Windows\Microsoft.NET\assembly\GAC_64\Newport.ESP301.CommandInterface\v4.0_2.0.0.3__9f994642f5b48132\Newport.ESP301.CommandInterface.dll');
>
> % load modules
>
> import CommandInterfaceESP301.*;
>
> cport = "COM3";
>
> BAUDRATE = 921600;
>
> ESP301Device = ESP301();
>
> % open communication
>
> ret = ESP301Device.OpenInstrument(cport, BAUDRATE);
>
> if ret == 0
>
> disp("Intrument open!")
>
> else
>
> disp("Error!")
>
> end
>
>
>
> % Get negative software limit
>
> [result, response, errString] = ESP301Device.SR_Get(1);
>
>
>
> I'm completely stumped and frustrated at this point. Any constructive
> feedback would be very appreciated!
>
>
>
> Matt
>
> ___
>
> PythonNet mailing list -- pythonnet@python.org
>
> To unsubscribe send an email to 

[Python.NET] Re: "TypeError: No method matches given arguments" Error - please help!

2021-08-16 Thread Slide
I'm not sure, I've had to pass dummy arguments in pretty much every call I
have.

On Mon, Aug 16, 2021 at 9:44 AM  wrote:

> I am using pythonnet version 2.5.2. Slide - your suggestion does fix the
> problem, thanks. The following code works:
>
> from System import UInt32, Int32
> from System import Double
> result, response, errString = ESP301Device.SR_Get(Int32(1),Double(0.),"")
>
> I think I misread the documentation, which says that calling dummy
> arguments was necessary with a void method. Is this correct? Otherwise the
> dummy arguments must always be provided? Thanks again to all for the
> feedback.
>
> Matt
> ___
> PythonNet mailing list -- pythonnet@python.org
> To unsubscribe send an email to pythonnet-le...@python.org
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: slide.o@gmail.com
>


-- 
Website: http://earl-of-code.com
___
PythonNet mailing list -- pythonnet@python.org
To unsubscribe send an email to pythonnet-le...@python.org
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: arch...@mail-archive.com


[Python.NET] Parameter marshalling question

2021-08-20 Thread Slide
I have the following method defined in my application that I am trying to
call from Python using PythonNET


Snippet

public IEnumerable ReadBuffer(ulong address, int size, out int readCount)


The address can be anything in the range of 0x0__ - 0x1__,
when I call this using a value that is less than 0x1__ (e.g.,
0x0_01d00_) I get an error that the value an Int32 when a UInt64 is
expected, so I created an override that takes an Int32 as the first
parameter and the function works when using values less than 0x1__,
so far so good. However, when I try and call the function with an address
>= 0x1__ I get the following exception.

System.AggregateException: One or more errors occurred. --->
System.ArgumentException: Expected UInt64, got Int32 in method
System.Collections.Generic.IEnumerab
le`1[System.Byte] ReadBuffer(UInt64, Int32, Int32 ByRef) --->
Python.Runtime.PythonException: Expected UInt64, got Int32
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.ArgumentException: Expected UInt64, got
Int32 in method System.Collections.Generic.IEnumerable`1[System.Byte]
ReadBuffer(UInt64
, Int32, Int32 ByRef) ---> Python.Runtime.PythonException: Expected UInt64,
got Int32
--- End of inner exception stack trace ---<---

---> (Inner Exception #1) System.ArgumentException: value too large to
convert in method System.Collections.Generic.IEnumerable`1[System.Byte]
ReadBuffer(Int32,
Int32, Int32 ByRef) ---> Python.Runtime.PythonException: value too large to
convert
--- End of inner exception stack trace ---<---

It seems like the checks in converter.cs will choose Int32 even if the
value is longer that 32-bits (since PyInt is also true for larger than
32-bit values).

Snippet

if (value == Runtime.PyIntType){result = int32Type;
return true;}
if (value == Runtime.PyLongType){
result = int64Type;
return true;}

So, I am confused how I can get the correct method resolution and the
correct type.

Can anyone shed any light on this?

Regards,

Alex

-- 
Website: http://earl-of-code.com
___
PythonNet mailing list -- pythonnet@python.org
To unsubscribe send an email to pythonnet-le...@python.org
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: arch...@mail-archive.com