import ctypes import time import os # 加载当前目录下的 so 文件 so_path = os.path.abspath("/usr/lib/aarch64-linux-gnu/libcrtdb.so") mylib = ctypes.CDLL(so_path) # 声明函数原型(如果有参数和返回值的话需要详细定义) mylib.initRtdb(0, 0, 1); # 返回值为 void # 设置函数返回值类型为 double(ctypes.c_double) mylib.getRtdbPointValue.restype = ctypes.c_double # 定义参数类型(函数没有返回值,所以 restype 可以不写) mylib.setRtdbPointValue.argtypes = [ ctypes.c_int, # rtdb_type_e -> int ctypes.c_uint16, # devType ctypes.c_uint16, # devId ctypes.c_uint16, # pointId ctypes.c_double # value ] # 每隔1秒调用一次 while True: value = mylib.getRtdbPointValue(0, 0, 0, 7); print(f"Double value: {value}") i_val = int(value) print(f" 心跳 Int value: {i_val}") mylib.setRtdbPointValue(0, 0, 0, 1, 7.0); val = mylib.getRtdbPointValue(0, 0, 0, 1); print(f"读取写入的值为: {val}") time.sleep(1)