[Python.NET] How to provide a variable of special type as method parameter

Daniel Krause krausda at gmx.de
Mon May 14 12:41:05 EDT 2018


I posted this question at stackoverflow some days ago:

I want to use a DLL with the help of Python for .NET (pythonnet).
The methods in this DLL require (pointer to?) variables as parameters.

I could figure out how to call a method and to provide an integer variable
as parameter.

I could not figure out how to provide such a parameter variable if a
special type is required (here: FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[]).

Here is a code summary, and the results:

import clrimport sys
sys.path.append("C:\\Users\\[...]\\FTD2XX_NET_v1.1.0\\") # path to dll
clr.AddReference("FTD2XX_NET")from FTD2XX_NET import FTDIfrom System
import UInt32
ftdi = FTDI()
if __name__ == '__main__':
# This method requires an integer as parameter, the code is working
    # M:FTD2XX_NET.FTDI.GetLibraryVersion(System.UInt32@)
    # summary: Gets the current FTD2XX.DLL driver version number.
    # returns: FT_STATUS value from FT_GetLibraryVersion in FTD2XX.DLL
    # param: name: LibraryVersion. The current library version.

    version_ = 0 # empty variable to provide as parameter
    ft_status, version = ftdi.GetLibraryVersion(version_)
    print('status: {}\nversion: {}'.format(ft_status, version))
    # prints
    # status: 0
    # version: 197140
# This method requires an FT_DEVICE_INFO_NODE[] as parameter, the code
is not working
    # summary: Gets information on all of the FTDI devices available.
    # returns: FT_STATUS value from FT_GetDeviceInfoDetail in FTD2XX.DLL
    # param: name: devicelist.
    #        An array of type FT_DEVICE_INFO_NODE to contain the
device information
    #        for all available devices.

    # no idea how to create the fitting parameter FT_DEVICE_INFO_NODE[]
    devicelist_ = ftdi.FT_DEVICE_INFO_NODE() # empty variable to
provide as parameter
    print(devicelist_.Flags, devicelist_.Type, devicelist_.ID,
          devicelist_.LocId, devicelist_.SerialNumber,
          devicelist_.Description, devicelist_.ftHandle)
    # prints
    # 0 0 0 0 None None 0

    status, devicelist = FTDI.GetDeviceList(devicelist_)
    # throws a TypeError: No method matches given arguments

Here <https://gist.github.com/Bovaz/aad3609abb70f23a208a> I found some
c#-code where FT_DEVICE_INFO_NODE[] and GetDeviceList are used in a method:

private int countDevices(){
    ftStatus = myDevice.GetNumberOfDevices(ref ftdiDeviceCount);
    if (ftStatus != FTDI.FT_STATUS.FT_OK)
        return 0;
    if (ftdiDeviceCount > 0)
        //allocate device info list
        ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount];
        //populate list
        ftStatus = myDevice.GetDeviceList(ftdiDeviceList);
        if (ftStatus == FTDI.FT_STATUS.FT_OK)
            return (int)ftdiDeviceCount;
            return 0;
        return 0;}

So my main problem seems to be the transition of ftdiDeviceList = new
FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; to valid python for .NET - code.
It would be great if someone could provide some hints.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20180514/0c7f3d55/attachment-0001.html>

More information about the PythonDotNet mailing list