sendGenericCommand
Function that sends a command via the electronUsbApiService to the scanner
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:
- Accessing local hardware
- Reading or writing files
- Opening native dialogs
- Generating PDFs or reports
- Interacting with external applications
- Executing custom utility functions
- Exchanging data between the pipeline and Electron
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:
- The configured Electron command is executed.
- A result is returned by the Electron application.
- The result is optionally written to the configured state location.
- The configured
onSuccessevent target is executed.
pipelineConfig.executeStage(
pipelineConfig.stageConfig.eventTargets?.onSuccess,
'onSuccess',
pipelineConfig.stage
);
Error Behaviour
An error is triggered when:
- No command name is configured.
- The command handler cannot be found.
- The Electron command throws an exception.
- Communication between the application and Electron fails.
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
- This stage acts as the primary extension point between the Config Editor and the Electron application.
- New Electron functionality can be made available to configurations by implementing a new command handler without modifying the pipeline framework.
- Input and output state mappings are optional.
- The stage itself contains no Electron-specific business logic and delegates execution to the command handling infrastructure.
- Missing
commandNameimmediately triggers the configuredonErrorevent. - Commands may return any serializable data type which can then be stored in the application state.