How-to guides

Commands

A public method of the Komod with the [KomodCommand] attribute can be called from the UI while the instance runs. Use it for one-time actions (calibration, reset, save); for continuous data use a port.

[KomodCommand("reset")]
public async Task<ResetResult> ResetAsync(CancellationToken ct) { … }

Rules

  • The name can be omitted: then it is the method name without Async, in camelCase.
  • At most one argument (deserialized from JSON) and a CancellationToken.
  • The return value: Task, Task<T>, ValueTask(<T>), void or a value; it goes back as JSON.
  • For an error meant for the user throw a KomodCommandException: with a Hungarian message, or with a translatable one (Text("key", "Hungarian text"), see Multilingual Komods). That is what the UI shows.
  • RequiresAdmin = true: only an Admin can call it. By default an Operator can too.

Calling from the UI

var result = await Kofa.InvokeAsync<ResetResult>(InstanceId, "reset");
// or: await InvokeCommandAsync("reset");

With an argument: await Kofa.InvokeAsync(InstanceId, "calibrate", new { offset = 1.5 }).

The command runs on the running instance. If the instance is not running, the call returns an error.