我当然希望这不是一个已经回答的问题或一个愚蠢的问题。最近我一直在用几种仪器编程。尝试在它们之间进行通信以创建测试程序。但是,当我尝试调用从仪器 DLL 文件中“屏蔽”出来的函数时,我遇到了一些特定仪器的问题。当我使用交互式 python shell 时,它可以完美运行(尽管它有很多单词破坏)。但是当我以面向对象的方式实现这些功能时,程序失败了,实际上它并没有失败,它只是什么都不做。这是第一个调用的方法:(导入了 ctypes 和 ctypes.util)
def init_hardware(self):
""" Inits the instrument """
self.write_log("Initialising the automatic tuner")
version_string = create_string_buffer(80)
self.error_string = create_string_buffer(80)
self.name = "Maury MT982EU"
self.write_log("Tuner DLL path: %s", find_library('MLibTuners'))
self.maury = WinDLL('MlibTuners')
self.maury.get_tuner_driver_version(version_string)
if (version_string.value == ""):
self.write_log("IMPORTANT: Error obtaining the driver version")
else:
self.write_log("Version number of the DLL: %s" % version_string.value)
self.ThreeTypeLong = c_long * 3
现在效果很好,一切都很完美,我得到了完美的日志条目。但是当我尝试在程序中进一步运行一个方法时,调用:
def add_tuner_and_controller(self, name, serial_number, tuner_number=0):
""" Adds the tuner to the driver object, controller is inside the tuner """
self.write_log("Adding tuner %d and the built-in controller" % tuner_number)
TempType = self.ThreeTypeLong()
self.maury.add_controller(c_short(tuner_number), c_char_p(self.file_path), c_char_p(name), c_int(0), c_int(0),
c_long(0), c_short(serial_number), self.error_string)
self.maury.add_tuner(c_short(tuner_number), c_char_p(name), c_short(serial_number), c_short(0),
c_short(1), pointer(c_double()), TempType, pointer(c_double()), pointer(c_double()),
pointer(c_double()), self.error_string)
程序突然停止工作/继续运行,调用“self.maury”行时没有任何反应。当我将所有内容都放在 init_hardware 方法中时,它可以完美运行,所以我猜测存在轻微的内存“错误”或面向目标的结构。我真的希望它保持这种状态,无论如何以这种方式隔离功能?还是我必须将自己限制在一大段代码中?
编辑:
文档信息:
[图例:星号表示指针,括号表示数组]
add_tuner 函数在调谐器驱动程序对象中添加或更新一个调谐器。
short add_tuner(short tuner_number, char model[ ], short serial_number, short ctlr_num, short ctlr_port, short *no_of_motors, long max_range[ ], double *fmin, double *fmax, double *fcrossover, char error_string[ ])
输出:no_motors, max_range (array of three numbers), fmin, fmax, fcrossover,error_string (80+ characters long), function-return->Error flag
add_controller 函数在调谐器驱动对象中添加或更新一个控制器
short add_controller(short controller_number, char driver[ ], char model[ ], int timeout, int address, long delay_ms, char error_string[ ])
输出:error_string, function-return->Error flag