Mergemaster - #150
Merged
Merged
Conversation
Introduces `uc2rest.aio` with an opt-in `AsyncUC2Client` wrapper around the synchronous `UC2Client`, running blocking operations via `asyncio.to_thread` and exposing a typed async event stream for serial callback frames (`steppers`, `home`, `emergency`, `message`, etc.). It also adds async convenience methods for motors, homing, illumination, objective control, CAN, galvo, and firmware/system calls, plus cancellation-safe stop behavior. A new hardware-free test (`TEST_aio_mock.py`) verifies MockSerial fallback and confirms raw callback frames are bridged into typed async events.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an opt-in asyncio facade (uc2rest.aio.AsyncUC2Client) for driving the existing blocking UC2Client from async applications, adds a motor API for configuring joystick jog speed multipliers, and adds a hardware-free script test that exercises the async event bridge using the existing MockSerial fallback.
Changes:
- Add
uc2rest/aio.py:AsyncUC2Clientwrapper usingasyncio.to_threadplus a typed async firmware-event stream bridged from serial callbacks. - Extend
uc2rest/motor.pywithset_speed_multiplier()/get_speed_multiplier()for joystick jog speed scaling. - Add
uc2rest/TEST/TEST_aio_mock.pyscript to validate MockSerial fallback and typed event emission without hardware.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| uc2rest/aio.py | Adds an asyncio-friendly wrapper around UC2Client and a typed async event stream bridged from serial callbacks. |
| uc2rest/motor.py | Adds joystick jog speed multiplier setter/getter methods. |
| uc2rest/TEST/TEST_aio_mock.py | Adds a hardware-free script test to validate async event bridging via injected frames. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1408
to
+1425
| motors = self.get_motors(timeout=timeout) | ||
|
|
||
| if motors and "steppers" in motors: | ||
| if axis is not None: | ||
| if type(axis) != int: | ||
| axis = self.xyztTo1230(axis) | ||
| for stepper in motors["steppers"]: | ||
| if stepper.get("stepperid") == axis: | ||
| return stepper.get("speedMultiplier", 1) | ||
| else: | ||
| result = [] | ||
| for stepper in motors["steppers"]: | ||
| result.append({ | ||
| "axis": stepper.get("stepperid"), | ||
| "multiplier": stepper.get("speedMultiplier", 1) | ||
| }) | ||
| return result | ||
| return None |
Comment on lines
+182
to
+186
| @property | ||
| def is_connected(self) -> bool: | ||
| """Whether the serial link is currently alive.""" | ||
| return bool(getattr(self._client, "is_connected", False)) | ||
|
|
Comment on lines
+229
to
+242
| async def events(self, queue_size: int = _DEFAULT_QUEUE_SIZE) -> AsyncIterator[SerialEvent]: | ||
| """Yield typed firmware events as they arrive. | ||
|
|
||
| Multiple consumers may iterate concurrently; each gets its own queue. | ||
| The oldest events are dropped if a consumer falls behind. | ||
| """ | ||
| queue: asyncio.Queue = asyncio.Queue(maxsize=queue_size) | ||
| self._queues.append(queue) | ||
| try: | ||
| while True: | ||
| yield await queue.get() | ||
| finally: | ||
| self._queues.remove(queue) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.