引发AttributeError(名称)AttributeError:LCC\GetChannelHand

2024-06-16 10:21:26 发布

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

我对python-cffi非常陌生。我必须使用temperature模块的索引或通道名来访问它。正如你在我的QmixTC课上看到的,我正在尝试两者。我得到属性错误。在另一个类中,没有错误。有人能帮我了解问题出在哪里吗。我把我的代码和错误跟踪。谢谢。在

main code with name qmix.py (importing it in to sample code): 

class QmixTC (object): 
"""

"""
def __init__(self, index=0, handle=None,name=''):

    self.dll_dir = DLL_DIR
    self.dll_file = os.path.join(self.dll_dir,
                             'labbCAN_Controller_API.dll')
    self._ffi = FFI()
    self._ffi.cdef(CONTROLLER_HEADER)

    self._dll = self._ffi.dlopen(self.dll_file)
    self._handle = self._ffi.new('dev_hdl *', 0)

    if handle is None:
        self.index = index
        self._handle = self._ffi.new('dev_hdl *', 0)
        self._call('LCC_GetChannelHandle', self.index, self._handle)
    else:
        self.index = None
        self._handle = handle



    self._ch_name="QmixTC_1_DO0_INA"
    self._channel = self._ch_name + str(index) 
    self._call('LCC_LookupChanByName',
               bytes(self._channel,'utf8'),
               self._handle)

    self.name = name

def _call(self, func_name, *args):
    func = getattr(self._dll, func_name)
    r = func(*args)
    r = CHK(r, func_name, *args)
    return r  

def Setpoint_write (self, setpoint): 
    """
    Write setpoint value to controller device.
    Parameters
        [in]    ChanHdl Valid handle of open controller channel
        [in]    fSetPointValue  The setpoint value to write
    Returns
        Error code - ERR_NOERR indicates success
    """
    self._call('LCC_WriteSetPoint', self._handle[0], setpoint) 

def enable_controllLoop (self, enable): 
      """
      Enables / disables a control loop.
      If the control loop is enabled, then the output value is calculated periodically.
      Parameters
          ChanHdl   Valid handle of a controller channel
          Enable    1 = enable, 0 = disable
      Returns
          Error code - ERR_NOERR indicates success
     """
      self._call('LCC_EnableControlLoop', self._handle[0], enable) 

def read_temp_value  (self, actualvalue):
     """
     Read actual value from device.
     Parameters
         [in]   ChanHdl Valid handle of open controller channel
         [out]  pfActualValue   Returns the actual controller value
     Returns
        Error code - ERR_NOERR indicates success
     """
     self._call('LCC_ReadActualValue', self._handle[0], actualvalue)  

if __name__ == '__main__':
import os.path as op

dll_dir = op.normpath('C:\\Users\\Ravikumar\\AppData\\Local\\QmixSDK')
config_dir = op.normpath('C:\\Users\\Public\\Documents\\QmixElements\\Projects\\QmixTC_Pump\\Configurations\\QmixTC_pump')

bus = QmixBus(config_dir=config_dir)
bus.open()
bus.start()

controller_0 = QmixTC(index=0) 
controller_0.enable_controllLoop(1)  

示例程序:

^{pr2}$

错误: 回溯(最近一次呼叫):

File "<ipython-input-5-40d4a3db9493>", line 17, in <module>
controller_0 = qmix.QmixTC(index=0)

File "qmix.py", line 921, in __init__
self._call('LCC_GetChannelHandle', self.index, self._handle)

File "qmix.py", line 937, in _call
func = getattr(self._dll, func_name)

 File "C:\Users\Ravikumar\Anaconda2\lib\site-packages\cffi\api.py", line 875, in __getattr__
make_accessor(name)

 File "C:\Users\Ravikumar\Anaconda2\lib\site-packages\cffi\api.py", line 870, in make_accessor
raise AttributeError(name)

AttributeError: LCC_GetChannelHandle

Tags: nameinpyselfindexvaluedircode