puda-drivers 0.0.5__py3-none-any.whl → 0.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
1
  from .serialcontroller import SerialController, list_serial_ports
2
+ from .logging import setup_logging
2
3
 
3
- __all__ = ["SerialController", "list_serial_ports"]
4
+ __all__ = ["SerialController", "list_serial_ports", "setup_logging"]
@@ -0,0 +1,73 @@
1
+ """
2
+ Logging configuration utility.
3
+
4
+ This module provides a function to configure logging with optional file output
5
+ to a logs folder.
6
+ """
7
+
8
+ import logging
9
+ from datetime import datetime
10
+ from pathlib import Path
11
+ from typing import Optional
12
+
13
+
14
+ def setup_logging(
15
+ enable_file_logging: bool = False,
16
+ log_level: int = logging.DEBUG,
17
+ logs_folder: str = "logs",
18
+ log_file_name: Optional[str] = None,
19
+ ) -> None:
20
+ """
21
+ Configure logging with optional file output to a logs folder.
22
+
23
+ Args:
24
+ enable_file_logging: If True, logs will be written to files in the logs folder.
25
+ If False, logs will only be output to console.
26
+ log_level: Logging level constant from logging module (e.g., logging.DEBUG,
27
+ logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL).
28
+ Defaults to logging.DEBUG.
29
+ logs_folder: Name of the folder to store log files (default: "logs")
30
+ log_file_name: Custom name for the log file. If None or empty string, uses
31
+ timestamp-based name. If provided without .log extension, it will
32
+ be added automatically.
33
+ """
34
+ # Create logs folder if file logging is enabled
35
+ if enable_file_logging:
36
+ log_dir = Path(logs_folder)
37
+ log_dir.mkdir(exist_ok=True)
38
+
39
+ # Create a log file with custom name or timestamp
40
+ if log_file_name and log_file_name.strip(): # None or empty/whitespace strings use timestamp
41
+ # Ensure .log extension if not present
42
+ if not log_file_name.endswith(".log"):
43
+ log_file_name = f"{log_file_name}.log"
44
+ log_file = log_dir / log_file_name
45
+ else:
46
+ # Default: timestamp-based name
47
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
48
+ log_file = log_dir / f"log_{timestamp}.log"
49
+
50
+ # Configure logging with both console and file handlers
51
+ logging.basicConfig(
52
+ level=log_level,
53
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
54
+ handlers=[
55
+ logging.StreamHandler(), # Console output
56
+ logging.FileHandler(log_file, mode="w"), # File output
57
+ ],
58
+ )
59
+
60
+ # Log that file logging is enabled
61
+ logger = logging.getLogger(__name__)
62
+ logger.info("File logging enabled. Log file: %s", log_file)
63
+ else:
64
+ # Configure logging with only console handler
65
+ logging.basicConfig(
66
+ level=log_level,
67
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
68
+ handlers=[logging.StreamHandler()], # Console output only
69
+ )
70
+
71
+ # Log that file logging is disabled
72
+ logger = logging.getLogger(__name__)
73
+ logger.info("File logging disabled. Logs will only be output to console.")
@@ -159,9 +159,13 @@ class SerialController(ABC):
159
159
  # Read all available bytes
160
160
  response += self._serial.read(self._serial.in_waiting)
161
161
 
162
- # Check for expected response markers for early return
162
+ # Check for expected response markers for early return for qubot
163
163
  if b"ok" in response or b"err" in response:
164
164
  break
165
+
166
+ # Check for expected response markers for early return for sartorius
167
+ if b"\xba\r" in response:
168
+ break
165
169
  else:
166
170
  time.sleep(0.1)
167
171
 
@@ -175,10 +179,12 @@ class SerialController(ABC):
175
179
  # Decode once and check the decoded string
176
180
  decoded_response = response.decode("utf-8", errors="ignore").strip()
177
181
 
178
- if "ok" in decoded_response.lower():
182
+ if "ok" in decoded_response.lower(): # for qubot
179
183
  self._logger.debug("<- Received response: %r", decoded_response)
180
- elif "err" in decoded_response.lower():
184
+ elif "err" in decoded_response.lower(): # for qubot
181
185
  self._logger.error("<- Received error: %r", decoded_response)
186
+ elif "º" in decoded_response: # for sartorius
187
+ self._logger.debug("<- Received response: %r", decoded_response)
182
188
  else:
183
189
  self._logger.warning(
184
190
  "<- Received unexpected response (no 'ok' or 'err'): %r", decoded_response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: puda-drivers
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: Hardware drivers for the PUDA platform.
5
5
  Project-URL: Homepage, https://github.com/zhao-bears/puda-drivers
6
6
  Project-URL: Issues, https://github.com/zhao-bears/puda-drivers/issues
@@ -27,6 +27,7 @@ Hardware drivers for the PUDA (Physical Unified Device Architecture) platform. T
27
27
  - **Gantry Control**: Control G-code compatible motion systems (e.g., QuBot)
28
28
  - **Liquid Handling**: Interface with Sartorius rLINE® pipettes and dispensers
29
29
  - **Serial Communication**: Robust serial port management with automatic reconnection
30
+ - **Logging**: Configurable logging with optional file output to logs folder
30
31
  - **Cross-platform**: Works on Linux, macOS, and Windows
31
32
 
32
33
  ## Installation
@@ -47,6 +48,37 @@ pip install -e .
47
48
 
48
49
  ## Quick Start
49
50
 
51
+ ### Logging Configuration
52
+
53
+ Configure logging for your application with optional file output:
54
+
55
+ ```python
56
+ import logging
57
+ from puda_drivers.core.logging import setup_logging
58
+
59
+ # Configure logging with file output enabled
60
+ setup_logging(
61
+ enable_file_logging=True,
62
+ log_level=logging.DEBUG,
63
+ logs_folder="logs", # Optional: default to logs
64
+ log_file_name="my_experiment" # Optional: custom log file name
65
+ )
66
+
67
+ # Or disable file logging (console only)
68
+ setup_logging(
69
+ enable_file_logging=False,
70
+ log_level=logging.INFO
71
+ )
72
+ ```
73
+
74
+ **Logging Options:**
75
+ - `enable_file_logging`: If `True`, logs are written to files in the `logs/` folder. If `False`, logs only go to console (default: `False`)
76
+ - `log_level`: Logging level constant (e.g., `logging.DEBUG`, `logging.INFO`, `logging.WARNING`, `logging.ERROR`, `logging.CRITICAL`) (default: `logging.DEBUG`)
77
+ - `logs_folder`: Name of the folder to store log files (default: `"logs"`)
78
+ - `log_file_name`: Custom name for the log file. If `None` or empty, uses timestamp-based name (e.g., `log_20250101_120000.log`). If provided without `.log` extension, it will be added automatically.
79
+
80
+ When file logging is enabled, logs are saved to timestamped files (unless a custom name is provided) in the `logs/` folder. The logs folder is created automatically if it doesn't exist.
81
+
50
82
  ### Gantry Control (GCode)
51
83
 
52
84
  ```python
@@ -183,6 +215,29 @@ except ValueError as e:
183
215
 
184
216
  Validation errors are automatically logged at the ERROR level before the exception is raised.
185
217
 
218
+ ### Logging Best Practices
219
+
220
+ For production applications, configure logging at the start of your script:
221
+
222
+ ```python
223
+ import logging
224
+ from puda_drivers.core.logging import setup_logging
225
+ from puda_drivers.move import GCodeController
226
+
227
+ # Configure logging first, before initializing devices
228
+ setup_logging(
229
+ enable_file_logging=True,
230
+ log_level=logging.INFO,
231
+ log_file_name="gantry_operation"
232
+ )
233
+
234
+ # Now all device operations will be logged
235
+ gantry = GCodeController(port_name="/dev/ttyACM0")
236
+ # ... rest of your code
237
+ ```
238
+
239
+ This ensures all device communication, movements, and errors are captured in log files for debugging and audit purposes.
240
+
186
241
  ## Finding Serial Ports
187
242
 
188
243
  To discover available serial ports on your system:
@@ -1,7 +1,8 @@
1
1
  puda_drivers/__init__.py,sha256=rcF5xCkMgyLlJLN3gWwJnUoW0ShPyISeyENvaqwg4Ik,503
2
2
  puda_drivers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- puda_drivers/core/__init__.py,sha256=JM6eWTelwcmjTGM3gprQlJWzPGEpIdRrDmbCHtGoKyM,119
4
- puda_drivers/core/serialcontroller.py,sha256=I7TsLNl45HPrO29LkhMRIQQ8fWdjdJUvIwQQ5swbMHM,7660
3
+ puda_drivers/core/__init__.py,sha256=yYsOLXl32msFNRGrXLqhNVl_OfNPFR4ED7pmgn7rPU0,171
4
+ puda_drivers/core/logging.py,sha256=prOeJ3CGEbm37TtMRyAOTQQiMU5_ImZTRXmcUJxkenc,2892
5
+ puda_drivers/core/serialcontroller.py,sha256=9Vgz884MWmq4Z7rQzIQ7DtPzygMuzBeNWj0JiUpAhGA,7996
5
6
  puda_drivers/move/__init__.py,sha256=i7G5VKD5FgnmC21TLxoASVtC88IrPUTLDJrTnp99u-0,35
6
7
  puda_drivers/move/gcode.py,sha256=egZw3D5m9d1R8P32L1wd3lDwiWcFMDGPHsFMFIYXkRA,22069
7
8
  puda_drivers/move/grbl/__init__.py,sha256=vBeeti8DVN2dACi1rLmHN_UGIOdo0s-HZX6mIepLV5I,98
@@ -11,7 +12,7 @@ puda_drivers/transfer/liquid/sartorius/__init__.py,sha256=QGpKz5YUwa8xCdSMXeZ0iR
11
12
  puda_drivers/transfer/liquid/sartorius/api.py,sha256=jxwIJmY2k1K2ts6NC2ZgFTe4MOiH8TGnJeqYOqNa3rE,28250
12
13
  puda_drivers/transfer/liquid/sartorius/constants.py,sha256=mcsjLrVBH-RSodH-pszstwcEL9wwbV0vOgHbGNxZz9w,2770
13
14
  puda_drivers/transfer/liquid/sartorius/sartorius.py,sha256=iW3v-YHjj4ZAfGv0x0J-XV-Y0fAAhS6xmSg2ozQm4UI,13803
14
- puda_drivers-0.0.5.dist-info/METADATA,sha256=5VB_QiC_hcuV4-FEoXi-qEp637jAjQLiv5fipHX9QPg,6559
15
- puda_drivers-0.0.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
16
- puda_drivers-0.0.5.dist-info/licenses/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
17
- puda_drivers-0.0.5.dist-info/RECORD,,
15
+ puda_drivers-0.0.6.dist-info/METADATA,sha256=ELS1LZxhddh-dD-b0iKDrO5RnuJrrgITv6F6GeJ20wY,8598
16
+ puda_drivers-0.0.6.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
17
+ puda_drivers-0.0.6.dist-info/licenses/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
18
+ puda_drivers-0.0.6.dist-info/RECORD,,