diff --git a/.gitignore b/.gitignore index dccff45..395312e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ code/__pycache__ code/testbench.py assets/logs/ assets/configs/io_device_XBC_* -assets/json/safety.safety_area.set_param.json \ No newline at end of file diff --git a/assets/json/safety.safety_area.set_param.json b/assets/json/safety.safety_area.set_param.json new file mode 100644 index 0000000..28b65da --- /dev/null +++ b/assets/json/safety.safety_area.set_param.json @@ -0,0 +1,5 @@ +{ + "c": { + "safety.safety_area.set_param": null + } +} \ No newline at end of file diff --git a/code/common.py b/code/common.py index 6e70abe..7a11560 100644 --- a/code/common.py +++ b/code/common.py @@ -8,7 +8,7 @@ def initialization(): hr = openapi.HmiRequest() pd = openapi.PreDos() # 推送配置文件 - clibs.logger.info("推送配置文件 fieldbus_device.json/registers.json/registers.xml 到控制器,并配置 IO 设备,设备号为 5...") + clibs.logger.info("推送配置文件 fieldbus_device.json/registers.json/registers.xml 到控制器,并配置 IO 设备,设备号为 7...") robot_params = hr.get_robot_params robot_type = robot_params["robot_type"] security_type = robot_params["security_type"] @@ -28,7 +28,7 @@ def initialization(): pd.push_file_to_server(config_file, f"{user_settings}/{filename}") pd.push_file_to_server(config_file, f"{interactive_data}/{filename}") - io_device_autotest = {'ai_num': 0, 'ao_num': 0, 'di_num': 16, 'do_num': 16, 'extend_attr': {'mode': 'slaver', 'name': 'autotest', 'type': 'MODBUS'}, 'id': 5, 'name': 'autotest', 'type': 6} + io_device_autotest = {'ai_num': 0, 'ao_num': 0, 'di_num': 16, 'do_num': 16, 'extend_attr': {'mode': 'slaver', 'name': 'autotest', 'type': 'MODBUS'}, 'id': 7, 'name': 'autotest', 'type': 6} io_device_file_local = f"..\\assets\\configs\\{io_device_file}" io_device_file_local_tmp = f"..\\assets\\configs\\{io_device_file}_tmp" io_device_file_remote = f"{user_settings}/{io_device_file}" diff --git a/code/openapi.py b/code/openapi.py index 049ee46..97122a9 100644 --- a/code/openapi.py +++ b/code/openapi.py @@ -1,4 +1,4 @@ -from json import load, dumps, loads, dump +from json import load, dumps, loads from os import listdir from inspect import currentframe from socket import socket, AF_INET, SOCK_STREAM @@ -783,6 +783,8 @@ class HmiRequest(object): case "safety.safety_area.safety_area_enable": req["c"]["safety.safety_area.safety_area_enable"]["id"] = kwargs["id"] req["c"]["safety.safety_area.safety_area_enable"]["enable"] = kwargs["enable"] + case "safety.safety_area.set_param": + req["c"]["safety.safety_area.set_param"] = kwargs["data"] case _: pass @@ -1474,13 +1476,13 @@ class HmiRequest(object): :param percent: 0-200,整机灵敏度百分比 :return: """ - res = self.get_collision_params - keys = res.keys() + data = self.get_collision_params + keys = data.keys() kwargs.update({"enable": enable, "mode": mode, "action": action, "percent": percent}) for _ in keys: if _ in kwargs.keys(): - res[_] = kwargs[_] - self.execution("collision.set_params", data=res) + data[_] = kwargs[_] + self.execution("collision.set_params", data=data) def set_collision_state(self, collision_state: bool): """ @@ -1719,7 +1721,7 @@ class HmiRequest(object): """ self.execution("safety.safety_area.safety_area_enable", protocol_flag=1, id=id, enable=enable) - def set_safety_area_param(self, id: int, enable: bool, **kwargs): # 不生效,待确认 + def set_safety_area_param(self, id: int, enable: bool, **kwargs): """ 设定单独安全区的参数 :param id: 安全区 id @@ -1727,15 +1729,13 @@ class HmiRequest(object): :param kwargs: 其他参数,参考 get_safety_area_params 的返回值形式 :return: None """ - res = self.get_safety_area_params["g"]["safety_area_data"]["safety_area_setting"][id] - keys = res.keys() + data = self.get_safety_area_params["g"]["safety_area_data"]["safety_area_setting"][id] + keys = data.keys() kwargs.update({"id": id, "enable": enable}) for _ in keys: if _ in kwargs.keys(): - res[_] = kwargs[_] - with open(f"{clibs.PREFIX}/json/safety.safety_area.set_param.json", mode="w", encoding="utf-8") as f: - dump({"c": {"safety.safety_area.set_param": res}}, f, indent=4) - self.execution("safety.safety_area.set_param", protocol_flag=1) + data[_] = kwargs[_] + self.execution("safety.safety_area.set_param", protocol_flag=1, data=data) self.execution("safety.safety_area.safety_area_enable", protocol_flag=1, id=id, enable=enable) @property