Skip to content

Cookbook of device patterns, lot 2: vendor DLL (ctypes) and multi-axis controller - #25

Merged
seb5g merged 5 commits into
5.3.xfrom
feat/cookbook-dll-sdk
Oct 25, 2026
Merged

seb5g merged 5 commits into
5.3.xfrom
feat/cookbook-dll-sdk

Conversation

@seb5g

@seb5g seb5g commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Before: the cookbook (lot 1) showed text protocols (pymeasure, serial, VISA) but nothing for the most common way to drive an instrument: a C library (DLL, shared object) supplied by the manufacturer and called with ctypes, and no recipe showed several axes of one controller in one plugin.

After:

  • A recipe CookbookDll: a multi-axis actuator (X, Y, Z, the library numbers its axes 0 to 2) and a 0D detector that reads the positions. Leave the port to MOCK to run on the simulated library. Axes and detector share one library handle (same controller ID: the first is the master, the others are slaves).
  • The simulated vendor library MockMotionLibrary (hardware/mock_dll_controller.py) is used exactly like a loaded ctypes.CDLL, so the real ctypes code of the driver (hardware/dll_controller.py) runs: argtypes/restype, an opaque handle received through byref, a structure, integer error codes turned into exceptions with the message of the library, and a CFUNCTYPE callback kept alive in an attribute.
  • The end of a move is reported by that callback, called from a thread of the library. The plugin only emits a Qt signal from it; the slot runs in the plugin thread and the position polling also waits for the event (user_condition_to_reach_target). The homing is not polled, so move_done is called by the slot.
  • load_library (hardware/native_library.py): names per platform, path from a setting or an environment variable, cdecl or stdcall, and an error that lists everything that was tried.
  • hardware/system_library_demo.py calls the real C library of the system (strlen, frexp with byref, qsort with a Python callback) on Linux, macOS and Windows.
  • The README has two new rows in the cookbook table. A vendor Python binding is packaged like the drivers of hardware/, which the README says.

How: tests in tests/test_cookbook_dll.py (27): loading, the real system library, the simulated library, the driver (callback from another thread, stop, error codes, closed handle), and the plugins with the harness of pymodaq.utils.plugin_testing (master and slave axes, detector sharing the controller, events of other axes ignored). The call into the system library is exercised on Linux by the shared CI; the Windows and macOS names are written but not run there yet (the shared tests workflow only runs on Ubuntu, the compatibility one also on Windows). check_plugin reports both new plugins ok.

No change to PyMoDAQ itself. Builds on the merged lot 1.


Generated by Claude Code

A simulated vendor library that behaves like a ctypes.CDLL, the ctypes driver on it,
a multi-axis actuator and a 0D detector sharing one handle, an end of move reported by
a callback from another thread, load_library and real calls to the C library of the system.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tdiso1u1ZhikSutj2Qs5Cg
Windows writes /somewhere as \somewhere in the message.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tdiso1u1ZhikSutj2Qs5Cg
PyMoDAQ only logs an exception raised by a plugin method. The recipes now emit a status
(report_errors) before raising it again.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tdiso1u1ZhikSutj2Qs5Cg
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tdiso1u1ZhikSutj2Qs5Cg
@seb5g
seb5g merged commit 6bb7164 into 5.3.x Oct 25, 2026
7 checks passed
@seb5g
seb5g deleted the feat/cookbook-dll-sdk branch October 25, 2026 19:35
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