From 31993594e62ce090a65c03752125a6de3dbac62a Mon Sep 17 00:00:00 2001 From: KCFeng425 <2100011801@stu.pku.edu.cn> Date: Mon, 16 Jun 2025 14:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=9B=BE=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E9=83=BD=E4=BF=AE=E5=A4=8D=E5=A5=BD=E4=BA=86=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86gassource=E5=92=8Cvacuum=20pump=E7=9A=84?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E4=BB=A5=E5=8F=8A=E6=B3=A8=E5=86=8C=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comprehensive_station.json | 4 +- .../devices/virtual/virtual_gas_source.py | 46 +++++++++++ .../devices/virtual/virtual_vacuum_pump.py | 47 +++++++++++ unilabos/registry/devices/virtual_device.yaml | 82 +++++++++++++++++++ 4 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 unilabos/devices/virtual/virtual_gas_source.py create mode 100644 unilabos/devices/virtual/virtual_vacuum_pump.py diff --git a/test/experiments/comprehensive_protocol/comprehensive_station.json b/test/experiments/comprehensive_protocol/comprehensive_station.json index 4fc21db..77d5d0c 100644 --- a/test/experiments/comprehensive_protocol/comprehensive_station.json +++ b/test/experiments/comprehensive_protocol/comprehensive_station.json @@ -486,8 +486,8 @@ "name": "气源", "children": [], "parent": "ComprehensiveProtocolStation", - "type": "container", - "class": "container", + "type": "device", + "class": "virtual_gas_source", "position": { "x": 650, "y": 150, diff --git a/unilabos/devices/virtual/virtual_gas_source.py b/unilabos/devices/virtual/virtual_gas_source.py new file mode 100644 index 0000000..9052882 --- /dev/null +++ b/unilabos/devices/virtual/virtual_gas_source.py @@ -0,0 +1,46 @@ +import time +from typing import Dict, Any, Optional + + +class VirtualGasSource: + """Virtual gas source for testing""" + + def __init__(self, device_id: Optional[str] = None, config: Optional[Dict[str, Any]] = None, **kwargs): + self.device_id = device_id or "unknown_gas_source" + self.config = config or {} + self.data = {} + self._status = "OPEN" + + async def initialize(self) -> bool: + """Initialize virtual gas source""" + self.data.update({ + "status": self._status + }) + return True + + async def cleanup(self) -> bool: + """Cleanup virtual gas source""" + return True + + @property + def status(self) -> str: + return self._status + + def get_status(self) -> str: + return self._status + + def set_status(self, string): + self._status = string + time.sleep(5) + + def open(self): + self._status = "OPEN" + + def close(self): + self._status = "CLOSED" + + def is_open(self): + return self._status + + def is_closed(self): + return not self._status \ No newline at end of file diff --git a/unilabos/devices/virtual/virtual_vacuum_pump.py b/unilabos/devices/virtual/virtual_vacuum_pump.py new file mode 100644 index 0000000..ec355b6 --- /dev/null +++ b/unilabos/devices/virtual/virtual_vacuum_pump.py @@ -0,0 +1,47 @@ +import asyncio +import time +from typing import Dict, Any, Optional + + +class VirtualVacuumPump: + """Virtual vacuum pump for testing""" + + def __init__(self, device_id: Optional[str] = None, config: Optional[Dict[str, Any]] = None, **kwargs): + self.device_id = device_id or "unknown_vacuum_pump" + self.config = config or {} + self.data = {} + self._status = "OPEN" + + async def initialize(self) -> bool: + """Initialize virtual vacuum pump""" + self.data.update({ + "status": self._status + }) + return True + + async def cleanup(self) -> bool: + """Cleanup virtual vacuum pump""" + return True + + @property + def status(self) -> str: + return self._status + + def get_status(self) -> str: + return self._status + + def set_status(self, string): + self._status = string + time.sleep(5) + + def open(self): + self._status = "OPEN" + + def close(self): + self._status = "CLOSED" + + def is_open(self): + return self._status + + def is_closed(self): + return not self._status \ No newline at end of file diff --git a/unilabos/registry/devices/virtual_device.yaml b/unilabos/registry/devices/virtual_device.yaml index 8d9aabc..18492e2 100644 --- a/unilabos/registry/devices/virtual_device.yaml +++ b/unilabos/registry/devices/virtual_device.yaml @@ -802,3 +802,85 @@ virtual_separator: type: boolean default: true additionalProperties: false + +virtual_vacuum_pump: + description: Virtual vacuum pump + class: + module: unilabos.devices.virtual.virtual_vacuum_pump:VirtualVacuumPump + type: python + status_types: + status: String + action_value_mappings: + open: + type: EmptyIn + goal: {} + feedback: {} + result: {} + close: + type: EmptyIn + goal: {} + feedback: {} + result: {} + set_status: + type: StrSingleInput + goal: + string: string + feedback: {} + result: {} + handles: + - handler_key: out + label: out + data_type: fluid + io_type: target + data_source: handle + data_key: fluid_in + init_param_schema: + type: object + properties: + port: + type: string + description: "通信端口" + default: "VIRTUAL" + required: + - port + +virtual_gas_source: + description: Virtual gas source + class: + module: unilabos.devices.virtual.virtual_gas_source:VirtualGasSource + type: python + status_types: + status: String + action_value_mappings: + open: + type: EmptyIn + goal: {} + feedback: {} + result: {} + close: + type: EmptyIn + goal: {} + feedback: {} + result: {} + set_status: + type: StrSingleInput + goal: + string: string + feedback: {} + result: {} + handles: + - handler_key: out + label: out + data_type: fluid + io_type: source + data_source: executor + data_key: fluid_out + init_param_schema: + type: object + properties: + port: + type: string + description: "通信端口" + default: "VIRTUAL" + required: + - port