forked from gary/ems
2
0
Fork 0
sun_ems/python-demo/demoso.py

35 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# 设置函数返回值类型为 doublectypes.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)