0

I am trying to call functions from a .dll file using windll instances. But, for unknown reasons, the instance does not find the functions of the .dll file. This is a part of the .dll file (the author is Newport for Cornerstone Monochromator):

    namespace CornerstoneDll
{
  public class Cornerstone
  {
    public USBDeviceList usbDevices;
    public CyUSBDevice device;
    private CyUSBDevice[] connectedDevices = new CyUSBDevice[10];
    private static int XFERSIZE = 64;
    private byte[] outData = new byte[Cornerstone.XFERSIZE];
    private byte[] inData = new byte[Cornerstone.XFERSIZE];
    private int waitTime = 10;
    private uint dev_timeout = 500;
    private CyBulkEndPoint BulkInEndPt;
    private CyBulkEndPoint BulkOutEndPt;
    private int vendorId = 4480;
    private int productId = 18;
    private string lastMessage;

    public Cornerstone(bool connect)
    {
      if (!connect)
        return;
      this.connect();
    }

    ~Cornerstone() => this.disconnect();

    public bool findDevices()
    {
      this.usbDevices = new USBDeviceList((byte) 1);
      this.usbDevices = this.listDevices();
      this.device = this.usbDevices[this.vendorId, this.productId] as CyUSBDevice;
      return true;
    }

    public bool connect()
    {
      this.findDevices();
      if (this.device != null)
      {
        this.BulkInEndPt = this.device.EndPointOf((byte) 129) as CyBulkEndPoint;
        this.BulkOutEndPt = this.device.EndPointOf((byte) 1) as CyBulkEndPoint;
        this.lastMessage = this.getDeviceName() + " connected.";
        return true;
      }
      this.lastMessage = "Please Connect Cornerstone Device";
      return false;
    }

    public void disconnect()

And this is the Python code that I am using:

from ctypes import WinDLL

corner = WinDLL('C:\Cornerstone.dll')

corner.connect()
Traceback (most recent call last):

  File "C:\Users\xxxx\AppData\Local\Temp/ipykernel_10464/1499858079.py", line 1, in <module>
    corner.connect()

  File "c:\program files\python39\lib\ctypes\__init__.py", line 387, in __getattr__
    func = self.__getitem__(name)

  File "c:\program files\python39\lib\ctypes\__init__.py", line 392, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))

AttributeError: function 'connect' not found


corner
<WinDLL 'C:\Cornerstone.dll', handle xxxxxxxxx at xxxxxxxxxxxx>

The Operative System is Windows 10 in 64 bit. I understandd both English and Spanish answers. Thank so much for your attention.

0 Answers0