"TypeError: No method matches given arguments" Error - please help!
![](https://secure.gravatar.com/avatar/9522cd02abe5851c1ae839c3c2fa07ca.jpg?s=120&d=mm&r=g)
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 <module> result, response, errString = ESP301Device.SR_Get(1) TypeError: No method matches given arguments for SR_Get: (<class 'int'>) 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
![](https://secure.gravatar.com/avatar/c1d5a49b51f1aa3df7aa8ee8fad45aca.jpg?s=120&d=mm&r=g)
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 _ <lostfreeman@gmail.com> 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: *mysfeir@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 <module>
result, response, errString = ESP301Device.SR_Get(1)
TypeError: No method matches given arguments for SR_Get: (<class 'int'>)
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 pythonnet-leave@python.org
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: lostfreeman@gmail.com
_______________________________________________ PythonNet mailing list -- pythonnet@python.org To unsubscribe send an email to pythonnet-leave@python.org https://mail.python.org/mailman3/lists/pythonnet.python.org/ Member address: slide.o.mix@gmail.com
-- Website: http://earl-of-code.com
![](https://secure.gravatar.com/avatar/9522cd02abe5851c1ae839c3c2fa07ca.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/c1d5a49b51f1aa3df7aa8ee8fad45aca.jpg?s=120&d=mm&r=g)
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 <mysfeir@gmail.com> 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-leave@python.org https://mail.python.org/mailman3/lists/pythonnet.python.org/ Member address: slide.o.mix@gmail.com
-- Website: http://earl-of-code.com
participants (3)
-
LOST _
-
mysfeir@gmail.com
-
Slide