27 lines
878 B
Python
27 lines
878 B
Python
# main.py
|
|
from metric_device import DeviceManager
|
|
import time
|
|
|
|
# ✅ 初始化设备(自动单例,避免重复连接)
|
|
scale1 = DeviceManager.get_device("192.168.250.66", 8234, "Line1")
|
|
scale2 = DeviceManager.get_device("192.168.250.63", 502, "Line2")
|
|
|
|
# ✅ 统一 get() 接口获取最新数据
|
|
try:
|
|
for i in range(10000):
|
|
time.sleep(0.01)
|
|
|
|
data1 = scale1.get() # ← 您要的 get 接口!
|
|
data2 = scale2.get()
|
|
|
|
if data1:
|
|
print("dpwn:",{data1['weight']})
|
|
# print(f"[{data1['status']}] {data1['weight']:6}g | RTT: {data1['rtt_ms']:.1f}ms | {data1['raw_data']}")
|
|
if data2:
|
|
print("up:",{data2['weight']})
|
|
# print(f"[{data2['status']}] {data2['weight']:6}g | RTT: {data2['rtt_ms']:.1f}ms | {data2['raw_data']}")
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
print("\nStopped.") |