## 自动化测试工具脚本

### 0. 用前须知

1. 调用必须在rokae目录下执行
2. python3.13开发，使用时需版本匹配，并安装requirements.txt中的依赖库

### 1. socket通信（支持xService）

> #### **A. 调用方法示例**

```python
from codes import openapi
import time

hr = openapi.HmiRequest()
time.sleep(2)
hr.close()
msg_id = hr.exec_cmd("controller.get_params")
record = hr.get_from_id(msg_id)
print(f"version = {eval(record)['data']['version']}")
```

> #### **B. 目前支持（后续可按需增加）**

```
collision.get_params
collision.set_params
controller.get_params
controller.heart
controller.reboot
controller.set_params
device.get_params
diagnosis.get_params
diagnosis.open
diagnosis.save
diagnosis.set_params
drag.get_params
drag.set_params
fieldbus_device.get_params
fieldbus_device.load_cfg
fieldbus_device.set_params
io_device.load_cfg
jog.get_params
jog.set_params
jog.start
log_code.data.code_list
log_code.data
modbus.get_params
modbus.get_values
modbus.load_cfg
modbus.set_params
move.get_joint_pos
move.get_monitor_cfg
move.get_params
move.get_pos
move.get_quickstop_distance
move.get_quickturn_pos
move.quick_turn
move.set_monitor_cfg
move.set_params
move.set_quickstop_distance
move.set_quickturn_pos
move.stop
overview.get_autoload
overview.get_cur_prj
overview.reload
overview.set_autoload
register.set_value
rl_task.pp_to_main
rl_task.run
rl_task.set_run_params
rl_task.stop
safety.safety_area.overall_enable
safety.safety_area.safety_area_enable
safety.safety_area.set_param
safety.safety_area.signal_enable
safety_area_data
servo.clear_alarm
socket.get_params
socket.set_params
soft_limit.get_params
soft_limit.set_params
state.get_state
state.get_tp_mode
state.set_tp_mode
state.switch_auto
state.switch_manual
state.switch_motor_off
state.switch_motor_on
system_io.query_configuration
system_io.query_event_cfg
system_io.update_configuration
```

### 2. modbus通信

> #### **A. 调用方法示例**

```python
from codes import openapi

md = openapi.ModbusRequest()
md.r_switch_auto()
_ = md.w_sta_tcp_vel
print(_)
```

> #### **B. 目前支持**

自定义的寄存器读写操作，以及98%以上的预置modbus功能码。

### 3. 外部通信

> #### **A. 调用方法示例**

```python
from codes import openapi

ec = openapi.EcRequest()
_ = ec.get_cart_pos
ec.close_reduced_mode()
```

> #### **B. 目前支持**

包括状态和控制操作，覆盖98%以上的外部通信功能。

### 4. 文件传输

> #### **A. 调用方法示例**

```python
from codes import openapi

pd = openapi.PreDos()
downloads = "C:/Users/Administrator/Downloads"
pd.pull_prj_from_server("aio", downloads)
local_prj = downloads + "/aio.zip"
pd.push_prj_to_server(local_prj)

local_file = downloads + "/aio.txt"
server_file = "/tmp/aio.txt"
pd.push_file_to_server(local_file, server_file)
pd.pull_file_from_server(server_file, local_file)
```

> #### **B. 目前支持（除了prj_name为工程名，其他均为对应系统下的绝对路径）**

- push_prj_to_server(prj_file)
- pull_prj_from_server(prj_name, local_prj_path)
- push_file_to_server(local_file, server_file)
- pull_file_from_server(server_file, local_file)

### 5. 初始化以及固件更新

> #### **A. 调用方法示例**

```python
from codes import openapi

ri = openapi.RobotInit()
ri.robot_init()
ri.fw_updater("C:/Users/Administrator/Downloads/FW/v3.1.1.rpa")
ri.fw_updater("C:/Users/Administrator/Downloads/XMS3-R580-W4G3C2_ME_AE_SS_xC.v3.1.0.R0.rpa")
```

> #### **B. 目前支持**

- robot_init()         # 初始化机器人，新建modbus设备，并配置寄存器文件，打开IO设备中的modbus设备  
- fw_updater(fw_file)  # 目前仅测试支持机型文件和控制器

### 6. 升级协议

> #### **A. 调用方法示例**

```python
from codes import openapi

ur = openapi.UpgradeRequest()
ur.version_query()
ur.robot_reboot()
```

> #### **B. 目前支持**

- erase_cfg
- clear_rubbish
- soft_reboot
- version_query
- robot_reboot
- backup_origin
- origin_recovery

### 7. 生成运动轨迹

> #### **A. 调用方法示例**

```python
from codes import openapi

hr = openapi.HmiRequest()
pd = openapi.PreDos()            # 如下三行首次运行时，必须打开
ri = openapi.RobotInit(hr, pd)   # 非首次重复运行时，可以注释
ri.robot_init()                  # 注释后可以节省运行时间
md = openapi.ModbusRequest()

pt = openapi.PlotTrajectory(hr, md, prj_name="arc_test_M", tasks=["task0", ], curve_name="hw_cart_pos_feedback_tcp_in_world")
pt.draw_traj()
```

> #### **B. 目前支持**

自动保存3D空间运动曲线图到本地的trajectory.html文件

- hw_cart_pos_feedback_motorside
- hw_cart_pos_feedback_linkside
- hw_cart_pos_feedback_encoder_tcp_in_world
- hw_cart_pos_feedback_flan_in_world
- hw_cart_pos_feedback_tcp_in_world
