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