Skip to content

Cookbook lot 4: vendor .NET assembly with pythonnet - #27

Merged
seb5g merged 1 commit into
5.3.xfrom
feat/cookbook-pythonnet
Oct 25, 2026
Merged

seb5g merged 1 commit into
5.3.xfrom
feat/cookbook-pythonnet

Conversation

@seb5g

@seb5g seb5g commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

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: the pythonnet driver, with the conventions a plugin author must know (an out parameter 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 its Message read, 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 when pythonnet or the runtime is missing) and load_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.Elapsed raised from another thread).
  • Plugins daq_move_CookbookDotNet (3 axes, end of move by an event turned into a Qt signal) and daq_0Dviewer_CookbookDotNet.
  • pythonnet>=3.0.3 becomes 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.py has 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

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
@seb5g
seb5g merged commit f76b2a0 into 5.3.x Oct 25, 2026
6 of 7 checks passed
@seb5g
seb5g deleted the feat/cookbook-pythonnet branch October 25, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants