How to provide a variable of special type as method parameter
Hi, I posted this question at stackoverflow some days ago: https://stackoverflow.com/questions/50254745/how-to-provide-a-variable-of-sp... 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("System") 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 # M:FTD2XX_NET.FTDI.GetDeviceList(FTD2XX_NET.FTDI.FT_DEVICE_INFO_NODE[]) # 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_) print(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(){ FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; 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; } else return 0; } else 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. Thanks Daniel
participants (1)
-
Daniel Krause