Python 提升AttributeError(名称)AttributeError:LCC_GetChannelHandle
我是python cffi的新手。我必须使用其索引或通道名称访问我的温度模块。正如你们在我的QmixTC课程中看到的,我正在尝试这两种方法。我得到属性错误。在另一个类中,没有错误。有人能帮我理解问题出在哪里吗。我把我的代码以及错误跟踪。谢谢Python 提升AttributeError(名称)AttributeError:LCC_GetChannelHandle,python,python-2.7,spyder,python-cffi,Python,Python 2.7,Spyder,Python Cffi,我是python cffi的新手。我必须使用其索引或通道名称访问我的温度模块。正如你们在我的QmixTC课程中看到的,我正在尝试这两种方法。我得到属性错误。在另一个类中,没有错误。有人能帮我理解问题出在哪里吗。我把我的代码以及错误跟踪。谢谢 main code with name qmix.py (importing it in to sample code): class QmixTC (object): """ """ def __init__(self, index=0, hand
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)
示例程序:
from __future__ import division, print_function
from win32api import GetSystemMetrics
import numpy as np
import os
import qmix
import pandas as pd
#%% CHANNEL INITIALIZATION
if __name__ == '__main__':
dll_dir = ('C:\\Users\\Ravikumar\\AppData\\Local\\QmixSDK')
config_dir = ('C:\\Users\\Public\\Documents\\QmixElements\\Projects\\QmixTC_test1\\Configurations\\QmixTC_test1')
qmix_bus = qmix.QmixBus(config_dir=config_dir,dll_dir=dll_dir)
qmix_bus.open()
qmix_bus.start()
controller_0 = qmix.QmixTC(index=0)
controller_0.Setpoint_write(50)
错误:
回溯(最近一次呼叫最后一次):
文件“”,第17行,在
控制器0=qmix.QmixTC(索引=0)
文件“qmix.py”,第921行,在_init中__
self.\u调用('LCC\u GetChannelHandle',self.index,self.\u handle)
调用中第937行的文件“qmix.py”
func=getattr(self.\u dll,func\u name)
文件“C:\Users\Ravikumar\Anaconda2\lib\site packages\cffi\api.py”,第875行,在u getattr中__
make_访问器(名称)
文件“C:\Users\Ravikumar\Anaconda2\lib\site packages\cffi\api.py”,第870行,在make\u访问器中
提升属性错误(名称)
AttributeError:LCC_GetChannelHandle
dll不提供“LCC\u GetChannelHandle”方法。请检查它是否提供了确切的名称并修复您的调用。@PatrickArtner我的问题已解决。标题定义中有一个脚本(函数声明)问题,这里没有。我正在将该定义导入self.\u ffi.cdef(CONTROLLER\u HEADER)。关于dll不提供方法“LCC_GetChannelHandle”,您是对的。
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