RTScale 产品使用手册Inscope 自动化使用手册

Inscope 自动化使用手册 教程

Inscope自动化内核基于gRPC开发,因此运行需要先安装如下python库

以下为调用接口,采用面向对象的方式开发。

初始化

from inscope_client import InscopeClient
# 连接到本地服务
client = InscopeClient()
# 连接到远程服务
client = InscopeClient(host='192.168.1.100', port=50051)
# 关闭连接
client.close()

连接管理

connect(ip_address="", port=0, wait_timeout=5)

连接到目标设备 参数:

返回: bool

client.connect("192.168.1.10", 5555, wait_timeout=10)

disconnect()

断开连接 返回: bool

测量信号

get_measurements()

获取所有测量信号 返回: list - 测量信号对象列表

measurements = client.get_measurements()
for m in measurements:
    print(f"{m.id}: {m.name}")

read_measurement_value()

读取测量信号的瞬时值(单点采样) 发送命令到目标设备,立即读取当前时刻的信号值并返回。 返回: int 或 float: 信号当前值,失败返回 None

#示例
client = InscopeClient()
client.connect("192.168.1.10", 5555)
client.read_measurement_value('Sinewave1')

波形窗口

波形通过在仪表盘界面手动放置 Waveform 控件来创建,并在控件属性中设置唯一的标题;自动化接口通过该标题来定位对应的波形。

get_windows()

获取仪表盘上所有波形控件 返回: list[tuple] - [(window_id, window_title), ...],其中 window_title 为波形控件标题(录制等接口均通过标题定位)

windows = client.get_windows()
for wid, title in windows:
    print(title)

模型控制

start_model()

启动模型 返回: bool

stop_model()

停止模型 返回: bool

录制控制

start_recording(window_title, file_name="")

启动波形录制(输出 CSV) 参数:

返回: bool

stop_recording(window_title)

停止波形录制 参数:

返回: bool

项目管理

create_project(project_name, directory, elf_file_path="", bit_file_path="")

创建工程 参数:

save_project(silent=True)

保存项目 参数:

返回: bool

参数管理

get_parameters()

获取所有参数 返回: list - Parameter对象列表

find_parameter(parameter_name)

查找参数 参数:

返回: Parameter 对象或 None

get_parameter_value(parameter_name)

读取参数值(自动类型转换) 参数:

返回: int/floatNone

set_parameter_value(parameter_name, value)

设置参数值(自动类型转换) 参数:

返回: bool

read_parameter(parameter_name)

读取参数原始字节 参数:

返回: bytesNone

set_parameter(parameter_name, value_bytes)

设置参数原始字节 参数:

返回: bool

# 示例:参数操作
params = client.get_parameters()
print(f"总共 {len(params)} 个参数")
# 查找并读取
param = client.find_parameter("engine_speed")
current_value = client.get_parameter_value("engine_speed")
print(f"当前值: {current_value}")
# 设置新值
client.set_parameter_value("engine_speed", 3000.0)

完整示例

from inscope_client import InscopeClient
import time
client = InscopeClient('localhost', 50051)
try:
    # 连接设备
    if not client.connect("192.168.1.10", 5555):
        exit(1)
    # 获取仪表盘上已放置的波形控件
    # (需提前在界面中放置 Waveform 控件,设置标题并绑定曲线)
    windows = client.get_windows()
    if not windows:
        print("请先在仪表盘上放置 Waveform 控件并设置标题")
        exit(1)
    wid, title = windows[0]
    # 启动模型和录制
    client.start_model()
    client.start_recording(title, "C:/data/recording.csv")
    # 运行10秒
    time.sleep(10)
    # 停止录制和模型
    client.stop_recording(title)
    client.stop_model()
    # 保存项目
    client.save_project(silent=True)
    # 断开连接
    client.disconnect()
finally:
    client.close()