Tôi muốn gọi hàm bên trong một DLL từ Python. Nhưng tôi nhận được lỗi này:Gọi hàm DLL từ Python
"Attribute Error function not found"
Đây là mã của tôi:
import os
import ctypes
os.chdir("C:\\Program Files\\Compact Automated Testing System V2.0")
# Load DLL into memory.
CATSDll = ctypes.WinDLL ("CATS.dll")
# Set up prototype and parameters for the desired function call.
CATSDllApiProto = ctypes.WINFUNCTYPE (ctypes.c_uint8,ctypes.c_double)
CATSDllApiParams = (1, "p1", 0), (1, "p2", 0),
# Actually map the call (setDACValue) to a Python name.
CATSDllApi = CATSDllApiProto (("setDACValue", CATSDll), CATSDllApiParams)
# Set up the variables and call the Python name with them.
p1 = ctypes.c_uint8 (1)
p2 = ctypes.c_double (4)
CATSDllApi(p1,p2)
nhưng tài liệu DLL cho thấy một hàm setDACValue
với ChannelId
& DAC Voltage
như đầu vào.
Ở trên dựa trên một đoạn mã có sẵn từ StackOverflow.
Tôi cũng đã thử phương pháp đơn giản khi sử dụng cdll.LoadLibrary & rồi gọi hàm, nhưng điều đó cũng cho cùng một lỗi.
Có ai có thể đề xuất tôi điều gì sai không? Cảm ơn.
Full Traceback:
Traceback (most recent call last):
File "C:\Users\AEC_FULL\Softwares\eclipse\plugins\org.python.pydev_3.9.2.201502050007\pysrc\pydevd.py", line 2235, in <module>
globals = debugger.run(setup['file'], None, None)
File "C:\Users\AEC_FULL\Softwares\eclipse\plugins\org.python.pydev_3.9.2.201502050007\pysrc\pydevd.py", line 1661, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Users\AEC_FULL\Saravanan\Workspace\CATS\CATS.py", line 18, in <module>
CATSDllApi = CATSDllApiProto (("setDACValue", CATSDll), CATSDllApiParams)
AttributeError: function 'setDACValue' not found
Bạn có thể cung cấp chữ ký của hàm 'setDACValue'? – kvorobiev
Hi kvorobiev ..added chữ ký .. – user3561075