【问题标题】:Using OWdotNET.dll in pythonnet (python for .NET)在 pythonnet 中使用 OWdotNET.dll (python for .NET)
【发布时间】:2012-04-04 12:50:59
【问题描述】:

我的办公桌上有一个 USB 转单线适配器,我想自动使用它。我用它来编程 dallaskeys,这是通过单线编程和读取的徽章。

有一个提供 API 的托管 DLL,我喜欢 python,所以我想使用这个来自“python for .NET”又名 pythonnet 的第三方托管 DLL。

我的脚本如下所示,运行没有问题:

import os
import clr
from clr import System

oneWireLibrary = clr.FindAssembly("OWdotNET")
System.Reflection.Assembly.LoadFile(os.path.abspath(oneWireLibrary))

但是,我不知道如何使用库中的类。我试过clr.OWdotNET 但这给了我一个属性错误。 我也试过clr.AddReference("OWdotNET")

链接:

http://files.maxim-ic.com/sia_bu/softdev/owdocs_400beta2/Docs/OW.NET/OW.NET_Primer.html

http://pythonnet.github.io/

【问题讨论】:

    标签: python .net dll ironpython python.net


    【解决方案1】:

    我从 IronPython 的角度回答这个问题,但我相信它在 Python for .NET 中是相似的。

    可以认为 clr.AddReference 调用类似于将 .NET 程序集路径添加到 sys.path,您是在告诉运行时它,但是您仍然需要将命名空间导入当前范围。

    import clr
    clr.AddReference("OWdotNET")
    from com.dalsemi.onewire import OneWireAccessProvider
    
    adapter = OneWireAccessProvider.getDefaultAdapter()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      相关资源
      最近更新 更多