Repository navigation
Cookbook lot 4: vendor .NET assembly with pythonnet - #27
Merged
Merged
Conversation
Actuator and 0D detector on a simulated .NET assembly (out parameter, event, exception type, IDisposable), the helpers to start the runtime and load an assembly, and real calls to the .NET libraries of the runtime. pythonnet is a dependency; the tests of the real libraries are skipped when no runtime is available. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tdiso1u1ZhikSutj2Qs5Cg
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.
Before: the cookbook covered serial, VISA, pymeasure, a ctypes DLL, a camera and a spectrometer, but nothing for a manufacturer that supplies a .NET assembly.
After: a recipe for a multi-axis controller on a .NET assembly, driven with
pythonnet, that runs without the assembly.What changes:
hardware/dotnet_controller.py: thepythonnetdriver, with the conventions a plugin author must know (anoutparameter comes back in a tuple, an event takes a Python function with+=and-=kept in an attribute, the exception type of the assembly is caught and itsMessageread,IDisposable).hardware/mock_dotnet_controller.py: the assembly is simulated by an object used like its namespace (same device as the DLL recipe), so the real driver code runs and is tested.hardware/dotnet_runtime.py:load_dotnet(runtime per platform, clear error whenpythonnetor the runtime is missing) andload_assembly(names, path from a setting or an environment variable, an error listing what was tried).hardware/system_dotnet_demo.py: real calls to the .NET libraries of the runtime (Int32.TryParse,List<double>,MemoryStream,Timer.Elapsedraised from another thread).daq_move_CookbookDotNet(3 axes, end of move by an event turned into a Qt signal) anddaq_0Dviewer_CookbookDotNet.pythonnet>=3.0.3becomes a dependency (a pure Python wheel; a .NET runtime is only needed when talking to an assembly). README table and note updated.How:
tests/test_cookbook_dotnet.pyhas the tests on the real .NET libraries (skipped if there is no runtime), on the simulated assembly and driver, and on the plugins. Locally (Linux, .NET 8 runtime,coreclr): 170 passed, 3 skipped for the full suite. The Windows (.NET Framework) path is only covered by the CI job. Nothing was tested on a real vendor assembly.Generated by Claude Code