Skip to content

Commit 71107e9

Browse files
committed
use gitee to install pylabrobot
fix virtual import
1 parent 1ad4766 commit 71107e9

6 files changed

Lines changed: 57 additions & 32 deletions

File tree

unilabos/app/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
import networkx as nx
1313
import yaml
1414

15+
# Windows 中文系统 stdout 默认 GBK,无法编码 banner / emoji 日志中的 Unicode 字符
16+
# 强制 stdout/stderr 用 UTF-8,避免 print 触发 UnicodeEncodeError 导致进程崩溃
17+
if sys.platform == "win32":
18+
for _stream in (sys.stdout, sys.stderr):
19+
try:
20+
_stream.reconfigure(encoding="utf-8", errors="replace") # type: ignore[attr-defined]
21+
except (AttributeError, OSError):
22+
pass
23+
1524
# 首先添加项目根目录到路径
1625
current_dir = os.path.dirname(os.path.abspath(__file__))
1726
unilabos_dir = os.path.dirname(os.path.dirname(current_dir))

unilabos/devices/virtual/virtual_multiway_valve.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import logging
33
from typing import Union, Dict, Optional
44

5+
from unilabos.registry.decorators import topic_config
6+
57

68
class VirtualMultiwayValve:
79
"""
@@ -41,13 +43,11 @@ def current_position(self) -> int:
4143
def target_position(self) -> int:
4244
return self._target_position
4345

44-
def get_current_position(self) -> int:
45-
"""获取当前阀门位置 📍"""
46-
return self._current_position
47-
48-
def get_current_port(self) -> str:
49-
"""获取当前连接的端口名称 🔌"""
50-
return self._current_position
46+
@property
47+
@topic_config()
48+
def current_port(self) -> str:
49+
"""当前连接的端口名称 🔌"""
50+
return self.port
5151

5252
def set_position(self, command: Union[int, str]):
5353
"""
@@ -169,12 +169,14 @@ def close(self):
169169
self._status = "Idle"
170170
self._valve_state = "Closed"
171171

172-
close_msg = f"🔒 阀门已关闭,保持在位置 {self._current_position} ({self.get_current_port()})"
172+
close_msg = f"🔒 阀门已关闭,保持在位置 {self._current_position} ({self.port})"
173173
self.logger.info(close_msg)
174174
return close_msg
175175

176-
def get_valve_position(self) -> int:
177-
"""获取阀门位置 - 兼容性方法 📍"""
176+
@property
177+
@topic_config()
178+
def valve_position(self) -> int:
179+
"""阀门位置 📍"""
178180
return self._current_position
179181

180182
def set_valve_position(self, command: Union[int, str]):
@@ -229,19 +231,16 @@ def switch_between_pump_and_port(self, port_number: int):
229231
self.logger.info(f"🔄 从端口 {self._current_position} 切换到泵位置...")
230232
return self.set_to_pump_position()
231233

232-
def get_flow_path(self) -> str:
233-
"""获取当前流路路径描述 🌊"""
234-
current_port = self.get_current_port()
234+
@property
235+
@topic_config()
236+
def flow_path(self) -> str:
237+
"""当前流路路径描述 🌊"""
235238
if self._current_position == 0:
236-
flow_path = f"🚰 转移泵已连接 (位置 {self._current_position})"
237-
else:
238-
flow_path = f"🔌 端口 {self._current_position} 已连接 ({current_port})"
239-
240-
# 删除debug日志:self.logger.debug(f"🌊 当前流路: {flow_path}")
241-
return flow_path
239+
return f"🚰 转移泵已连接 (位置 {self._current_position})"
240+
return f"🔌 端口 {self._current_position} 已连接 ({self.current_port})"
242241

243242
def __str__(self):
244-
current_port = self.get_current_port()
243+
current_port = self.current_port
245244
status_emoji = "✅" if self._status == "Idle" else "🔄" if self._status == "Busy" else "❌"
246245

247246
return f"🔄 VirtualMultiwayValve({status_emoji} 位置: {self._current_position}/{self.max_positions}, 端口: {current_port}, 状态: {self._status})"
@@ -253,7 +252,7 @@ def __str__(self):
253252

254253
print("🔄 === 虚拟九通阀门测试 === ✨")
255254
print(f"🏠 初始状态: {valve}")
256-
print(f"🌊 当前流路: {valve.get_flow_path()}")
255+
print(f"🌊 当前流路: {valve.flow_path}")
257256

258257
# 切换到试剂瓶1(1号位)
259258
print(f"\n🔌 切换到1号位: {valve.set_position(1)}")

unilabos/devices/virtual/virtual_stirrer.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time as time_module
44
from typing import Dict, Any
55

6+
from unilabos.registry.decorators import topic_config
67
from unilabos.ros.nodes.base_device_node import BaseROS2DeviceNode
78

89
class VirtualStirrer:
@@ -314,9 +315,11 @@ def max_speed(self) -> float:
314315
def min_speed(self) -> float:
315316
return self._min_speed
316317

317-
def get_device_info(self) -> Dict[str, Any]:
318-
"""获取设备状态信息 📊"""
319-
info = {
318+
@property
319+
@topic_config()
320+
def device_info(self) -> Dict[str, Any]:
321+
"""设备状态快照信息 📊"""
322+
return {
320323
"device_id": self.device_id,
321324
"status": self.status,
322325
"operation_mode": self.operation_mode,
@@ -325,12 +328,9 @@ def get_device_info(self) -> Dict[str, Any]:
325328
"is_stirring": self.is_stirring,
326329
"remaining_time": self.remaining_time,
327330
"max_speed": self._max_speed,
328-
"min_speed": self._min_speed
331+
"min_speed": self._min_speed,
329332
}
330-
331-
# self.logger.debug(f"📊 设备信息: 模式={self.operation_mode}, 速度={self.current_speed} RPM, 搅拌={self.is_stirring}")
332-
return info
333-
333+
334334
def __str__(self):
335335
status_emoji = "✅" if self.operation_mode == "Idle" else "🌪️" if self.operation_mode == "Stirring" else "🛑" if self.operation_mode == "Settling" else "❌"
336336
return f"🌪️ VirtualStirrer({status_emoji} {self.device_id}: {self.operation_mode}, {self.current_speed} RPM)"

unilabos/devices/virtual/virtual_transferpump.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Union, Optional
55
import logging
66

7+
from unilabos.registry.decorators import topic_config
78
from unilabos.ros.nodes.base_device_node import BaseROS2DeviceNode
89

910

@@ -385,8 +386,10 @@ def get_current_volume(self) -> float:
385386
"""获取当前体积"""
386387
return self._current_volume
387388

388-
def get_remaining_capacity(self) -> float:
389-
"""获取剩余容量"""
389+
@property
390+
@topic_config()
391+
def remaining_capacity(self) -> float:
392+
"""剩余容量 (ml)"""
390393
return self.max_volume - self._current_volume
391394

392395
def is_empty(self) -> bool:

unilabos/registry/devices/virtual_device.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3960,6 +3960,14 @@ virtual_separator:
39603960
io_type: source
39613961
label: bottom_phase_out
39623962
side: SOUTH
3963+
- data_key: top_outlet
3964+
data_source: executor
3965+
data_type: fluid
3966+
description: 上相(轻相)液体输出口
3967+
handler_key: topphaseout
3968+
io_type: source
3969+
label: top_phase_out
3970+
side: NORTH
39633971
- data_key: mechanical_port
39643972
data_source: handle
39653973
data_type: mechanical

unilabos/utils/environment_check.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ def __init__(self):
188188
"crcmod": "crcmod-plus",
189189
}
190190

191-
self.special_packages = {"pylabrobot": "git+https://github.com/Xuwznln/pylabrobot.git"}
191+
# 中文 locale 下走 Gitee 镜像,规避 GitHub 拉取失败
192+
pylabrobot_url = (
193+
"git+https://gitee.com/xuwznln/pylabrobot.git"
194+
if _is_chinese_locale()
195+
else "git+https://github.com/Xuwznln/pylabrobot.git"
196+
)
197+
self.special_packages = {"pylabrobot": pylabrobot_url}
192198

193199
self.version_requirements = {
194200
"msgcenterpy": "0.1.8",

0 commit comments

Comments
 (0)