Skip to content

Commit 18c4eb3

Browse files
committed
fix device ports
1 parent dd7abe9 commit 18c4eb3

File tree

7 files changed

+113
-41
lines changed

7 files changed

+113
-41
lines changed

test/experiments/comprehensive_protocol/comprehensive_station.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@
730730
"type": "fluid",
731731
"port": {
732732
"multiway_valve_2": "2",
733-
"solenoid_valve_1": "1"
733+
"solenoid_valve_1": "in"
734734
}
735735
},
736736
{
@@ -739,7 +739,7 @@
739739
"target": "vacuum_pump_1",
740740
"type": "fluid",
741741
"port": {
742-
"solenoid_valve_1": "2",
742+
"solenoid_valve_1": "out",
743743
"vacuum_pump_1": "vacuumpump"
744744
}
745745
},
@@ -750,7 +750,7 @@
750750
"type": "fluid",
751751
"port": {
752752
"multiway_valve_2": "3",
753-
"solenoid_valve_2": "1"
753+
"solenoid_valve_2": "in"
754754
}
755755
},
756756
{
@@ -759,7 +759,7 @@
759759
"target": "gas_source_1",
760760
"type": "fluid",
761761
"port": {
762-
"solenoid_valve_2": "2",
762+
"solenoid_valve_2": "out",
763763
"gas_source_1": "gassource"
764764
}
765765
},

test/experiments/mock_reactor.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,39 +122,39 @@
122122
],
123123
"links": [
124124
{
125-
"source": "reactor",
126-
"target": "vacuum_valve",
127-
"type": "physical",
125+
"source": "vacuum_valve",
126+
"target": "reactor",
127+
"type": "fluid",
128128
"port": {
129129
"reactor": "top",
130-
"vacuum_valve": "1"
130+
"vacuum_valve": "out"
131131
}
132132
},
133133
{
134-
"source": "reactor",
135-
"target": "gas_valve",
136-
"type": "physical",
134+
"source": "gas_valve",
135+
"target": "reactor",
136+
"type": "fluid",
137137
"port": {
138138
"reactor": "top",
139-
"gas_valve": "1"
139+
"gas_valve": "out"
140140
}
141141
},
142142
{
143-
"source": "vacuum_pump",
144-
"target": "vacuum_valve",
145-
"type": "physical",
143+
"source": "vacuum_valve",
144+
"target": "vacuum_pump",
145+
"type": "fluid",
146146
"port": {
147147
"vacuum_pump": "out",
148-
"vacuum_valve": "0"
148+
"vacuum_valve": "in"
149149
}
150150
},
151151
{
152-
"source": "gas_source",
153-
"target": "gas_valve",
154-
"type": "physical",
152+
"source": "gas_valve",
153+
"target": "gas_source",
154+
"type": "fluid",
155155
"port": {
156156
"gas_source": "out",
157-
"gas_valve": "0"
157+
"gas_valve": "in"
158158
}
159159
}
160160
]

unilabos/app/register.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import argparse
2+
import time
3+
4+
from unilabos.registry.registry import build_registry
5+
6+
from unilabos.app.main import load_config_from_file
7+
from unilabos.utils.log import logger
8+
9+
10+
def register_devices_and_resources(mqtt_client, lab_registry):
11+
"""
12+
注册设备和资源到 MQTT
13+
"""
14+
logger.info("[UniLab Register] 开始注册设备和资源...")
15+
16+
# 注册设备信息
17+
for device_info in lab_registry.obtain_registry_device_info():
18+
mqtt_client.publish_registry(device_info["id"], device_info)
19+
logger.debug(f"[UniLab Register] 注册设备: {device_info['id']}")
20+
21+
# 注册资源信息
22+
for resource_info in lab_registry.obtain_registry_resource_info():
23+
mqtt_client.publish_registry(resource_info["id"], resource_info)
24+
logger.debug(f"[UniLab Register] 注册资源: {resource_info['id']}")
25+
26+
time.sleep(20)
27+
28+
logger.info("[UniLab Register] 设备和资源注册完成.")
29+
30+
31+
def main():
32+
"""
33+
命令行入口函数
34+
"""
35+
parser = argparse.ArgumentParser(description="注册设备和资源到 MQTT")
36+
parser.add_argument(
37+
"--registry_path",
38+
type=str,
39+
default=None,
40+
action="append",
41+
help="注册表路径",
42+
)
43+
parser.add_argument(
44+
"--config",
45+
type=str,
46+
default=None,
47+
help="配置文件路径,支持.py格式的Python配置文件",
48+
)
49+
args = parser.parse_args()
50+
51+
# 构建注册表
52+
build_registry(args.registry_path)
53+
load_config_from_file(args.config)
54+
55+
from unilabos.app.mq import mqtt_client
56+
from unilabos.registry.registry import lab_registry
57+
58+
# 注册设备和资源
59+
register_devices_and_resources(mqtt_client, lab_registry)
60+
61+
62+
if __name__ == "__main__":
63+
main()

unilabos/registry/devices/pump_and_valve.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ solenoid_valve.mock:
4848
feedback: {}
4949
result: {}
5050
handles:
51-
- handler_key: 0
52-
label: 0
51+
- handler_key: in
52+
label: in
53+
io_type: target
5354
data_type: fluid
5455
side: NORTH
55-
- handler_key: 1
56-
label: 1
56+
- handler_key: out
57+
label: out
58+
io_type: source
5759
data_type: fluid
5860
side: SOUTH
5961
init_param_schema:

unilabos/registry/devices/virtual_device.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ virtual_pump:
107107
success: success
108108
# 虚拟泵节点配置 - 具有多通道阀门特性,根据valve_position可连接多个容器
109109
handles:
110-
- handler_key: pump-inlet
111-
label: Pump Inlet
110+
- handler_key: pumpio
111+
label: pumpio
112112
data_type: fluid
113-
io_type: target
113+
io_type: source
114114
data_source: handle
115115
data_key: fluid_in
116116
description: "泵的进液口,连接源容器"
@@ -168,7 +168,7 @@ virtual_stirrer:
168168
label: stirrer
169169
data_type: mechanical
170170
side: NORTH
171-
io_type: undirected
171+
io_type: source
172172
data_source: handle
173173
data_key: vessel
174174
description: "搅拌器的机械连接口,直接与反应容器连接提供搅拌功能"
@@ -323,19 +323,19 @@ virtual_solenoid_valve:
323323
success: success
324324
# 电磁阀门节点配置 - 双向流通的开关型阀门,流动方向由泵决定
325325
handles:
326-
- handler_key: 1
327-
label: 1
326+
- handler_key: in
327+
label: in
328328
data_type: fluid
329329
side: NORTH
330-
io_type: undirected
330+
io_type: target
331331
data_source: handle
332332
data_key: fluid_port_in
333333
description: "电磁阀的双向流体口,开启时允许流体双向通过,关闭时完全阻断"
334-
- handler_key: 2
335-
label: 2
334+
- handler_key: out
335+
label: out
336336
data_type: fluid
337337
side: SOUTH
338-
io_type: undirected
338+
io_type: source
339339
data_source: handle
340340
data_key: fluid_port_out
341341
description: "电磁阀的双向流体口,开启时允许流体双向通过,关闭时完全阻断"
@@ -391,7 +391,7 @@ virtual_centrifuge:
391391
label: centrifuge
392392
data_type: transport
393393
side: NORTH
394-
io_type: undirected
394+
io_type: target
395395
data_source: handle
396396
data_key: vessel
397397
description: "需要离心的样品容器"
@@ -534,7 +534,7 @@ virtual_heatchill:
534534
label: heatchill
535535
data_type: mechanical
536536
side: NORTH
537-
io_type: undirected
537+
io_type: source
538538
data_source: handle
539539
data_key: vessel
540540
description: "加热/冷却器的物理连接口,容器直接放置在设备上进行温度控制"
@@ -593,7 +593,7 @@ virtual_transfer_pump:
593593
label: transferpump
594594
data_type: fluid
595595
side: SOUTH
596-
io_type: undirected
596+
io_type: source
597597
data_source: handle
598598
data_key: fluid_port
599599
description: "注射器式转移泵的唯一连接口,通过阀门切换实现吸入和排出"
@@ -716,7 +716,7 @@ virtual_rotavap:
716716
label: rotavap-sample
717717
data_type: fluid
718718
side: NORTH
719-
io_type: undirected
719+
io_type: target
720720
data_source: handle
721721
data_key: vessel
722722
description: "样品的双向连接口,可放入需要蒸发的样品,蒸发完成后取出浓缩物"
@@ -787,7 +787,7 @@ virtual_separator:
787787
label: separatorin
788788
data_type: fluid
789789
side: NORTH
790-
io_type: undirected
790+
io_type: target
791791
data_source: handle
792792
data_key: from_vessel
793793
description: "需要分离的混合液体输入口"
@@ -844,7 +844,7 @@ virtual_vacuum_pump:
844844
label: vacuumpump
845845
data_type: fluid
846846
side: SOUTH
847-
io_type: target
847+
io_type: source
848848
data_source: handle
849849
data_key: fluid_in
850850
description: "真空泵进气口,连接需要抽真空的容器或管路"

unilabos/registry/resources/organic/container.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ container:
66
handles:
77
- handler_key: top
88
label: top
9+
io_type: target
910
data_type: fluid
1011
side: NORTH
1112
- handler_key: bottom
1213
label: bottom
14+
io_type: source
1315
data_type: fluid
16+
side: SOUTH
17+
- handler_key: bind
18+
label: bind
19+
io_type: target
20+
data_type: mechanical
1421
side: SOUTH

unilabos/resources/graphio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def modify_to_backend_format(data: list[dict[str, Any]]) -> list[dict[str, Any]]
176176
elif "target_port" in edge:
177177
edge["targetHandle"] = edge.pop("target_port")
178178
if "id" not in edge:
179-
edge["id"] = f"link_generated_{source}_{target}"
179+
edge["id"] = f"reactflow__edge-{edge['sourceHandle']}-{edge['targetHandle']}"
180180
for key in ["source_port", "target_port"]:
181181
if key in edge:
182182
edge.pop(key)

0 commit comments

Comments
 (0)