Domanda

I have a USB to one-wire adapter on my desk, I would like to automate the use of it. I use it for programming dallaskeys, which are badges that are programmed and read over onewire.

There is a managed DLL that offers an API, I love python so I would like to use this third party managed DLL from "python for .NET" aka pythonnet.

My script looks as follows, and runs without problems:

import os
import clr
from clr import System

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

BUT, I can not figure out how to use the classes in the library. I have tried clr.OWdotNET but that gives me an attribute error. I have tried clr.AddReference("OWdotNET") as well.

Links:

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

http://pythonnet.github.io/

È stato utile?

Soluzione

I'm answering this from the viewpoint of IronPython, but I believe it is similar in Python for .NET.

The clr.AddReference call can be thought of as similar to adding the .NET assembly path to sys.path, you are telling the runtime about it, but then you still need to import the namespace into the current scope.

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

adapter = OneWireAccessProvider.getDefaultAdapter()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top