Conversation
When a machine is switched to a non-G-code driver such as the Ruida
RPA adapter, its dialect_uid kept pointing at the Grbl dialect. Job
encoding picked the native Grbl encoder based on that stale dialect
and handed GRBL G-code to the Ruida driver, which failed to stage the
job with 'Missing '(' in gluescript line: G21 ;Set units to mm'.
- Machine.set_driver now syncs the dialect with the driver's G-code
capability: non-G-code drivers clear the leftover dialect, and
switching back to a G-code driver restores the framework default.
- IntentBuilder._build_encoder now consults the driver's uses_gcode
flag before routing to the native Grbl encoder, so encoding always
follows the connected driver even if a stale dialect survives.
Fixes #420
Setting driver_name on a machine backed by the real context lazily creates a MachineController, which schedules the debounced rebuild-driver-on-init coroutine on the task manager. Sync tests never pump the event loop, so the task can still be pending at teardown and the task_mgr fixture fails with 'Task manager still has tasks'. Build the routing tests on the isolated_machine fixture instead: its mocked context never constructs a real controller, so no background task is scheduled. This matches the other encoder-routing tests in the file.
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.
Problem
Sending a job to a machine that was switched over to the new Ruida (RPA) driver crashed the send-job task (#420):
Jogging worked, but every job sent GRBL G-code to the Ruida driver.
Root cause
Every machine carries a
dialect_uiddescribing the G-code flavor of its controller, and new machines default togrbl. Switching the machine to a driver that does not speak G-code (RuidaRPAAdapter) did not clear that setting, so the machine still claimed to be a GRBL speaker.The job encoder route in
IntentBuilder._build_encoder()picked the native GRBL encoder purely from the dialect (_is_grbl(dialect)), without consulting the connected driver. The resulting GRBL G-code (G21 ;Set units to mmpreamble) was then handed toRuidaRPAAdapter.run()→stage_gluescript(), whose parser only acceptsmethod(arg)transcript lines.Fix
Machine.set_driver()now syncs the dialect with the driver's G-code capability (_sync_dialect_with_driver):uses_gcode == False) clear the leftover dialect,grbl), mirroring the deserialization fallback inMachine.from_dict().IntentBuilder._build_encoder()only routes to the native GRBLGcodeSpecwhen the driver itself consumes G-code (new_driver_uses_gcode()helper), so job encoding always follows the connected driver — defense in depth against any stale dialect.Testing
RuidaRPAAdapterclears the stalegrbldialect; switching back to a G-code driver restores it. Removed the now-redundantset_dialect_uid(None)workaround fromtest_supports_travel_speed_non_gcode_driver.GcodeSpec; a non-G-code driver with a leftover Grbl dialect routes to the driver'sPythonEncoder.tests/machine/driver/ruidarpa/(326),tests/machine/models/(983),tests/pipeline/(324),tests/machine/device/+tests/machine/driver/(985): all pass.pixi run lintandpixi run formatclean.Stacked on #417 (base branch:
fix/415-ruida-driver-switch-crash).Fixes #420