pythonfor.NET:如何提供一个特殊类型的变量(FTDI.FT_设备信息节点[])作为方法参数

2024-06-09 01:57:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在pythonfor.NET(pythonnet)的帮助下使用DLL。 此DLL中的方法需要(指针指向?)变量作为参数。在

我可以想出如何调用方法并提供一个整型变量作为参数。在

如果需要特殊类型(这里是FTD2XX),我不知道如何提供这样的参数变量_NET.FTDI.FT设备信息节点[]). 在

当使用调用FTDI.GetDeviceList的不同变体(其中一些技术上是相同的)时,我得到了不同类型的类型错误:

类型错误:没有与给定参数匹配的方法

  • FTDI.GetDeviceList([ftdi.FT_DEVICE_INFO_NODE()][:])
  • FTDI.GetDeviceList(ftdi.FT_DEVICE_INFO_NODE)
  • FTDI.GetDeviceList(ftdi.FT_DEVICE_INFO_NODE())
  • FTDI.GetDeviceList(ftdi.FT_DEVICE_INFO_NODE(device_count))
  • FTDI.GetDeviceList([devicelist_])
  • FTDI.GetDeviceList(devicelist_)

类型错误:无法编制索引的对象

  • FTDI.GetDeviceList(ftdi.FT_DEVICE_INFO_NODE()[:])

类型错误:需要类型

  • FTDI.GetDeviceList(ftdi.FT_DEVICE_INFO_NODE[:])

  • FTDI.GetDeviceList(ftdi.FT_DEVICE_INFO_NODE[1])

  • FTDI.GetDeviceList(ftdi.FT_DEVICE_INFO_NODE[0])

下面是代码摘要,结果:

import clr
import 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 FTDI
from 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我发现了一些c代码,其中FT_DEVICE_INFO_NODE[]和GetDeviceList用于某个方法:

^{pr2}$

提供FTDI.FT_DEVICE_INFO_NODE[]作为FTDI.GetDeviceList的参数,我遗漏了什么?在

FTDI的USB驱动程序下载在这里:http://www.ftdichip.com/Drivers/D2XX.htm,而.Net包装器是从这里下载的:http://www.ftdichip.com/Support/SoftwareExamples/CodeExamples/CSharp.htm


Tags: theinfonode类型参数netversiondevice
1条回答
网友
1楼 · 发布于 2024-06-09 01:57:04

源代码需要包含FT_DEVICE_INFO_节点的列表。以下是函数声明:

public FTDI.FT_STATUS GetDeviceList(FTDI.FT_DEVICE_INFO_NODE[] devicelist)

这个代码对我有用:

^{pr2}$

最后,我放弃了这个函数,因为我无法让它返回我想要的,而是在打开我想从中获取信息的设备后分别使用了“GetDeviceID”、“GetDescription”和“GetSerialNumber”函数。在

示例:

^{3}$

相关问题 更多 >