Skip to content

Commit 8ba9e43

Browse files
committed
removing most of stdout communication
1 parent 0ba3905 commit 8ba9e43

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

benchmesh-serial-service/src/benchmesh_service/api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import subprocess
77
import hashlib
8+
import logging
89
from pathlib import Path
910
from contextlib import asynccontextmanager
1011
from typing import Any, Dict, List
@@ -21,6 +22,8 @@
2122
import serial.tools.list_ports
2223
from .transport import discover_usbtmc_devices
2324

25+
logger = logging.getLogger(__name__)
26+
2427
API_PORT = int(os.getenv('API_PORT', '57666'))
2528
UI_DEV_PORT = int(os.getenv('UI_PORT', '52893'))
2629

@@ -474,7 +477,7 @@ def list_serial_ports(exclude: str = ""):
474477
continue
475478
except Exception as e:
476479
# Non-fatal - just log and continue with what we have
477-
print(f"Warning: Failed to scan /dev for symlinks: {e}")
480+
logger.warning(f"Failed to scan /dev for symlinks: {e}")
478481

479482
# Sort by device name for consistent ordering
480483
result.sort(key=lambda p: p["device"])

benchmesh-serial-service/src/benchmesh_service/device.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import logging
2+
3+
logger = logging.getLogger(__name__)
4+
5+
16
class Device:
27
def __init__(self, id, name, port, baud, driver):
38
self.id = id
@@ -11,23 +16,23 @@ def connect(self):
1116
"""Establish a serial connection using the specified driver."""
1217
try:
1318
self.connection = self.driver.connect(self.port, self.baud)
14-
print(f"{self.name} connected on {self.port}")
19+
logger.info(f"{self.name} connected on {self.port}")
1520
except Exception as e:
16-
print(f"Failed to connect to {self.name}: {e}")
21+
logger.error(f"Failed to connect to {self.name}: {e}")
1722

1823
def send_command(self, command):
1924
"""Send a command to the device."""
2025
if self.connection:
2126
self.connection.write(command)
2227
else:
23-
print(f"{self.name} is not connected.")
28+
logger.warning(f"{self.name} is not connected.")
2429

2530
def receive_response(self):
2631
"""Receive a response from the device."""
2732
if self.connection:
2833
return self.connection.read()
2934
else:
30-
print(f"{self.name} is not connected.")
35+
logger.warning(f"{self.name} is not connected.")
3136
return None
3237

3338
def check_status(self):
@@ -40,4 +45,4 @@ def close(self):
4045
"""Close the connection to the device."""
4146
if self.connection:
4247
self.connection.close()
43-
print(f"{self.name} connection closed.")
48+
logger.info(f"{self.name} connection closed.")

benchmesh-serial-service/src/benchmesh_service/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ def main():
88
parser = argparse.ArgumentParser()
99
parser.add_argument("--config", "-c", default="config.yaml", help="Path to config YAML")
1010
args = parser.parse_args()
11-
print("Using config file:", args.config)
1211
logger = setup_logger()
12+
logger.info(f"Using config file: {args.config}")
1313
config = load_config(args.config)
14-
print("Loaded config:", config)
14+
logger.info(f"Loaded config: {config}")
1515
serial_manager = SerialManager(config['devices'])
1616
serial_manager.start()
1717

benchmesh-serial-service/src/benchmesh_service/serial_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def _load_manifest(driver_key: str) -> Dict:
5252

5353
class SerialManager:
5454
def __init__(self, config_source: Any, *, resolver: ManifestResolver | None = None, driver_factory: DriverFactory | None = None, clock: Clock | None = None, metrics: MetricsRecorder | None = None, policy: ReconnectPolicy | None = None):
55-
print("Initializing SerialManager with config:", config_source)
5655
self.logger = setup_logger()
56+
self.logger.info(f"Initializing SerialManager with config: {config_source}")
5757
self.devices: List[Dict] = self._load_devices(config_source)
5858
self.keep_running = True
5959
self.dev_locks: Dict[str, threading.RLock] = {d.get('id'): threading.RLock() for d in self.devices if d.get('id')}
@@ -126,7 +126,7 @@ def _load_devices(self, source: Any) -> List[Dict]:
126126
return []
127127

128128
def establish_connections(self):
129-
print("Establishing connections to devices...")
129+
self.logger.info("Establishing connections to devices...")
130130
for device in self.devices:
131131
dev_id = device.get('id')
132132
if not dev_id:

0 commit comments

Comments
 (0)