Background
The pslab.serial_handler module is deprecated and emits warnings during build and runtime.
A newer API is available via pslab.connection.SerialHandler.
Migrating to the new API is necessary, but the two implementations differ in runtime behavior, particularly regarding connection states.
Current CLI behavior
In pslab/cli.py, the CLI currently:
- Instantiates
SerialHandler(port=args.port)
- Uses the handler immediately without explicitly calling
connect()
- Relies on the deprecated module's implicit connection behavior to function.
Behavior difference with pslab.connection
The newer pslab.connection.SerialHandler:
- Does not auto-connect on initialization.
- Requires an explicit
.connect() call to open the port.
- Will fail at runtime if used immediately after instantiation without connection.
Proposed Resolution
To safely migrate to the new API, the CLI logic in pslab/cli.py will be updated to:
- Explicit Connection: Call
handler.connect() immediately after instantiation.
- Lifecycle Management: Wrap the execution in a
try...finally block to ensure handler.disconnect() is called on exit.
- Port Handling: Ensure
args.port is passed correctly to support both specific port selection and auto-discovery.
Related work
Background
The
pslab.serial_handlermodule is deprecated and emits warnings during build and runtime.A newer API is available via
pslab.connection.SerialHandler.Migrating to the new API is necessary, but the two implementations differ in runtime behavior, particularly regarding connection states.
Current CLI behavior
In
pslab/cli.py, the CLI currently:SerialHandler(port=args.port)connect()Behavior difference with
pslab.connectionThe newer
pslab.connection.SerialHandler:.connect()call to open the port.Proposed Resolution
To safely migrate to the new API, the CLI logic in
pslab/cli.pywill be updated to:handler.connect()immediately after instantiation.try...finallyblock to ensurehandler.disconnect()is called on exit.args.portis passed correctly to support both specific port selection and auto-discovery.Related work