0

我使用 pyVisa 与 OSA 进行通信。在我移动文件夹中的文件以获得更好的结构后,没有任何效果了。结构为:ProjektFolder -> Includes -> VisaInstrument.py 和 ProjektFolder -> Instrument -> osa.py

在 VisaInstrument.py 中,代码如下:

import pyvisa
...
class VisaInstrument():

    def __init__(self, resource):
         self.rm = pyvisa.ResourceManager()
         self.resource = resource
         self.instr = self.rm.open_resource(self.resource)
         logging.debug('New lab object (resource %s) created.' % self.resource)

并在 osa.py

from Includes import VisaInstrument
...
class osa(VisaInstrument.VisaInstrument):


    def __init__(self, resource):
        VisaInstrument.__init__(self, resource)

当我尝试像这样初始化 osa 时(在不同的文件中):

from Instrument import osa
osaControl = osa.osa('GPIB0::14::INSTR')

我收到以下错误消息:

回溯(最近一次通话最后):

文件“”,第 1 行,在

文件“C:\python\ProjektFolder\Instrument\osa.py”,第 40 行,在init

签证仪器。初始化(自我,资源)

TypeError: module() 参数 1 必须是 str,而不是 osa

使用 init 显示在代码中不是粗体

谁能告诉我我的错误是什么?

4

1 回答 1

0

问题是:我没有在 osa 类中正确调用 VisaInstrument

from Includes import VisaInstrument
...
class osa(VisaInstrument.VisaInstrument):


    def __init__(self, resource):
        VisaInstrument.VisaInstrument.__init__(self, resource)
             ^this was missing
于 2020-01-24T11:33:22.787 回答