C# plugins
Python devices run in their own process, and a call costs about 0.1 ms. That is fine for nearly everything. For an instrument that streams hundreds of megabytes per second, such as an oscilloscope, the driver runs inside the server as a C# plugin. It looks like any other device from the outside: options, state, actions, logs, restart after errors.
Building a plugin needs the .NET SDK (version 11, or the one named in the README of the new project) on the computer where you build; LabOrchestra itself does not need it to run. The SDK is version 0.x: until 1.0, any minor version may break plugins that were built against an older one.
Start a plugin
Section titled “Start a plugin”On the lab PC, the Devices page has a section Drivers with New C# plugin… (and New Python driver…): enter a name written like a C# class (Camera), and the dialog creates the project and shows the build command. The section also lists the loaded plugins with their drivers and problems, and refreshes by itself, so a plugin you just built appears. The same from the command line:
laborchestra new plugin CameraThis makes <workspace>/plugin_src/Camera/ with a simulated driver, a README and a VS Code configuration. The project refers to the NuGet package LabOrchestra.Sdk in the version of your server; the first build needs internet. To use a newer SDK, change the version number in the .csproj.
[Driver("camera")]public class Camera : Device<CameraOptions, CameraState>{ [Action] public async Task SetExposure(double milliseconds) => Update(s => s.Exposure = milliseconds);
public override Task ConnectAsync(CancellationToken ct) { /* open the camera */ return Task.CompletedTask; } public override async Task RunAsync(CancellationToken ct) { /* acquire */ } public override Task CloseAsync() => Task.CompletedTask;}- Options and state are public properties. On the wire they are snake_case (
Exposurebecomesexposure).Update(s => ...)changes the state under a lock and publishes it. - Actions are methods marked
[Action]. A/// <summary>comment on one is its description in the dashboard and in MCP (the project file writes the XML file next to the DLL). The scaffolded actionRampshows how a long action can be interrupted by another one. - Name in the list:
[Driver("camera", Title = "Acme camera", Category = "imaging")]; the categories are the short words of Write a device. - Settings that survive a restart: override
SaveSettings()andLoadSettings(...). - A lost instrument: throw
ConnectionLostException,TimeoutException,IOExceptionorSocketException(or callOffline(reason)). The device shows as offline and the server connects it again by itself. - Creating the project needs the passphrase of the server: an MCP token is refused.
The guide for AI assistants (get_docs topic plugin) has a complete example.
Build and load
Section titled “Build and load”- Run
dotnet buildin the plugin’s folder. The DLL and its files go to<workspace>/plugins/. - The server notices the new plugin within a couple of seconds and loads it. Add the device with
"driver": "camera"indevices.jsonor in the dialog. - Rebuilt it? Set
"plugin_reload": trueinconfig.jsonand the server replaces the plugin while it runs. Without it, restart the server.
More folders can be watched with the setting plugin_dirs (separated by ;, relative to the workspace), for example the build output of the plugin.
Debugging
Section titled “Debugging”Build in debug mode and use the VS Code configuration Attach to LabOrchestra server.
Versions
Section titled “Versions”The SDK has its own version. Within one major version a built plugin keeps working with the same or a newer server. A new major may need a rebuild, and LabOrchestra tells you before an update which plugins would stop working. The SDK is still 0.x: until 1.0, any minor version may break plugins.
Vendor SDKs such as PicoSDK are not shipped. Your plugin should load them at runtime and report a clear device error when they are missing.
Something wrong or missing on this page? Open a GitHub issue or use the form (no account needed).