Wiki.js

sendGenericCommand

Function that sends a command via the electronUsbApiService to the scanner

AI Generated

sendGenericCommand()

Purpose

Provides a generic interface for executing custom Electron-side functionality from within the pipeline configuration.

By specifying a command name in the stage configuration, functionality implemented in the Electron application can be invoked directly from configuration files. This enables the Config Editor to access Electron-specific features without requiring dedicated pipeline stages for each use case.

The stage is intended as a flexible extension mechanism that allows new Electron features to be added and made available to configurations with minimal changes to the existing pipeline system.

Typical use cases include:


Location

src/app/services/genericStages/generic-stages.service.ts

Signature

sendGenericCommand(
  pipelineConfig: PipelineStageConfig
): OperatorFunction<StatusObject, Observable<any>>

Parameters

Parameter Type Description
pipelineConfig PipelineStageConfig Current pipeline stage configuration containing command parameters, state, and event targets.

Returns

OperatorFunction<StatusObject, Observable<any>>

RxJS operator which executes a custom Electron command and optionally stores the returned result in the application state.


Command Configuration

The stage uses values from:

pipelineConfig.stageConfig.commandParameters

Supported Parameters

Parameter Description
commandName Name of the Electron command to execute
transferConstant Constant value passed to the command
fromResKey State key used as transfer variable source
fromResGroup State group containing the source value
toResKey State key where the command result should be stored
toResGroup State group where the result should be written

Example Configuration

{
  "commandParameters": {
    "commandName": "generateMeasurementReport",
    "fromResKey": "MEASUREMENT_RESULT",
    "fromResGroup": "persistentValues",
    "toResKey": "PDF_PATH",
    "toResGroup": "persistentValues"
  }
}

Workflow

Read command configuration
        ↓
Read transferVariable (optional)
        ↓
Build transferData
        ↓
Execute Electron command
        ↓
Receive result
        ↓
Store result (optional)
        ↓
Execute onSuccess

Transfer Data Handling

The function supports two types of transfer data.

Constant Transfer Data

A fixed value defined in the configuration:

{
  "transferConstant": "exampleValue"
}

State-Based Transfer Data

A value read from the current application state:

{
  "fromResKey": "SCANNER_SERIAL",
  "fromResGroup": "persistentValues"
}

Result:

transferVariable =
  state.persistentValues.SCANNER_SERIAL;

Generated Transfer Object

const transferData = {
  transferConstant,
  transferVariable
};

This object is passed to the Electron command handler.


Electron Command Execution

await this.scannerApiService.executeGenericCommand(
  pipelineConfig.state.persistentValues,
  command,
  transferData
);

Parameters

Parameter Description
persistentValues Current scanner and application state values
command Name of the Electron command
transferData Additional command-specific data

State Dependencies

Reads

Optional:

state[fromResGroup][fromResKey]

Always:

state.persistentValues

Writes

Optional:

state[toResGroup][toResKey]

Success Behaviour

On successful execution:

  1. The configured Electron command is executed.
  2. A result is returned by the Electron application.
  3. The result is optionally written to the configured state location.
  4. The configured onSuccess event target is executed.
pipelineConfig.executeStage(
  pipelineConfig.stageConfig.eventTargets?.onSuccess,
  'onSuccess',
  pipelineConfig.stage
);

Error Behaviour

An error is triggered when:

In these cases the configured onError event target is executed.

pipelineConfig.executeStage(
  pipelineConfig.stageConfig.eventTargets?.onError,
  'onError',
  pipelineConfig.stage
);

Example 1: Generate a PDF Report

{
  "commandParameters": {
    "commandName": "generateMeasurementReport",
    "fromResKey": "MEASUREMENT_RESULT",
    "fromResGroup": "persistentValues",
    "toResKey": "PDF_PATH",
    "toResGroup": "persistentValues"
  }
}

Result:

persistentValues: {
  PDF_PATH: "/reports/report_001.pdf"
}

Example 2: Open a Native File Dialog

{
  "commandParameters": {
    "commandName": "selectOutputDirectory",
    "toResKey": "OUTPUT_DIRECTORY",
    "toResGroup": "persistentValues"
  }
}

Result:

persistentValues: {
  OUTPUT_DIRECTORY: "C:/Users/Oliver/Documents"
}

Notes