# LumiScan Script Runner 1.0.0.2 – complete documentation

> All pages of the LumiScan Script Runner 1.0.0.2 manual (language: en) by HD Vision Systems GmbH, in navigation order. Each page starts with a level-1 heading followed by its URL; cite that URL. Manual: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/

# LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/index.html

|   |   |   |
| --- | --- | --- |
| ![A HALCON procedure with its documented interface: image and value inputs, value outputs](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/_images/intro/step-1.svg)<br><br>**Write it in HDevelop.** Develop and test your vision logic as a HALCON procedure, as you always do. | ![The procedure file in the script folder, turned into a module with typed input and output nodes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/_images/intro/step-2.svg)<br><br>**Drop it in.** The Script Runner reads the procedure’s interface and gives every parameter its own node. | ![A PLC function block with Execute, Busy, Done and Error, connected to the module’s run handshake](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/_images/intro/step-3.svg)<br><br>**Call it from the PLC.** One handshake per module, the same function block for every script. |

LumiScan Script Runner is the LumiScan app for vision experts who know and love HALCON. It runs your HALCON procedures (`.hdvp`) with MVTec’s HDevEngine and publishes each one as a module on the Data Layer. The procedure’s declared interface decides the nodes: one typed node per value parameter, an image group per image parameter, and a `run` handshake that a PLC function block maps one to one. Change the vision logic by replacing the procedure file, without a new software build. Procedures that share a model run in one group and pass HALCON handles through the group’s store, inside the app. The Script Runner uses the MVTec HALCON 22.11 installation on the PC, which you install with its runtime licence before the Script Runner.

To get started, see [Run Your First Script](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/run-your-first-script.html). Installing: [Requirements](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/requirements.html) and [Installing the Script Runner](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/installation.html). Questions or an error code? See [Status Codes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/status-codes.html) and [Troubleshooting](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html). Product information and quotes: [LumiScan Script Runner on hdvisionsystems.com](https://www.hdvisionsystems.com/en/lumiscan-ecosystem/script-runner/).

# Description – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/description.html

LumiScan Script Runner turns HALCON procedures into functions on the Data Layer. It is meant for vision experts who write their own HALCON code for demanding edge cases and want to call it from a PLC or any other Data Layer client, without writing glue code. Customers who want to solve a vision task without vision knowledge use the other apps of the LumiScan Vision Suite.

## How it works

1. **You write a procedure.** In HDevelop you write and test a procedure with a declared interface: image inputs, image outputs, value (control) inputs and value outputs. The types of the parameters come from the procedure’s documentation or from an [interface file](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html) next to it.
2. **You put it into the script folder.** The procedure file (`<name>.hdvp`) goes into the Script Runner’s script folder, see [Settings Folder](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html).
3. **You configure a module.** An entry in the [application file](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html) names the module, the procedure it runs, its group and where each parameter comes from or goes to.
4. **The Script Runner builds the nodes.** At start it reads every procedure of the script folder through HDevEngine, maps each parameter to a node (see [Type Mapping](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html)) and publishes the module under `hdvisionsystems/lumiscan-script-runner/v1/<module>/`.
5. **A client calls the module.** It writes the inputs, raises `run/request` and waits for `run/done` or `run/has-error`, see [The run Handshake](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/run-handshake.html). The Script Runner runs the procedure, checks every output against the interface and writes the outputs.

## What you get

- **Typed nodes from your interface.** An integer parameter becomes an INT64 node, a real parameter a FLOAT64 node, a string a STRING node, several values an array node, an image a group with `data`, `width`, `height` and `pixel-type`. Descriptions, units, minimum, maximum and default values of the procedure go into the node’s description, and the minimum and maximum are checked before the procedure runs.
- **One handshake for every script.** Every module has the same `run` function (`request`, `ready`, `running`, `done`, `has-error`, `output/status-code`). One PLC function block with `xExecute`, `xBusy`, `xDone`, `xError` and `eErrorID` serves every module; only the input and output nodes differ.
- **Shared models without handles on the Data Layer.** A HALCON handle (a shape model, a dictionary) never leaves the app. Modules that share a handle run in one group and pass it through the group’s store, see [Modules, Groups and the Store](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html). A module can run once at start, for example to read a model file.
- **Protection for your PLC program.** The Script Runner computes a hash of every procedure’s interface. A module is built only when the hash is the one it was accepted for, so a changed procedure never moves your PLC program’s nodes unnoticed, see [Interfaces and Hashes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interfaces-and-hashes.html).
- **Changes without a new build.** Replace a procedure whose interface stays the same and restart the app: the new vision logic runs behind the same nodes.
- **Protected procedures.** A procedure locked with a password in HDevelop runs as well; its interface stays readable. The password never reaches the device.

## What it does not do

- It runs procedures, not HDevelop programs (`.hdev`) with a `main`: wrap a program into a procedure first, see [Prepare a HALCON Procedure](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html).
- Regions and contours (XLD) are not transported on the Data Layer. Convert them into an image (`region_to_bin`, `paint_xld`) or into coordinate arrays before the procedure returns.
- A parameter that mixes strings and numbers in one tuple is not supported.
- The procedure has no timeout: the client times out on its side.

The limits of this version are listed in the [Release Notes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/release-notes.html).

# Requirements – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/requirements.html

## PC

|   |   |
| --- | --- |
| Operating system | Windows 11 (64 bit) or Ubuntu 24.04 (64 bit, x86-64) |
| HALCON | MVTec HALCON 22.11 (Steady), any 22.11.x maintenance release, with a runtime licence: on Windows installed for all users of the PC, on Ubuntu set up for the user who starts the Script Runner. **No other HALCON release**, older or newer, see [HALCON 22.11 only](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/requirements.html#halcon-release). HALCON is not part of the Script Runner’s installer or package: the Script Runner uses the HALCON installation on the PC. Install HALCON **before** the Script Runner, see [Installing the Script Runner](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/installation.html). |
| Data Layer | LumiScan Keryx on the same PC. The Script Runner connects to it at start. |
| Licence | The LumiScan Key, see [Licence](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/requirements.html#licence) |

This version runs on Windows 11 and on Ubuntu 24.04.

## HALCON 22.11 only {#halcon-release}

This version of the Script Runner is built for HALCON 22.11 and runs only with HALCON 22.11. Any 22.11.x maintenance release works; any other release does not, neither an older one (for example 20.11) nor a newer one (for example 24.11). The reason is HALCON itself: MVTec keeps HALCON’s libraries binary compatible within one release only, and a program built for one release has to be rebuilt for the next.

- **At start** the Script Runner checks the release of the HALCON libraries it loaded, before it calls HALCON: `halcon.dll`, `halconcpp.dll` and `hdevenginecpp.dll` on Windows, `libhalcon.so`, `libhalconcpp.so` and `libhdevenginecpp.so` on Ubuntu. If one is of another release, it stops, and its log names each library with its version and folder, see [Troubleshooting](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#ts-halcon-release).
- **The Windows installer** checks only that HALCON is installed, not its release.
- **Several HALCON releases on one PC** are possible, but the Script Runner uses the one whose library folder comes first: on Windows the `bin\x64-win64` folder on `PATH`, on Ubuntu the `lib/x64-linux` folder on `LD_LIBRARY_PATH`. That must be HALCON 22.11.
- **The HALCON licence** must be valid for HALCON 22.11. A licence for a newer HALCON release is usually valid for older releases too; ask MVTec or your HALCON distributor.
- **A newer HALCON release** needs a new version of the Script Runner, built for it.

## Your procedures

- HALCON procedures (`.hdvp`) that use only operators of HALCON 22.11. A procedure saved with a newer HDevelop (for example 26.05) loads and runs, because the file format is the same; it fails only if it uses an operator that HALCON 22.11 does not have. Test such a procedure with HALCON 22.11 before you put it on the device.
- Protected procedures (locked with a password in HDevelop) work like open ones: the Script Runner reads their interface and their documentation and runs them, without the password.
- Every parameter has a type: from the procedure’s documentation in HDevelop or from an [interface file](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html). See [Prepare a HALCON Procedure](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html#parameter-information).
- The HALCON modules the procedures use must be in your HALCON runtime licence.

## Licence {#licence}

Two licences are needed on the PC:

- **LumiScan Script Runner:** the **LumiScan Key** (a CodeMeter USB key; WIBU CodeMeter, firm code 6000380, product code 9063), plugged into the PC. The PC needs the **CodeMeter Runtime** 9.00 or newer (from WIBU-SYSTEMS, wibu.com).
- **HALCON runtime:** the HALCON runtime licence (a dongle or a licence file) from MVTec or your HALCON distributor. Without a valid HALCON licence the Script Runner starts, but no module runs: every module reports `-4`, and `system/engine/license-valid` is `false`.

For licences, contact HD Vision Systems at [licenses@hdvisionsystems.com](mailto:licenses@hdvisionsystems.com).

# Run Your First Script – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/run-your-first-script.html

This tutorial runs the three example procedures that come with the Script Runner. You write inputs, start a run with the `run` handshake, read the outputs, and provoke two errors. It takes about 15 minutes.

You need:

- LumiScan Script Runner installed and started, see [Installing the Script Runner](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/installation.html).
- A Data Layer client that can read and write nodes of LumiScan Keryx, for example your PLC or a test client.

All addresses below start with `hdvisionsystems/lumiscan-script-runner/v1/`.

## The examples

The first start copied three procedures into the script folder, and the application file configures one module for each:

| Module | Procedure | What it does |
| --- | --- | --- |
| `add` | `add_values (: : A, B : Sum, Text)` | Adds two integers. It throws an error when the sum is negative. |
| `blobs` | `count_blobs ( : Binary : ImageFile, MinGray, MinArea : Count, Areas, MeanGray)` | Reads the image file `blobs.png` from the script folder, finds its bright blobs and returns their number, each blob’s area, their mean gray value and a binary image. |
| `convert` | `convert_length (: : Length, FromUnit, ToUnit : Converted, Text)` | Converts a length between mm, cm and m. It throws an error for any other unit. |

`add_values` and `count_blobs` get their parameter types from an interface file next to them (`add_values.interface.json`, `count_blobs.interface.json`). `convert_length` has none: every parameter is documented in HDevelop, and the Script Runner reads the types from the procedure itself. See [Prepare a HALCON Procedure](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html).

## 1. Check that the modules are ready

1. Read `add/status/code`, `blobs/status/code` and `convert/status/code`. Expected: `0` (`status/text` says `ready`).
2. Read `add/run/ready`. Expected: `true`.

If a status code is not `0`, look it up in [Status Codes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/status-codes.html).

## 2. Look at the nodes of a module

Browse `add/`. The Script Runner built these nodes from the interface of `add_values`:

| Node | Type | From |
| --- | --- | --- |
| `add/run/input/a` | INT64 | input parameter `A` |
| `add/run/input/b` | INT64 | input parameter `B` |
| `add/run/output/sum` | INT64 | output parameter `Sum` |
| `add/run/output/text` | STRING | output parameter `Text` |
| `add/run/output/status-code`, `status-text`, `package-identifier` |   | every module |
| `add/run/request`, `ready`, `running`, `done`, `has-error` | BOOL8 | every module |

`add/script/interface` shows the interface as JSON, `add/script/interface-hash` its hash.

## 3. Run `add`

1. Write `40` to `add/run/input/a` and `2` to `add/run/input/b`.
2. Write `true` to `add/run/request`.
3. Wait until `add/run/done` or `add/run/has-error` is `true`. Expected: `done` is `true`.
4. Read the outputs. Expected: `add/run/output/sum` is `42`, `add/run/output/text` is `sum of 40 and 2`, `add/run/output/status-code` is `0`, and `add/run/output/package-identifier` has grown by one.
5. Write `false` to `add/run/request`. Expected: `done` goes back to `false`, `ready` to `true`.

You have just run the handshake a PLC function block runs: `request` is `xExecute`, `running` is `xBusy`, `done` is `xDone`, `has-error` is `xError`, `output/status-code` is `eErrorID`. See [The run Handshake](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/run-handshake.html).

## 4. Provoke a script error

1. Write `-50` to `add/run/input/a`, keep `b` at `2`.
2. Raise `add/run/request` and wait. Expected: `has-error` is `true`, `output/status-code` is `-10001` (script error), and `output/status-text` names the procedure, the program line, the HALCON error number and the text the script threw: `the sum must not be negative`.
3. The outputs keep their values of the last successful run: a failed run writes no output.
4. Lower `request` again.

## 5. Run `blobs`

The inputs of `blobs` start at the defaults declared in its interface file: `image-file` is `blobs.png`, `min-gray` `128`, `min-area` `100`.

1. Raise `blobs/run/request` and wait for `done`.
2. Read the outputs. Expected: `blobs/run/output/count` is `4`, `blobs/run/output/areas` holds four areas, `blobs/run/output/mean-gray` is a real value, and `blobs/run/output/binary/` holds the binary image (`data`, `width`, `height`, `pixel-type` `mono8`).
3. Lower `request`.

## 6. Run `convert`, a procedure without an interface file

1. Read `convert/script/interface-source`. Expected: `documentation`: the types come from the procedure’s HDevelop documentation, not from a file.
2. Read the inputs. They start at the documented defaults: `convert/run/input/length` is `25.4` (FLOAT64), `from-unit` is `mm` and `to-unit` is `cm` (STRING).
3. Raise `convert/run/request` and wait for `done`. Expected: `convert/run/output/converted` is `2.54` and `convert/run/output/text` is `25.4 mm = 2.54 cm`.
4. Lower `request`, write `inch` to `convert/run/input/to-unit` and run again. Expected: `has-error` is `true`, `output/status-code` is `-10001`, and `status-text` ends with the text the procedure threw: `unknown unit: use mm, cm or m`.
5. Write `cm` again and lower `request`.

## 7. Provoke an input error

The interface file of `count_blobs` gives `MinGray` a minimum of `0` and a maximum of `255`.

1. Write `300` to `blobs/run/input/min-gray`.
2. Raise `request` and wait. Expected: `has-error` is `true`, `output/status-code` is `-3` (invalid input), and `status-text` names the input and its range. The procedure did not run.
3. Write `128` again and lower `request`.

## Next steps

- Write your own procedure: [Prepare a HALCON Procedure](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html).
- Make it a module: [Add a Module](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/add-a-module.html).
- Look at the three examples in the script folder: `add_values.hdvp` and `count_blobs.hdvp` with their interface files, and `convert_length.hdvp`, whose documentation carries the types. They are a good starting point.

# Prepare a HALCON Procedure – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html

The Script Runner runs HALCON **procedures**. It reads a procedure’s declared interface and builds one node per parameter, so the interface must say what every parameter holds. This guide shows how to get there in HDevelop.

## 1. Make it a procedure

The Script Runner can pass inputs only to a procedure and read only a procedure’s outputs. If your vision logic is an HDevelop program (`.hdev`) with a `main`:

1. In HDevelop select the lines of your logic and choose **Create New Procedure**.
2. Declare the interface: which iconic objects and control values go in and come out.
3. Save the procedure as an **external procedure** (`<name>.hdvp`). The file name is the procedure name.

Rules for the interface:

- Input or output is what the interface declares. The Script Runner never guesses it from the body.
- Every parameter name must be unique within the procedure. A procedure cannot use one name for an input and an output; to carry a value from one run to the next, see [A value carried from run to run](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html#carried-value).
- Parameter names become node names in kebab case: `MinScore` becomes `min-score`, `ROIRow` becomes `roi-row`. Two parameters must not give the same node name.
- The output names `status-code`, `status-text` and `package-identifier` are reserved: no output parameter may give one of them.

## 2. Describe every input and output {#parameter-information}

To run a procedure, the Script Runner has to know each of its arguments. It needs two kinds of information:

- **The shape:** which parameters are inputs and which are outputs, which are images (iconic) and which are values (control), their names and their order. The Script Runner reads the shape from the procedure itself; the interface you declared in step 1 is enough.
- **The types:** what each parameter holds. For a value parameter that is integer, real, string or handle, one value or several. For an image parameter it is the pixel types and the channels. HALCON does not store this in the declared interface: a control parameter is a tuple that can hold anything. Without the type, the Script Runner cannot build a node of the right type, check a value the PLC writes, or check an output after a run.

You give the types in one of two ways:

| Approach | Use it when | Where the types are kept |
| --- | --- | --- |
| [1. Parameter documentation](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html#from-documentation) | You can edit the procedure in HDevelop. This is the recommended way. | Inside the `.hdvp` file. Nothing else has to be copied with it. |
| [2. Interface file](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html#from-interface-file) | The procedure is protected, you do not want to change it, or its documentation is incomplete. | In `<procedure>.interface.json` next to the procedure. Where the file and the documentation disagree, the file wins. |

Both can be mixed: the file only has to give the types the documentation lacks. A parameter that has no type from either refuses the module (`-10002`); the status text names the parameter.

### Approach 1: Export the procedure with parameter documentation {#from-documentation}

HDevelop documents a procedure’s parameters the same way as HALCON’s own operators. The fields are described in the *HDevelop User’s Guide* of HALCON 22.11, section 6.17.8.2 "Parameter Documentation" (in the HALCON help, or `doc` folder of the HALCON installation).

1. Open the procedure in HDevelop and choose **Procedures** > **Edit Procedure Interface** (`Ctrl+Shift+P`, `I`).
2. Open the documentation part of the dialog. It has a tab card for each parameter.
3. For each **control parameter** (value), fill in:
   - **Semantics**, for example `integer`, `real`, `string`, `number`, `angle.rad` or `filename.read`, or a handle type such as `shape_model`;
   - **Type List**: `integer`, `real`, `string` or `handle`;
   - **Multi Value**: `false` for one value, `true` or `optional` for several;
   - **Mixed Types**: leave it at `false`. A parameter that mixes strings and numbers is refused.
4. For each **iconic parameter** (image), fill in:
   - **Semantics** `image`;
   - **Pixel Types**: the pixel types the procedure accepts (`byte`, `uint2`, …);
   - **Multi Channel**: `false` for one channel, `true` for colour.
5. Optionally fill in **Default Value**, **Value Min**, **Value Max**, **Values** and **Description** of each input. The default is the node’s first value, the description goes into the node’s description, and the Script Runner refuses an input outside **Value Min** and **Value Max** before the procedure runs.
6. Save the procedure as an external procedure (`.hdvp`).

HDevelop saves the documentation in the `<docu>` part of the `.hdvp` file, one slot per field:

| Dialog field | Slot | What the Script Runner does with it |
| --- | --- | --- |
| Semantics | `sem_type` | Gives the type when `type_list` is empty (see below); `image`, `region` or `xld` for an iconic parameter; `angle.rad` and `angle.deg` give the unit. |
| Type List | `type_list` | Gives the type of a control parameter; the accepted pixel types of an image. |
| Multi Value | `multivalue` | One value gives a scalar node, several values an array node. |
| Mixed Types | `mixed_type` | `true` or `optional` refuses the parameter. |
| Multi Channel | `multichannel` | One channel or colour. |
| Default Value | `default_value` | The input node’s first value. |
| Value Min, Value Max | `valuemin`, `valuemax` | The range an input is checked against. |
| Values | `value_list` | The suggested values. |
| Description | `description` | The node’s description. |

Which slot decides the type of a control parameter:

- `type_list` decides when it is filled in.
- Only when `type_list` is empty does the Script Runner read the type from `sem_type`, and only from these labels: `integer`; `real`, `number`, `angle.`, `point.`; `string`, `filename*`; the handle labels `handle`, `dict`, `window`, `message`, `message_queue`, `serial`, `socket` and any `*_model`. Any other `sem_type` gives no type.
- One exception: a `type_list` of `integer` alone beside a handle label is read as a handle, with a warning in the log. That is how documentation from before HALCON 18, when handles were integers, describes a model; some of MVTec’s own procedures still do. See [Types from sem_type](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html#sem-type).

So a procedure needs no interface file when every control parameter has a `type_list`, or one of the `sem_type` labels above, and every image parameter has the `sem_type` `image` (or pixel types in its `type_list`).

This is one parameter of the example `convert_length.hdvp`, which needs no interface file:

```xml
<parameter id="Length">
<default_type>real</default_type>
<default_value>25.4</default_value>
<description lang="en_US">The length to convert.</description>
<mixed_type>false</mixed_type>
<multivalue>false</multivalue>
<sem_type>real</sem_type>
<type_list>
<item>real</item>
</type_list>
<valuemin>0</valuemin>
</parameter>
```

A procedure whose parameters were never documented has only `<parameter id="Length"/>` there. No type can be read from it, and its module is refused until approach 2 gives the types.

### Approach 2: Configure the interface by hand in an interface file {#from-interface-file}

An interface file is a JSON file named `<procedure>.interface.json` in the script folder, next to the procedure. It lists every parameter of the procedure with its type. You do not have to type it from scratch: the Script Runner shows the procedure’s shape in the format of an interface file, and you add the types. The Script Runner can also build the file for you over the Data Layer, see [Building one over the Data Layer](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#over-the-data-layer).

1. Copy the procedure into the script folder, add a module for it to the application file and restart the app, see [Add a Module](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/add-a-module.html). The module is refused (`-10002` or `-10005`), but its `script/` nodes are there.

2. Read `v1/<module>/script/interface`. It lists every parameter with `group` (`input_iconic`, `output_iconic`, `input_ctrl`, `output_ctrl`), `name`, `position` and `dimension`; each parameter without a type is marked `"typeSource": "missing"`.

3. Save that JSON as `<procedure>.interface.json` next to the procedure. Delete every `typeSource` and the top-level `interfaceHash`, and add the type of each parameter:
   - a control parameter gets `elementTypes` (`["integer"]`, `["real"]`, `["string"]` or `["handle"]`) and, for several values, `"multivalue": "true"`;

   - an iconic parameter gets `"objectClass": "image"`, `pixelTypes` (for example `["byte"]`) and, for colour, `"multichannel": "true"`.

     Optionally add `description`, `unit`, `default`, `min`, `max` and `values`. All fields are listed in [Interface File](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#parameter).

4. Restart the app. The types changed the interface, so the module reports `-10005`, and its `status/text` gives the new hash (`… now sha256:…`). Copy that hash into the module’s `acceptedInterfaceHash` in the application file and restart again.

5. Read `v1/<module>/status/code` and `script/interface-source`. Expected: `0` and `interface-file` (or `mixed`, when some types still come from the documentation).

When it loads the file, the Script Runner checks it against the procedure, so a file that does not fit is refused (`-10002`) instead of being half applied:

- Every parameter of the procedure must be in the file, and every parameter in the file must be in the procedure. The status text names each one that is missing on either side.
- Each parameter must be in the same group (input or output, iconic or control) and have the same dimension as in the procedure.
- A parameter must not be listed twice.
- Each type must be in the [closed type set](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html#closed-type-set).

The file matches parameters by name, not by position: reordering the parameters in HDevelop needs no change to the file, but renaming one does. A worked example with a complete file is in [Writing one from the procedure’s shape](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#from-the-shape).

## 3. Use types the Data Layer can carry

See [Type Mapping](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html) for the complete table. In short:

- **Numbers and strings** become nodes. One value is a scalar node, several values (`multivalue` `true` or `optional`) an array node.
- **Do not mix strings and numbers** in one parameter: such a parameter is refused.
- **Images** become image groups. Mono8, Mono12, Mono16, RGB8 and BGR8 are carried.
- **Regions and contours (XLD)** are not carried. A region or contour **input** refuses the module. A region or contour **output** gets no node: convert it before `return ()`, for example `region_to_bin` or `paint_region` for an image, `area_center` or `get_region_points` for coordinates, `paint_xld` for a contour.
- **Handles** (`shape_model`, `dict`, any model) never cross the Data Layer. A handle input must be bound to the group’s store; a handle output goes to the store by default. See [Share a Model Between Scripts](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/share-a-model-between-scripts.html).
- **A structured value** is declared with the plain types: a pose is 7 `real` values, a `hom_mat2d` 6.

## 4. Files the procedure reads

A string input of the semantic type `filename` (`filename.read`, …) is resolved inside the script folder: the client writes `blobs.png`, the procedure gets the full path. Put model files, images and other data your procedure reads into the script folder. See [The script folder](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html#script-folder).

## 5. Leave out the display

The Script Runner runs without a display. By default the display operators (`dev_display`, `dev_set_color`, …) do nothing, and `dev_open_window` and `dev_get_window` fail. Remove window operators from the procedure, or guard them. See `ignoreDisplay` in [engine](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html#engine).

## 6. Test it

1. Test the procedure in HDevelop with typical and with bad inputs.
2. For a bad input, raise an error yourself with `throw`: the text arrives in the module’s `run/output/status-text` with code `-10001`.
3. Make sure every output is set on every path through the procedure: an output the procedure never set fails the run with `-10003`.
4. Every output must match its declared type. An integer where a real is declared is converted; anything else fails the run with `-10003`.

## 7. Protect it (optional)

You can lock the procedure with a password in HDevelop. The Script Runner still reads its interface and runs it; the password never reaches the device. Keep an unlocked copy: only the password holder can view or change the body.

If you use an interface file, write it **before** you protect the procedure, from the open procedure.

## Next

Copy the procedure (and its interface file) into the script folder, then [Add a Module](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/add-a-module.html).

# Add a Module – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/add-a-module.html

A module runs one procedure and gets its own nodes under `v1/<module>/`. This guide adds a module `find` that runs a procedure `find_pattern`.

You need a procedure prepared as described in [Prepare a HALCON Procedure](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html).

## 1. Copy the procedure

Copy `find_pattern.hdvp`, and its interface file `find_pattern.interface.json` if it has one, into the script folder, see [Settings Folder](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html#location). Copy any file the procedure reads there too.

## 2. Add the module to the application file

Open `lumiscan-script-runner.json` in the settings folder and add an entry to `modules`:

```json
{
    "name": "find",
    "procedure": "find_pattern",
    "trigger": "handshake"
}
```

- `name` is the module’s name on the Data Layer: lower case, only `a-z`, `0-9`, `-` and `_`. `system`, `api-version` and `v` followed by digits are reserved.
- `procedure` is the file name without `.hdvp`.
- Without `inputs` and `outputs` every value and image parameter gets a node. To give a parameter a fixed value, or to take it from the group’s store, add a binding, see [Bindings](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html#bindings).
- Without `group` the module is a group of its own. Modules that share a model go into one group, see [Share a Model Between Scripts](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/share-a-model-between-scripts.html).

Alternatively write the whole application file to `v1/system/settings` over the Data Layer: it is checked and saved, and `v1/system/restart-required` turns `true`.

## 3. Start the app and read the interface hash

1. Restart LumiScan Script Runner.

2. Read `v1/find/status/code`. Expected: `-10005`. A new module has no accepted interface hash yet, so its nodes are not built; `status/text` says so.

   If the code is `-10002` instead, the procedure did not load or its interface cannot be mapped: `status/text` names the parameter. Correct the procedure or its interface file, then restart. See [Troubleshooting](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#ts-script-not-loaded). When the text says a parameter `has no type`, write an interface file from the shape `script/interface` shows, see [Writing one from the procedure’s shape](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#from-the-shape).

3. Read `v1/find/script/interface`. Check the parameters, their types and where the types come from (`typeSource`).

4. Read `v1/find/script/interface-hash`, for example `sha256:4f1c…`.

## 4. Accept the interface

The accepted hash says: *this is the interface my PLC program is written for*.

1. Copy the hash into the module’s entry:
   ```json
   {
       "name": "find",
       "procedure": "find_pattern",
       "trigger": "handshake",
       "acceptedInterfaceHash": "sha256:4f1c…"
   }
   ```
2. Restart the app.
3. Read `v1/find/status/code`. Expected: `0`. The module’s input and output nodes are under `v1/find/run/`.

Note the accepted hash in your PLC project. Your PLC program can compare it with `v1/find/script/accepted-interface-hash` at its start.

## 5. Test the module

Run it once with the `run` handshake, as in [Run Your First Script](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/run-your-first-script.html). Then connect your PLC function block, see [The run Handshake](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/run-handshake.html).

## Removing a module

Delete its entry from `modules` and restart the app. Its nodes are gone after the restart. The procedure file can stay in the script folder.

# Share a Model Between Scripts – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/share-a-model-between-scripts.html

A HALCON handle, such as a shape model, lives in the Script Runner’s memory and never crosses the Data Layer. Procedures that use the same handle run in one **group** and pass it through the group’s **store**. This guide reads a shape model from a file once at start and uses it in every run of a search procedure.

The two procedures:

```
load_model ( : : ModelFile : ModelID)
find_pattern (Image : Overlay : ModelID, MinScore, MaxMatches : Row, Column, Angle, Score)
```

`ModelID` is a `handle` in both (`type_list` `handle`, `sem_type` `shape_model`).

## 1. Put both modules into one group

```json
"modules": [
    {
        "name": "load",
        "procedure": "load_model",
        "group": "line-1",
        "trigger": "start",
        "inputs":  { "ModelFile": { "from": "value", "value": "part.shm" } },
        "outputs": { "ModelID":   { "to": "store", "key": "model" } },
        "acceptedInterfaceHash": "sha256:…"
    },
    {
        "name": "find",
        "procedure": "find_pattern",
        "group": "line-1",
        "trigger": "handshake",
        "inputs":  { "ModelID": { "from": "store", "key": "model" } },
        "acceptedInterfaceHash": "sha256:…"
    }
]
```

What happens:

- `load` has `trigger` `start`: it runs once when the group starts, before any request is served. It has no `run` function and no input or output nodes.
- `ModelFile` gets the fixed value `part.shm`, resolved in the script folder.
- `load` writes its `ModelID` output into the store of group `line-1` under the key `model`. A handle output goes to the store even without the binding, and so does every output of a `start` module; the key is then the parameter name.
- `find` reads `ModelID` from the same key. It gets no node for `ModelID`; its other parameters get nodes: `run/input/image/…`, `run/input/min-score`, `run/input/max-matches`, `run/output/overlay/…`, `run/output/row`, `column`, `angle`, `score`.

Put `part.shm` into the script folder, accept both interface hashes (see [Add a Module](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/add-a-module.html)) and restart the app.

## 2. Use it

The PLC calls `find/run` as often as it needs; every run uses the model `load` read at start.

- If `load` fails at start, `load/status/code` is `-10002` and its `status/text` gives the reason. The key stays empty, and every `find` run ends with `-10004` (store value missing); the status text names the key and the module that writes it.
- Before each run the Script Runner checks that the handle taken from the store is still valid and, where the interface gives a semantic type, that it is the right kind of handle. If not, the run ends with `-3` and the procedure does not run.

## Variant: train the model at run time

Replace the start module by a handshake module that trains the model from a camera image:

```json
{
    "name": "train",
    "procedure": "train_model",
    "group": "line-1",
    "outputs": { "ModelID": { "to": "store", "key": "model" } },
    "acceptedInterfaceHash": "sha256:…"
}
```

The PLC calls `train/run` once, then `find/run` as often as it likes. The next `find` after a new `train` uses the new model. A `find` before any `train` ends with `-10004`. The store is written only after a successful run whose outputs passed the output check, so a failed `train` keeps the old model.

## Good to know

- A group has one worker thread. Its modules run one after the other, never at the same time, so a handle is never used by two threads. A request to a module whose group is busy is acknowledged (`running` `true`) and waits in the group’s queue, first in, first out.
- Modules without shared state should not share a group: put them into groups of their own (or leave out `group`), and they run in parallel.
- The store lives in memory only. After a restart of the app the `start` modules fill it again. To keep a trained model across restarts, write it to a file in the procedure (`write_shape_model`) and read it in a start module (`read_shape_model`).
- Procedures written before HALCON 18, and some of MVTec’s own, document a model ID with `type_list` `integer`. Beside a handle label such as `shape_model` the Script Runner reads it as a handle anyway and logs a warning, see [Types from sem_type](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html#sem-type).

See [Modules, Groups and the Store](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html).

# Replace a Script – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/replace-a-script.html

You improved a procedure and want the new version to run. What to do depends on whether its **interface** changed.

## Same interface: replace the file

The interface is unchanged when no parameter was added, removed, renamed, moved to another group or given another type. Reordering parameters within a group does not change it, and neither does a change to the body, the description, the default value or min and max.

1. Copy the new `<procedure>.hdvp` (and the interface file, if it changed) into the script folder.
2. Restart the app.
3. Check: `v1/<module>/status/code` is `0`. `v1/<module>/script/procedure-hash` shows the new file’s hash; `script/interface-hash` is unchanged.

The new vision logic runs behind the same nodes. Your PLC program needs no change.

## Changed interface: accept it on purpose

A changed interface changes the module’s nodes and breaks PLC programs written for the old ones. The Script Runner therefore never applies it on its own:

1. Copy the new procedure into the script folder and restart the app.
2. Read `v1/<module>/status/code`. Expected: `-10005` (interface changed). `status/text` gives the accepted and the current hash. The module keeps only its `status/`, `script/` and fixed `run` nodes and accepts no request.
3. Compare `v1/<module>/script/interface` with what your PLC program expects. Adapt the PLC program.
4. Copy `v1/<module>/script/interface-hash` into the module’s `acceptedInterfaceHash` in the application file and restart the app.
5. Check: `status/code` is `0`, and the new nodes are there.

List a changed interface in your own release notes: for everyone who calls the module it is a breaking change.

## Going back

Copy the previous procedure file back into the script folder and restart the app. If its interface hash is the accepted one, the module is built as before.

See [Interfaces and Hashes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interfaces-and-hashes.html).

# Installing the Script Runner – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/installation.html

## Before you start

- The PC meets the [Requirements](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/requirements.html).
- You have the HALCON delivery and the LumiScan Script Runner installer (Windows) or package (Ubuntu).
- LumiScan Keryx is installed on the PC.

## 1. Install HALCON

1. Install MVTec HALCON 22.11 with its runtime licence, **for all users**. HALCON’s installer then sets the system environment variable `HALCONROOT` and puts HALCON’s program folder on `PATH`.
2. Check: the file `%HALCONROOT%\bin\x64-win64\halcon.dll` exists.

The Script Runner does not bring HALCON’s libraries with it: it uses the HALCON installation. Before it installs anything, its installer checks two things:

- the **system** environment variable `HALCONROOT` is set (a HALCON installed for one user only sets a user variable, which does not count);
- `bin\x64-win64\halcon.dll` exists in the folder `HALCONROOT` names.

If either is missing, the installer stops with the message *LumiScan Script Runner needs MVTec HALCON 22.11 (Steady) with a runtime licence, and HALCON was not found*, and installs nothing. See [Troubleshooting](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#ts-installer-halcon).

1. Install MVTec HALCON 22.11 for Linux (`x64-linux`) with its runtime licence.
2. For the user who starts the Script Runner, set the environment variable `HALCONROOT` to the HALCON folder and put `$HALCONROOT/lib/x64-linux` on `LD_LIBRARY_PATH`, for example in `~/.profile`. Sign out and in again.
3. Check: the file `$HALCONROOT/lib/x64-linux/libhalcon.so` exists, and `echo $LD_LIBRARY_PATH` shows its folder.

The Script Runner does not bring HALCON’s libraries with it: it uses the HALCON installation.

> [!IMPORTANT]
> The Script Runner runs only with HALCON 22.11 (any 22.11.x) and checks that at every start: with HALCON of another release it stops. The installer checks only that HALCON is installed, not its release. See [HALCON 22.11 only](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/requirements.html#halcon-release).

## 2. Install the Script Runner

1. Run the LumiScan Script Runner installer as an administrator. It installs for all users of the PC and adds a Start menu entry and a desktop shortcut.
2. Plug the LumiScan Key into the PC.

1. Install the package:
   ```shell
   sudo apt install ./lumiscan-script-runner_<version>_amd64.deb
   ```
2. Plug the LumiScan Key into the PC.

The installation holds the program, the shipped settings (`etc`) and the licence texts of the third-party software it uses (`licenses`, with `THIRD-PARTY.txt`).

## 3. Start it the first time

1. Start LumiScan Keryx.
2. Start LumiScan Script Runner: on Windows **LumiScan Script Runner** from the Start menu, on Ubuntu `lumiscan-script-runner` in a terminal in which `HALCONROOT` and `LD_LIBRARY_PATH` are set.

At the first start the Script Runner copies its shipped settings into its [settings folder](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html): the application file `lumiscan-script-runner.json`, its JSON schema and, into a script folder that holds no procedure yet, three example procedures. It then sets up HDevEngine, checks the HALCON licence, loads the procedures and publishes its nodes under `hdvisionsystems/lumiscan-script-runner`.

Check that it runs:

- `hdvisionsystems/lumiscan-script-runner/api-version` is `1`.
- `v1/system/status-text` is `Initialized`.
- `v1/system/engine/license-valid` is `true`, and `v1/system/engine/version` shows the HALCON version.
- `v1/add/status/code`, `v1/blobs/status/code` and `v1/convert/status/code` are `0`: the three example modules are ready.

Then follow [Run Your First Script](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/run-your-first-script.html).

## Connecting to LumiScan Keryx

By default the Script Runner connects to LumiScan Keryx on the same PC. To use another broker, start the program with the options `--keryx-backend` and `--keryx-url`; `lumiscan-script-runner --help` lists them. See the [LumiScan Keryx manual](https://docs.hdvisionsystems.com/en/lumiscan-keryx/index.html).

## Updating and uninstalling

Install a new version over the old one. Your settings folder, the application file and the procedures in the script folder are kept: the application file and its schema are copied only where they are missing, and the example procedures only into a script folder without any procedure. So an example that is new in a version does not appear in a script folder you already use: copy it from the installation’s `etc/scripts` folder and add its module from the installation’s `etc/lumiscan-script-runner.json`.

On Windows, run the new installer; the installation is by default `C:\Program Files\HD Vision Systems GmbH\LumiScan Script Runner`. Uninstall the Script Runner in the Windows settings under **Apps**.

On Ubuntu, install the new package with `sudo apt install ./lumiscan-script-runner_<version>_amd64.deb`. Uninstall the Script Runner with `sudo apt remove lumiscan-script-runner`.

The settings folder stays on the PC; delete it yourself if you no longer need it.

# Settings Folder – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html

## Location {#location}

The settings folder holds the application file, its schema and, by default, the script folder:

| Platform | Settings folder |
| --- | --- |
| PC (Windows) | `%APP_RESOURCE_DIR%\etc\lumiscan-script-runner`; without `APP_RESOURCE_DIR`, `C:\ProgramData\HD Vision Systems GmbH\LumiScan Vision Suite\lumiscan-script-runner\etc\lumiscan-script-runner` |
| PC (Ubuntu) | `$APP_RESOURCE_DIR/etc/lumiscan-script-runner` |

The Script Runner names the folder it uses in its log at start (`Script folder: …`).

## Content

| File or folder | Content |
| --- | --- |
| `lumiscan-script-runner.json` | The [application file](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html): the script folder, the engine settings and the modules. |
| `schemas/lumiscan-script-runner.schema.json` | The JSON schema of the application file. Editors such as Visual Studio Code use it to check the file and to complete keys while you type. |
| `scripts/` | The script folder (the default of `scriptFolder`): your procedures `<name>.hdvp`, their interface files `<name>.interface.json` and any files they read, such as images or models. |

## The script folder {#script-folder}

- The Script Runner loads every `.hdvp` file of the script folder at start. A module runs the procedure of the same name: `"procedure": "find_pattern"` runs `find_pattern.hdvp`.
- An interface file `<procedure>.interface.json` next to a procedure gives the types of its parameters, see [Interface File](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html).
- A file name a procedure gets as an input (a parameter of the semantic type `filename`) is resolved inside the script folder: `blobs.png` means `scripts/blobs.png`.
- The script folder is also HALCON’s procedure path: a procedure may call other procedures of the folder, and MVTec’s standard procedures load on their own.
- `scriptFolder` in the application file may name another folder, relative to the settings folder or absolute.

`v1/system/scripts` lists the procedures found, with their procedure and interface hashes, where their types come from, and why a procedure did not load.

## When changes take effect {#changes}

The Script Runner reads the application file and the procedures at start.

- **A change to a file** (the application file, a procedure, an interface file) takes effect at the next start of the app.
- **A change over the Data Layer** (a new `v1/system/settings`) is checked and saved; the app then sets `v1/system/restart-required` to `true`, and every module reports `-5` (restart required) and accepts no new request until the app is restarted. A run that is going on finishes.

Restart the app after every change.

# Modules, Groups and the Store – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html

## Modules

A **module** is one procedure with its own nodes. Each entry of `modules` in the [application file](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html) is one module. Several modules may run the same procedure, each with its own bindings.

How a module is started is its `trigger`:

| Trigger | Meaning |
| --- | --- |
| `handshake` (default) | The module has a `run` function. A client starts a run with the [run handshake](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/run-handshake.html). |
| `start` | The module runs once when its group starts, before the group serves any request. It has no `run` function and no input or output nodes. Use it to read a model, open a dictionary or set up any state that the group’s other modules use. |

## Groups

A **group** is one worker thread and one store. The modules of a group run one at a time, in the order their requests arrive. A module without `group` is a group of its own.

- Modules that share a handle **must** be in one group: HALCON handles are not safe to use from two threads at once.
- Modules without shared state should be in groups of their own: different groups run in parallel.
- While one module of a group runs, the other modules of the group stay `ready`. A request to them is acknowledged (`running` turns `true`) and waits in the group’s queue until it is its turn.

`v1/system/groups` lists every group with its modules and the keys in its store.

## The store

The **store** of a group maps a key to a HALCON value: a control tuple (a handle is one) or an iconic object such as an image. Values never cross the Data Layer: a client can see which keys exist (`v1/system/groups`), never their content.

- An output bound to the store is written only after a successful run whose outputs passed the output check.
- An input bound to the store that finds its key empty ends the run with `-10004`; the status text names the key and the modules that write it.
- Before each run every handle taken from the store is checked: still valid, and of the semantic type the interface declares, if it declares one. A mismatch ends the run with `-3`; the procedure does not run.
- The store lives in memory only. It is empty after a restart; `start` modules fill it again.

## Bindings {#bindings}

Every parameter has a binding: where an input comes from, where an output goes. Set them under `inputs` and `outputs` of a module, keyed by the parameter name.

| Direction | Binding | Meaning |
| --- | --- | --- |
| Input | `node` (default for values and images) | A node under `run/input/`. The client writes it. |
| Input | `store` | Read from the group’s store under `key` (the parameter name when `key` is left out). No node. Required for a handle input. |
| Input | `value` | A fixed value from the settings. No node. A file name is resolved in the script folder. |
| Output | `node` (default for values and images) | A node under `run/output/`. |
| Output | `store` (default for handles) | Written to the group’s store under `key` (the parameter name when left out). No node. |
| Output | `both` | Node and store. |
| Output | `none` | Dropped. |

## A value carried from run to run {#carried-value}

A procedure cannot use one name for an input and an output. To carry a value from one run to the next, give the procedure an output and an input and bind both to the same store key:

```json
"inputs":  { "TrackState":    { "from": "store", "key": "track" } },
"outputs": { "TrackStateOut": { "to": "store",   "key": "track" } }
```

The first run finds the key empty and ends with `-10004`, unless a `start` module of the group fills it first.

## Two modules in a row {#chain}

Two handshake modules of one group can pass values by name: module A’s output `{"to": "store"}` and module B’s input `{"from": "store"}`, both without a key, use the parameter name. B takes A’s last value of that name. This only works inside one group, whose single worker keeps the runs in order.

# Interfaces and Hashes – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interfaces-and-hashes.html

The nodes of a module follow from its procedure’s interface. If the interface changes, the nodes change, and a PLC program written for the old nodes breaks. The Script Runner makes sure this never happens unnoticed.

## Bound by name

The Script Runner passes every parameter to HALCON by its **name**, never by its position. You may reorder the parameters of a procedure without breaking anything; the position is used only for the display order.

## Where the types come from

HALCON’s documentation of a procedure is advisory: the engine does not enforce it. The Script Runner therefore reads the types once, from the procedure’s documentation or from its [interface file](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html), and enforces them itself:

- before a run: the minimum and maximum of numbers, and the pixel type and channels of images (`-3`);
- after a run: every output against its declared type, before anything is written (`-10003`).

`v1/<module>/script/interface-source` says where the types came from: `documentation`, `interface-file`, or `mixed`. Where the documentation and the interface file disagree, the file wins and the Script Runner logs a warning.

## The four hashes

| Hash | Where | What it is for |
| --- | --- | --- |
| Current interface hash | `v1/<module>/script/interface-hash`, `v1/system/scripts` | What the procedure and its interface file declare now. |
| Accepted interface hash | `acceptedInterfaceHash` of the module in the application file; `v1/<module>/script/accepted-interface-hash` | The interface the module’s nodes, and your PLC program, were built for. |
| Interface file hash | `interfaceHash` inside the interface file (optional) | Shows that an interface file was edited by hand: a stored hash that does not match the content gives a warning. |
| Procedure hash | `v1/<module>/script/procedure-hash` | The SHA-256 of the procedure file’s bytes. It changes with every change to the body. Not checked; for your records. |

The interface hash is the SHA-256 of the interface, sorted by group and then by name: each parameter’s name, group, dimension, semantic type, element or pixel types and whether it takes several values. It does **not** contain the position, the description, the unit, the default value, min and max, or the HALCON modules the procedure needs. So the hash changes when a parameter is added, removed, renamed, moved to another group or retyped, and stays the same otherwise.

## What happens at start

At every start the Script Runner computes the current hash of each module’s procedure and compares it with the module’s accepted hash:

- **Equal:** the module is built with its nodes.
- **Different, or no accepted hash:** the module is refused with `-10005` (interface changed). It keeps its `status/`, `script/` and fixed `run` nodes, so you can read the current interface and its hash, but it accepts no request.

Only you set the accepted hash: in the application file, or by saving an interface file with `interface-save`, which writes the new hash into the modules that run the procedure (see [Building one over the Data Layer](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#over-the-data-layer)). A copied procedure file can therefore never move a PLC program’s nodes on its own. See [Replace a Script](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/replace-a-script.html).

> [!TIP]
> Store the accepted hash in your PLC program and compare it with `v1/<module>/script/accepted-interface-hash` when the PLC starts. Then the PLC knows that the module serves the nodes it expects.

# Application File – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html

`lumiscan-script-runner.json` in the [settings folder](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html) holds all settings of the Script Runner. It is read at start; see [When changes take effect](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html#changes). The shipped file states every setting. Its JSON schema is `schemas/lumiscan-script-runner.schema.json` next to it.

## Example

```json
{
    "$schema": "schemas/lumiscan-script-runner.schema.json",
    "apiVersion": 1,
    "scriptFolder": "scripts",
    "engine": {
        "threadNum": 1,
        "useSpinLock": false,
        "startUpThreadPool": false,
        "jitCompiled": false,
        "ignoreDisplay": true
    },
    "modules": [
        {
            "name": "blobs",
            "procedure": "count_blobs",
            "group": "vision",
            "trigger": "handshake",
            "inputs": {
                "ImageFile": { "from": "node" },
                "MinGray": { "from": "node" },
                "MinArea": { "from": "node" }
            },
            "outputs": {
                "Binary": { "to": "node" },
                "Count": { "to": "node" },
                "Areas": { "to": "node" },
                "MeanGray": { "to": "node" }
            },
            "mono12Shift": 0,
            "acceptedInterfaceHash": "sha256:d7b6f8ff6d772a1392512bf7d11d1d00050e7fc9fc4045da50d566ea6676e64d"
        }
    ]
}
```

## Top level

| Key | Type | Default | Meaning |
| --- | --- | --- | --- |
| `apiVersion` | integer | `1` | The Data Layer API version the app serves. Only `1` is valid; any other value stops the app at start. |
| `scriptFolder` | string | `"scripts"` | The script folder, relative to the settings folder or absolute. Must not be empty. |
| `engine` | object | see [`engine`](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html#engine) | How HALCON and HDevEngine are set up. |
| `modules` | array | `[]` | The modules, see [`modules`](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html#modules). Their order is the order on the Data Layer. |

## `engine` {#engine}

These settings put HALCON into a CPU-friendly state before the first operator runs. They apply to the whole app.

| Key | Type | Default | Meaning |
| --- | --- | --- | --- |
| `threadNum` | integer | `1` | How many threads HALCON may use to parallelise one operator (HALCON’s `thread_num`), `0` to `1024`. `0` keeps HALCON’s own default, which uses every core. Raise it only if the PC has cores to spare: the groups already run in parallel. |
| `useSpinLock` | boolean | `false` | HALCON’s spinlocks. They slow down severely with more threads than cores; leave them off. |
| `startUpThreadPool` | boolean | `false` | HALCON’s thread pool. It always spins and keeps cores busy; leave it off. |
| `jitCompiled` | boolean | `false` | Runs procedures JIT-compiled (HDevEngine’s `execute_procedures_jit_compiled`). Faster for loops; HALCON falls back to the interpreter on its own where it cannot compile. |
| `ignoreDisplay` | boolean | `true` | The display operators (`dev_*`) do nothing; `dev_open_window` and `dev_get_window` fail. The Script Runner has no display. |

The Script Runner never gives a HALCON thread real-time scheduling, and it sets HALCON so that an output a procedure never set fails the run instead of coming back empty.

## `modules` {#modules}

Each entry is one module, see [Modules, Groups and the Store](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html).

| Key | Type | Default | Meaning |
| --- | --- | --- | --- |
| `name` | string | required | The module’s name and its folder on the Data Layer (`v1/<name>/`). Lower case, only `a-z`, `0-9`, `-` and `_`. `system`, `api-version` and `v` followed by digits are reserved. Unique. |
| `procedure` | string | required | The procedure the module runs: the file name in the script folder without `.hdvp`. |
| `group` | string | the module’s name | The group the module runs in. Same rules as `name`. Modules that share store keys must be in one group. |
| `trigger` | string | `"handshake"` | `handshake`: the module has a `run` function. `start`: it runs once when its group starts and has no `run` function. The schema also lists `stream` and a `stream` section: they are reserved for a later version and not served in this one; do not use them. |
| `inputs` | object | every value and image input on a node | The input bindings, keyed by parameter name, see [Bindings](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html#bindings). |
| `outputs` | object | every value and image output on a node, every handle output to the store; in a `start` module every output to the store | The output bindings, keyed by parameter name, see [Bindings](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html#bindings). |
| `mono12Shift` | integer | `0` | Bits a `mono12` input image is shifted right before the procedure gets it, `0` to `4`. LumiScan X images need `4`. |
| `acceptedInterfaceHash` | string | none | The interface hash the module’s nodes were built for (`sha256:…`). Without it, or when it differs from the procedure’s current hash, the module is refused with `-10005`. See [Interfaces and Hashes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interfaces-and-hashes.html). |

## Bindings {#bindings}

`inputs` and `outputs` map a parameter name to a binding. A parameter without an entry gets its default.

**Table 1. Input binding**

| Binding | Meaning |
| --- | --- |
| `{ "from": "node" }` | A node under `run/input/` (default for value and image inputs). |
| `{ "from": "store", "key": "model" }` | Read from the group’s store under `key`; without `key`, under the parameter name. No node. Required for handle inputs. |
| `{ "from": "value", "value": 0.7 }` | A fixed value. No node. Only for number and string parameters, not for images or handles. `value` is required: a JSON number or string, or an array of them, that fits the parameter (an integer also fits a real parameter; a single-value parameter takes one value). A file name is resolved in the script folder. |

**Table 2. Output binding**

| Binding | Meaning |
| --- | --- |
| `{ "to": "node" }` | A node under `run/output/` (default for value and image outputs). |
| `{ "to": "store", "key": "model" }` | Written to the group’s store under `key`; without `key`, under the parameter name (default for handle outputs, and for every output of a `start` module). |
| `{ "to": "both", "key": "model" }` | Node and store. |
| `{ "to": "none" }` | Dropped. |

The module is refused (`-10002`, the status text names the parameter) when a binding names a parameter the procedure does not have, binds it in the wrong direction, puts a handle, a vector, a mixed tuple, a region or a contour input on a node, gives an image or a handle a fixed value, gives a fixed value that does not fit the parameter, or gives a `start` module a node.

## Checks at start

The app does not start, and logs why, when:

- the file is not valid JSON, or `apiVersion` is not `1`;
- a section has the wrong kind, `scriptFolder` is empty, `engine.threadNum` is not a whole number from 0 to 1024, or an `engine` switch is not `true` or `false`;
- a module entry is refused: it has no valid `name` or `group`, no `procedure`, an unknown `trigger`, a binding with an unknown `from` or `to`, a `value` binding without `value`, or a `mono12Shift` outside 0 to 4 (the log names the module);
- two modules have the same name.

A module whose procedure is missing, cannot be loaded or cannot be mapped is refused on its own with `-10002`; the other modules run.

# Interface File – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html

An interface file gives the types of a procedure’s parameters outside the procedure. Use it when a procedure is not documented in HDevelop, when you do not want to change the procedure, or before you protect it. It lies next to the procedure in the script folder and is named after it: `count_blobs.interface.json` for `count_blobs.hdvp`.

`v1/<module>/script/interface` shows the same format for the interface the module actually uses, with the field `typeSource` for each parameter.

## Example

```json
{
  "format": 1,
  "procedure": "count_blobs",
  "parameters": [
    { "group": "output_iconic", "name": "Binary", "position": 1, "dimension": 0,
      "objectClass": "image", "pixelTypes": ["byte"],
      "description": "the blobs white (255) on black, the size of the image" },
    { "group": "input_ctrl", "name": "ImageFile", "position": 1, "dimension": 0,
      "semType": "filename.read", "elementTypes": ["string"],
      "default": "blobs.png", "description": "an image file in the script folder" },
    { "group": "input_ctrl", "name": "MinGray", "position": 2, "dimension": 0,
      "elementTypes": ["integer"], "default": "128", "min": "0", "max": "255",
      "description": "the lowest gray value of a blob" },
    { "group": "output_ctrl", "name": "Areas", "position": 2, "dimension": 0,
      "elementTypes": ["integer"], "multivalue": "true", "unit": "px",
      "description": "each blob's area" }
  ]
}
```

## Top level

| Key | Type | Meaning |
| --- | --- | --- |
| `format` | integer | Required. `1`. |
| `procedure` | string | The procedure’s name. |
| `parameters` | array | Required. One entry per parameter of the procedure, see [Parameter entry](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#parameter). |
| `requiredModules` | array of strings | Optional. The HALCON modules the procedure needs, for example `["matching"]`. A module whose HALCON licence lacks one of them is refused with `-4`, and the status text names the missing HALCON module. Not part of the interface hash. |
| `interfaceHash` | string | Optional. The interface hash of the content (`sha256:…`). If it does not match, the Script Runner logs a warning: the file was changed by hand after it was written. |

## Parameter entry {#parameter}

| Key | Type | Meaning |
| --- | --- | --- |
| `group` | string | Required. `input_iconic`, `output_iconic`, `input_ctrl` or `output_ctrl`. |
| `name` | string | Required. The parameter’s name as in the procedure. |
| `position` | integer | 1-based position within its group. Display order only. |
| `dimension` | integer | `0` (a tuple or object), `1` (a vector) or `2` (a vector of vectors). Must match the procedure. |
| `semType` | string | Free label, for example `filename.read`, `angle.rad`, `shape_model`. |
| `elementTypes` | array of strings | Control parameters: `integer`, `real`, `string`, `handle`. |
| `multivalue` | string | Control parameters: `"false"` (default, one value), `"true"` or `"optional"` (several values). |
| `mixedTypes` | boolean | Control parameters: `true` when strings and numbers mix in one tuple. Such a parameter cannot be on a node. |
| `objectClass` | string | Iconic parameters: `image`, `region` or `xld`. |
| `pixelTypes` | array of strings | Images: the accepted pixel types, for example `["byte", "uint2"]`. |
| `multichannel` | string | Images: `"false"` (default, one channel), `"true"` or `"optional"`. |
| `description`, `unit` | string | Shown in the node’s description. |
| `default`, `min`, `max` | string | The default value (the input node’s first value) and the range of a number. An input outside `min` and `max` is refused with `-3`. |
| `values` | array | The suggested values, as in HALCON’s documentation. |

Type names outside the [closed type set](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html#closed-type-set) refuse the procedure and name the parameter. An iconic parameter must not have `elementTypes`, a control parameter must not have `objectClass` or `pixelTypes`.

## Building one over the Data Layer {#over-the-data-layer}

The Script Runner can build the file for you. Under `v1/system/` it serves six functions, each with the handshake of a module’s `run` ([Run Handshake](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/run-handshake.html)): write the inputs, set `request`, wait for `done` or `has-error`, read the outputs, set `request` back to `false`. Every input is a STRING node; every function has `output/status-code`, `output/status-text` and `output/package-identifier`.

| Function | Inputs | What it does |
| --- | --- | --- |
| `interface-scan` | `procedure` | Starts the procedure’s draft, if there is none yet, and writes it to `output/interface`: each parameter with group, position, name, dimension, type and `typeSource` (`documentation`, `interface-file`, `draft` or `missing`), `missing` (the parameters without a type), `interfaceHash`, and `interfaceFile` (the file’s name, whether it exists, whether it was used and its findings). |
| `interface-set-parameter` | `procedure`, `group`, `parameter`, `type` | Sets one parameter’s type in the draft. `group` is `input_ctrl`, `output_ctrl`, `input_iconic` or `output_iconic`; `parameter` is the name or the 1-based position in the group (the draft keeps the name); `type` is a JSON object with the fields of a [Parameter entry](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#parameter), for example `{"elementTypes":["integer","real"]}` or `{"objectClass":"image","pixelTypes":["byte"]}`. `output/interface` shows the draft afterwards. |
| `interface-load` | `procedure`, `content` | Takes an interface file’s JSON into the draft, with the rules of [How it is merged with the procedure](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#merge). `output/interface` shows the draft afterwards. |
| `interface-export` | `procedure` | Writes the draft as file content to `output/interface`, also while types are missing. |
| `interface-save` | `procedure` | Refused while a parameter has no type. Writes `<procedure>.interface.json` next to the procedure, sets `acceptedInterfaceHash` of every module that runs the procedure to the new hash, and ends the draft. `output/interface` holds the content written. |
| `interface-discard` | `procedure` | Drops the draft. |

There is one draft per procedure. It starts with the first function that names the procedure, from the procedure’s HDevelop documentation merged with its interface file, and lives until `interface-save` or `interface-discard` (or until the app stops). An interface file that no longer fits the procedure is left out of the draft: `interfaceFile.used` is `false`, and `interfaceFile.issues` says why.

A refused call ends with `has-error` and changes nothing. `status-code` is `-3` for a wrong input (a procedure that is not in the script folder, a type outside the [closed type set](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html#closed-type-set), a parameter in another group, a file that does not fit, a save with a type missing) and `-10002` for a procedure HDevEngine cannot load; `status-text` says which.

**Example:** `sum_values` is not documented in HDevelop and has no interface file.

1. Write `sum_values` to `interface-scan/input/procedure` and call `interface-scan`. `status-text`: `sum_values: 4 parameter(s) still need a type: A, B, Sum, Text`.
2. Call `interface-set-parameter` once per parameter, for example with `group` `input_ctrl`, `parameter` `A` and `type` `{"elementTypes":["integer","real"]}`, then with `parameter` `2` for `B`. Each call says which types are still missing.
3. Call `interface-save`. `status-text`: `saved sum_values.interface.json (sha256:…); acceptedInterfaceHash of module(s) sum set to it; restart the application …`.
4. The app cannot load the new file while it runs yet: `v1/system/restart-required` is `true`, and every module reports `-5`. Restart the app. The module is built with the new interface: `status/code` is `0`, `script/interface-source` is `interface-file`, and `script/accepted-interface-hash` equals `script/interface-hash`.

A module that does not exist yet when you save gets the hash when you add it: `status-text` gives it.

## Writing one from the procedure’s shape {#from-the-shape}

Without the functions above you can still write the file by hand. You do not have to type it from scratch. The Script Runner reads a procedure’s shape by itself: each parameter’s name, group, position and dimension. Only the types are missing. Start from that shape:

1. Copy the procedure into the script folder, add a module for it to the application file, and restart the app, see [Add a Module](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/add-a-module.html). The module is refused (`-10005` or `-10002`), but its `script/` nodes are there.
2. Read `v1/<module>/script/interface`. It holds the shape in the format of an interface file, each parameter without a type marked `"typeSource": "missing"`:
   ```json
   {
     "format": 1,
     "procedure": "multiply_values",
     "interfaceHash": "sha256:0d4aae06…",
     "parameters": [
       { "group": "input_ctrl", "name": "A", "position": 1, "dimension": 0, "typeSource": "missing" },
       { "group": "input_ctrl", "name": "B", "position": 2, "dimension": 0, "typeSource": "missing" },
       { "group": "output_ctrl", "name": "Product", "position": 1, "dimension": 0, "typeSource": "missing" }
     ]
   }
   ```
3. Save it as `<procedure>.interface.json` next to the procedure, then:
   - keep `group`, `name`, `position` and `dimension` as they are;
   - delete every `typeSource` (a copied `missing` is kept and reported as such) and the top-level `interfaceHash` (a stale one only gives a warning);
   - add the type of each parameter: `elementTypes` (and `multivalue`) for a control parameter, `objectClass` (and `pixelTypes`) for an iconic one.
     ```json
     {
       "format": 1,
       "procedure": "multiply_values",
       "parameters": [
         { "group": "input_ctrl", "name": "A", "position": 1, "dimension": 0, "elementTypes": ["real"] },
         { "group": "input_ctrl", "name": "B", "position": 2, "dimension": 0, "elementTypes": ["real"] },
         { "group": "output_ctrl", "name": "Product", "position": 1, "dimension": 0, "elementTypes": ["real"] }
       ]
     }
     ```
4. Restart the app. The types changed the interface, so the module reports `-10005`, and its `status/text` gives the new hash (`… now sha256:…`). Copy that hash into the module’s `acceptedInterfaceHash` and restart again. `status/code` is now `0`, and `script/interface-source` is `interface-file`.

You cannot rename a parameter in the interface file: the procedure gets its parameters by name, and each node’s name is made from it. To get another node name, rename the parameter in HDevelop.

## How it is merged with the procedure {#merge}

The file is matched to the procedure by group and name:

- Parameters in another order: fine, positions come from the procedure.
- A parameter missing in the file or in the procedure, a rename, a changed group or a changed dimension: the procedure is refused with `-10002`, and the text names the parameter.
- Where the file gives a type, it wins. If the procedure’s documentation says something else, a warning is logged.
- `semType`, `description`, `unit`, `default`, `min`, `max` and `values` of the file replace those of the documentation where the file gives them.

> [!TIP]
> Write the interface file from the open procedure **before** you protect it with a password, and ship both files.

# Type Mapping – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html

## Parameters to nodes {#parameters}

| Procedure parameter | Node | Notes |
| --- | --- | --- |
| Control, element type `integer` only | INT64 |   |
| Control, element types with `real` (also `number`, `angle.`, `point.`) | FLOAT64 | An integer the procedure returns for a real output is converted. |
| Control, element type `string` (also `filename*`) | STRING | A file name is resolved inside the script folder. |
| Any of the above with `multivalue` `true` or `optional` | ARRAY_OF_INT64, ARRAY_OF_FLOAT64, ARRAY_OF_STRING |   |
| Control, strings mixed with numbers | refused (`-10002`) |   |
| Control, `handle` (`shape_model`, `dict`, any model) | no node | An input must be bound to the group’s store; an output goes to the store by default. See [Modules, Groups and the Store](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html). |
| Iconic, object class `image` | image group | `<name>/data` (RAW), `width`, `height`, `pixel-type`, see [Images](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html#images). |
| Iconic input, region or contour (XLD) | refused (`-10002`) |   |
| Iconic output, region or contour (XLD) | no node | Convert it in the procedure, for example with `region_to_bin`. |
| A vector parameter (dimension 1 or 2) on a node | refused (`-10002`) | Bind it to the store, or use a tuple with several values instead. |

### Types from `sem_type` {#sem-type}

When `type_list` is empty, the type is taken from `sem_type` where it says one:

- `integer` gives an integer;
- `real`, `angle.` and `point.` give a real, `number` an integer or a real;
- `string` and `filename*` give a string;
- the handle labels `handle`, `dict`, `window`, `message`, `message_queue`, `serial`, `socket` and any `*_model` (`shape_model`, `ncc_model`, …) give a handle.

Any other `sem_type` is kept as a label and needs a `type_list` or an interface file.

A `type_list` of `integer` alone beside a handle label is read as a handle, and the log names the parameter with a warning. Before HALCON 18 handles were integers, and some of MVTec’s own procedures still document a model that way, for example `ModelID` of `dev_display_shape_matching_results` (`type_list` `integer`, `sem_type` `shape_model`). Any other `type_list` is taken as it is.

The node name is the parameter name in kebab case (`MinScore` → `min-score`), lower case, only `a-z`, `0-9`, `-` and `_`. The original name is the node’s display name. The parameter’s description ends with its unit, min, max and default, for example `the lowest gray value (min 0, max 255, default 128)`. An input node starts at the parameter’s default value.

## Images {#images}

An image parameter is a group of four nodes:

| Node | Type | Content |
| --- | --- | --- |
| `data` | RAW | The pixels, row by row without padding; 16-bit values little-endian. |
| `width` | UINT64 | Width in pixels. |
| `height` | UINT64 | Height in pixels. |
| `pixel-type` | STRING | `mono8`, `mono12`, `mono16`, `rgb8` or `bgr8`. |

| `pixel-type` | Image input becomes | Image output from |
| --- | --- | --- |
| `mono8` | `byte`, one channel | `byte`, one channel |
| `mono12` | `uint2`, one channel, shifted right by the module’s `mono12Shift` bits | – |
| `mono16` | `uint2`, one channel | `uint2`, one channel |
| `rgb8` | `byte`, three channels (r, g, b) | `byte`, three channels |
| `bgr8` | `byte`, three channels (r, g, b) | – |

- An input image is checked before the procedure runs: a known pixel type, width and height above 0, exactly width × height × bytes per pixel bytes, and a pixel type and channel count the parameter accepts. A failed check ends the run with `-3`.
- LumiScan X cameras put their 12 bits at the top of the 16-bit word. Set `mono12Shift` to `4` for such a module to give the procedure values from 0 to 4095.
- An image output must be exactly one image of pixel type `byte` (one or three channels) or `uint2` (one channel). Anything else fails the run with `-10003`: convert it in the procedure (`convert_image_type`, `scale_image_max`).

### Copy time {#image-copy-time}

Every image is copied into HALCON before the procedure runs, and every image output is copied out of HALCON after it. The copy adds to the run time. For a 5-megapixel frame (2448 × 2048) a development PC took per direction:

| `pixel-type` | Copy time per direction |
| --- | --- |
| `mono8` | about 1 to 3 ms |
| `mono16` | about 3 to 10 ms |
| `rgb8` | about 13 to 27 ms |

The time grows with the number of bytes; your PC may be faster or slower. Where the cycle time is tight, prefer `mono8`, and pass only the images the procedure needs.

## The closed type set {#closed-type-set}

HALCON has no user-defined types. The Script Runner, the interface file and the type checks know exactly these names:

- element types of control values: `integer`, `real`, `string`, `handle`;
- object classes of iconic objects: `image`, `region`, `xld`;
- pixel types: `byte`, `int1`, `int2`, `uint2`, `int4`, `int8`, `real`, `complex`, `cyclic`, `direction`, `vector_field`;
- multiplicity: `false` (one), `true` (several), `optional`;
- dimension: `0`, `1` or `2`.

A name outside this set refuses the procedure and names the parameter. `sem_type` is a free label, not a type: any label is kept.

# Data Layer Reference – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/datalayer-reference.html

All nodes are under `hdvisionsystems/lumiscan-script-runner/`. The app serves API version 1 only: everything but `api-version` is under `v1/`.

## Node tree

```
hdvisionsystems/lumiscan-script-runner/
  api-version                         UINT32, read-only: 1
  v1/
    system/
      settings                        the application file (JSON); writable, see below
      restart-required                BOOL8, read-only
      status-text                     STRING, read-only
      scripts                         STRING (JSON), read-only
      modules                         STRING (JSON), read-only
      groups                          STRING (JSON), read-only
      engine/
        version                       STRING, read-only
        license-valid                 BOOL8, read-only
        licensed-modules              ARRAY_OF_STRING, read-only
        edition, revision, arch       STRING, read-only
        library, halcon-root          STRING, read-only
      licenses/
        current/
          file, type, version         STRING, read-only
          valid                       BOOL8, read-only
          error-text                  STRING, read-only
          modules                     ARRAY_OF_STRING, read-only
          expiration-date, host-id    STRING, read-only
        files                         ARRAY_OF_STRING, read-only
      interface-scan/                 build an interface file, see Interface File
      interface-set-parameter/        each: request, ready, running, done, has-error,
      interface-load/                   input/procedure (STRING) and further STRING inputs,
      interface-export/                 output/status-code, status-text, package-identifier
      interface-save/                   and, but for interface-discard, output/interface (JSON)
      interface-discard/
    <module>/
      status/
        code                          INT32, read-only
        text                          STRING, read-only
      run/                            not for trigger "start"
        request                       BOOL8, written by the client
        ready, running, done, has-error   BOOL8, read-only
        input/
          <parameter>                 one node per value input on a node
          <image>/data, width, height, pixel-type
        output/
          status-code                 INT32, read-only
          status-text                 STRING, read-only
          package-identifier          UINT64, read-only
          <parameter>                 one node per value output on a node, read-only
          <image>/data, width, height, pixel-type
      setting/
        procedure, group, trigger     STRING, read-only
        bindings                      STRING (JSON), read-only
      script/
        interface                     STRING (JSON), read-only
        interface-source              STRING, read-only
        interface-hash                STRING, read-only
        accepted-interface-hash       STRING, read-only
        procedure-hash                STRING, read-only
        required-modules              ARRAY_OF_STRING, read-only
```

## `v1/system/`

| Node | Type | Content |
| --- | --- | --- |
| `settings` | JSON | The application file. Writing it checks the new content (the same checks as at start), saves it and sets `restart-required`; a refused write leaves everything as it was. See [When changes take effect](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html#changes). |
| `restart-required` | BOOL8 | `true` after the settings were changed: every module reports `-5` until the app is restarted. |
| `status-text` | STRING | The app’s state in words: `Initialized`; `the HALCON licence is not valid: …`; `No module configured: …`; or why it has to be restarted. |
| `scripts` | STRING (JSON) | The procedures of the script folder: file, procedure hash, interface hash, interface source and, for a procedure that did not load, the error. |
| `modules` | STRING (JSON) | Per module: group, procedure, trigger, state and both interface hashes. |
| `groups` | STRING (JSON) | Per group: its modules and the keys of its store. Never a value. |
| `engine/version` | STRING | HALCON’s version, for example `22.11.1.0`. |
| `engine/license-valid` | BOOL8 | `true` when HALCON’s licence is valid. |
| `engine/licensed-modules` | ARRAY_OF_STRING | The HALCON modules the licence covers. Empty without a valid licence. |
| `engine/edition`, `engine/revision`, `engine/arch` | STRING | HALCON’s edition (`steady`), maintenance revision (for example `4`) and architecture (`x64-win64`). |
| `engine/library` | STRING | The path of the `halcon.dll` the app loaded. |
| `engine/halcon-root` | STRING | The HALCON folder (`HALCONROOT`) as HALCON sees it. |
| `licenses/current/file` | STRING | The HALCON licence file in use. HALCON uses one licence: the file bound to this PC or to the plugged HALCON dongle. |
| `licenses/current/type` | STRING | `runtime` or `development`. |
| `licenses/current/valid` | BOOL8 | `true` when the licence in use is valid; the same as `engine/license-valid`. |
| `licenses/current/error-text` | STRING | HALCON’s own message when the licence is not valid; empty otherwise. |
| `licenses/current/version` | STRING | The HALCON release the licence is valid for, for example `22.11`. |
| `licenses/current/modules` | ARRAY_OF_STRING | The HALCON modules the licence covers; the same as `engine/licensed-modules`. |
| `licenses/current/expiration-date` | STRING | `permanent`, or the date the licence ends. |
| `licenses/current/host-id` | STRING | The PC or HALCON dongle the licence is bound to. |
| `licenses/files` | ARRAY_OF_STRING | Every licence file HALCON found. HALCON reports details only for the file in use. |
| `interface-scan/`, `interface-set-parameter/`, `interface-load/`, `interface-export/`, `interface-save/`, `interface-discard/` | functions | Build a procedure’s interface file over the Data Layer, with the same handshake as a module’s `run`. See [Building one over the Data Layer](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#over-the-data-layer). |

## `v1/<module>/`

| Node | Type | Content |
| --- | --- | --- |
| `status/code`, `status/text` | INT32, STRING | The module’s state, see [Module state](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/status-codes.html#module-state). |
| `run/…` |   | The `run` function, see [The run Handshake](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/run-handshake.html). The input and output nodes follow the [Type Mapping](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html); each node’s description holds the parameter’s description, unit, min, max and default, its display name is the parameter name. |
| `setting/procedure`, `group`, `trigger` | STRING | The module’s settings. `group` is the module’s own name when it has no group. |
| `setting/bindings` | STRING (JSON) | The module’s `inputs` and `outputs` bindings. |
| `script/interface` | STRING (JSON) | The interface the module uses, in the format of the [interface file](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html), with `typeSource` per parameter. |
| `script/interface-source` | STRING | `documentation`, `interface-file` or `mixed`. |
| `script/interface-hash` | STRING | The current interface hash, `sha256:…`. |
| `script/accepted-interface-hash` | STRING | The accepted interface hash from the application file. |
| `script/procedure-hash` | STRING | The SHA-256 of the procedure file. |
| `script/required-modules` | ARRAY_OF_STRING | The HALCON modules the procedure needs, from its interface file. A module whose HALCON licence lacks one reports `-4`. |

A module that is not built (status `-10002`, `-10005`) keeps `status/`, `setting/`, `script/` and the fixed `run` nodes, but has no input or output parameter nodes.

# The run Handshake – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/run-handshake.html

Every handshake module has one function, `run`, under `v1/<module>/run/`. It is the version 1 handshake of the LumiScan apps: one PLC function block serves every module of the Script Runner and every other app on version 1.

## Nodes

| Node | Type | PLC variable | Meaning |
| --- | --- | --- | --- |
| `run/request` | BOOL8 | `xExecute` | Written by the client. The run starts on its rising edge. |
| `run/ready` | BOOL8 |   | `true` when a request would be accepted now: the module is built, the licence is valid, no restart is pending, nothing is running, and `request` was `false` since the last run. |
| `run/running` | BOOL8 | `xBusy` | `true` from the acknowledge until the run ends, including the time a request waits in its group’s queue. |
| `run/done` | BOOL8 | `xDone` | `true` when the run succeeded and its outputs are written. |
| `run/has-error` | BOOL8 | `xError` | `true` when the run failed; `output/status-code` says why. |
| `run/output/status-code` | INT32 | `eErrorID` | The last run’s outcome: `0` or negative at the end, `2` while it runs. See [Status Codes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/status-codes.html). |
| `run/output/status-text` | STRING |   | The outcome in words. |
| `run/output/package-identifier` | UINT64 |   | Grows by one with every successful run. |
| `run/input/…` |   |   | One node or image group per input on a node. |
| `run/output/…` |   |   | One node or image group per output on a node. |
| `status/code`, `status/text` | INT32, STRING |   | The module’s state: why `ready` is `false`. |

## Sequence

| Step | Client | Module | `ready` | `running` | `done` | `has-error` |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | Waits for `ready` = `true`. | Idle. | `true` | `false` | `false` | `false` |
| 2 | Writes `run/input/…`. | Keeps the values. | `true` | `false` | `false` | `false` |
| 3 | Sets `request` = `true`. | Acknowledges (`status-code` `2`), **takes all inputs**, checks them and runs the procedure on its group’s worker. | `false` | `true` | `false` | `false` |
| 4 | Waits for `done` or `has-error`. | On success: writes the outputs, increments `package-identifier`, `status-code` `0`. On failure: `status-code` and `status-text`, no output written. Then `running` falls and `done` or `has-error` rises. | `false` | `false` | `true` on success | `true` on failure |
| 5 | Reads the outputs, or `status-code` and `status-text`. |   |   |   |   |   |
| 6 | Sets `request` = `false`. | Clears `done` and `has-error`, then sets `ready`. | `true` | `false` | `false` | `false` |

## Rules

- **The inputs are taken when the run starts.** A value written during a run is kept for the next run; it never changes the running one.
- **A failed input check ends the run before the procedure runs:** a missing or wrong-kind value, a number outside min and max, an image of the wrong pixel type or size, an invalid handle from the store. Code `-3`.
- **A failed run writes no output.** The output nodes keep the values of the last successful run. Check `done` (or `package-identifier`) before you use them.
- **Lowering `request` during a run does not stop it.** The run ends, and its `done` or `has-error` stays until the next acknowledge.
- **A request while `ready` is `false` is not acknowledged.** Read `status/code` and `status/text` of the module to see why.
- **There is no timeout.** A procedure runs until it returns; your PLC program times out on its side.
- **One writer per `request`.** Do not let two clients drive the same module.
- **A request in a busy group waits.** While another module of the same group runs, `ready` stays `true`; the request is acknowledged and waits in the group’s queue.

## PLC function block

Map one function block instance onto one module’s `run` folder:

| Function block | Node |
| --- | --- |
| `xExecute` (in) | `run/request` |
| `xBusy` (out) | `run/running` |
| `xDone` (out) | `run/done` |
| `xError` (out) | `run/has-error` |
| `eErrorID` (out) | `run/output/status-code` |

Write the module’s inputs before you raise `xExecute`, and read its outputs when `xDone` is `true`. Hold `xExecute` until you have read `xDone` or `xError`.

# Status Codes – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/status-codes.html

The Script Runner reports on two nodes per module:

- `v1/<module>/status/code` (with `status/text`): the **module’s state**. Anything but `0` means the module accepts no request, and `run/ready` is `false`.
- `v1/<module>/run/output/status-code` (with `run/output/status-text`): the **outcome of the last run**. At the end of a run it is `0` or negative; while a run is going on it is `2`. A client that uses `running`, `done` and `has-error` can ignore the `2`.

The status text always says more: the parameter, the HALCON error, the key or the hash concerned.

## Module state (`status/code`) {#module-state}

| Code | Name | Meaning and what to do |
| --- | --- | --- |
| `0` | ready | The module is built and accepts requests. |
| `-4` | missingLicense | A licence is missing: the HALCON runtime licence is not valid, or it does not cover a HALCON module the procedure needs (the text names it). See [Troubleshooting](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#ts-licence). |
| `-5` | restartRequired | The settings were changed over the Data Layer, or an interface file was saved with `interface-save`. Restart the app. |
| `-10002` | scriptNotLoaded | The procedure is missing, did not load, or its interface cannot be mapped (the text names the parameter), or the module’s `start` run failed. The module has only its `status/`, `script/` and fixed `run` nodes. See [Troubleshooting](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#ts-script-not-loaded). |
| `-10005` | interfaceChanged | The procedure’s interface hash is not the module’s accepted hash, or the module has no accepted hash yet. The text gives both hashes. Accept the current hash in the module’s `acceptedInterfaceHash`, or save the interface file with `interface-save`. See [Replace a Script](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/replace-a-script.html). |

## Run outcome (`run/output/status-code`) {#run-outcome}

| Code | Name | Meaning and what to do |
| --- | --- | --- |
| `0` | ok | The run succeeded; the outputs are written, `done` is `true`. |
| `2` | running | The run was acknowledged and is going on (or waits in its group’s queue). |
| `-3` | invalidInput | An input failed its check before the procedure ran: missing or of the wrong kind, outside min and max, an image of an unknown or unaccepted pixel type or of the wrong size, or a handle from the store that is invalid or of the wrong kind. The text names the input. |
| `-4` | missingLicense | HALCON refused an operator for licence reasons during the run, for example because the HALCON dongle was pulled. The module reports `-4` until the app is restarted with a valid licence. |
| `-10001` | scriptError | The procedure raised an error: its own `throw`, or a HALCON operator failed. The text names the procedure (or sub-procedure), the program line, the HALCON error number and the message. Window errors get a hint: the Script Runner has no display. |
| `-10003` | outputTypeMismatch | An output does not match the interface, or the procedure never set it. The text names the parameter, the declared and the returned type. No output is written. |
| `-10004` | storeValueMissing | An input bound to the group’s store found its key empty. The text names the key and the modules that write it. See [Modules, Groups and the Store](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html). |

On a failure `has-error` is `true` and no output node is written.

# Release Notes – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/release-notes.html

## Version 1.0.0 {#v1-0-0}

The first version of LumiScan Script Runner.

**New**

- HALCON procedures (`.hdvp`) run on HDevEngine and are published as modules on LumiScan Keryx, under `hdvisionsystems/lumiscan-script-runner/v1/`.
- One typed node per value parameter and an image group per image parameter, generated from the procedure’s documented interface or from an interface file next to it. Descriptions, units, min, max and defaults are carried over; inputs start at their defaults; min and max are checked.
- MVTec’s own procedures load from their documentation alone, also where it dates from before HALCON 18 and types a model as `integer`: beside a handle label in `sem_type` such a parameter is read as a handle, with a warning.
- The `run` handshake of API version 1 for every module, mapped one to one by a PLC function block.
- Groups with one worker thread and a store for HALCON handles and other values; bindings of each parameter to a node, the store or a fixed value; `start` modules that run once when their group starts.
- Interface hashes: a module is built only for its accepted interface hash, so a changed procedure never moves a PLC program’s nodes on its own.
- Interface files built over the Data Layer: `v1/system/interface-scan` lists the parameters still missing a type, `interface-set-parameter` sets one, `interface-load` takes a file in, and `interface-save` writes `<procedure>.interface.json` and sets the accepted hash of the modules that run the procedure. The app has to be restarted to load the file.
- Output check after every run: an output that does not match the interface is never written.
- Images Mono8, Mono12 (with a configurable shift), Mono16, RGB8 and BGR8 in, Mono8, Mono16 and RGB8 out.
- The HALCON in use on the Data Layer: `v1/system/engine/` gives its version, edition, revision, library and folder, `v1/system/licenses/` the HALCON licence in use, its type, validity, modules, expiry and host ID.
- Three example procedures, copied into an empty script folder at the first start: `add_values` and `count_blobs` with interface files, and `convert_length`, whose HDevelop documentation carries its types.
- Runs on Windows 11 and Ubuntu 24.04.
- Windows installer and a Debian package for Ubuntu 24.04. HALCON 22.11 is part of neither and is taken from its own installation. The Windows installer stops before installing anything unless the system environment variable `HALCONROOT` is set and `bin\x64-win64\halcon.dll` exists in that folder.
- JSON schema of the application file, installed next to it, so an editor checks module names, interface hashes and misspelled keys.

**Limits of this version**

- HALCON 22.11 only (any 22.11.x). The app checks the release of the loaded HALCON libraries at start and stops with HALCON of another release; the Windows installer checks only that HALCON is installed.
- Procedures as single files (`.hdvp`); procedure libraries (`.hdpl`) are not loaded as modules.
- Modules are added, changed and removed in the application file; every change needs a restart of the app.
- A module is called with the `run` handshake only; there is no single blocking call (`invoke`) and no image stream input yet. The `trigger` `stream` and the `stream` section of the schema are reserved for that.
- Images are copied into HALCON and back for every run, see [Copy time](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html#image-copy-time).
- Regions, contours and parameters that mix strings and numbers are not carried on the Data Layer.

# Troubleshooting – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html

This page describes problems of LumiScan Script Runner. Start with the [general checks](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#general-checks), then find your symptom below: each problem lists its symptoms, the possible causes, a diagnostic procedure and the resolution. The status codes are listed in [Status Codes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/status-codes.html).

## General checks {#general-checks}

1. **Check the app.** Read `hdvisionsystems/lumiscan-script-runner/v1/system/status-text`. Expected: `Initialized`.
2. **Check HALCON.** Read `v1/system/engine/license-valid` and `v1/system/engine/version`. Expected: `true` and the HALCON version.
3. **Check the module.** Read `v1/<module>/status/code` and `status/text`. Expected: `0` and `ready`.
4. **Check the last run.** Read `v1/<module>/run/output/status-code` and `status-text`. Expected: `0`.
5. **Read the log.** The Script Runner writes its log to its console window. At start it names the script folder, every procedure it loaded with its interface hash, every module with its group, and every module it did not build, with the reason.

The settings folder is listed under [Settings Folder](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html#location).

## Installation {#ts-installation}

### Problem: The installer says HALCON was not found {#ts-installer-halcon}

**Symptoms**

The installer stops before installing anything with the message *LumiScan Script Runner needs MVTec HALCON 22.11 (Steady) with a runtime licence, and HALCON was not found*. The message continues with one of two reasons: *the system environment variable HALCONROOT is not set*, or *no bin\\x64-win64\\halcon.dll in the HALCONROOT folder*.

**Possible causes**

- HALCON is not installed.
- HALCON was installed for the current user only. That sets `HALCONROOT` as a user variable, and the installer reads only the system variable.
- `HALCONROOT` names a folder without `bin\x64-win64\halcon.dll`, for example after HALCON was moved or partly uninstalled, or it is the 32-bit or another platform’s installation.

**Diagnostic procedure**

1. Open **Edit the system environment variables** in Windows, then **Environment Variables**. Look for `HALCONROOT` under **System variables** (not under the user variables).
2. Check that `bin\x64-win64\halcon.dll` exists in the folder it names, for example `C:\Program Files\MVTec\HALCON-22.11-Steady\bin\x64-win64\halcon.dll`.
3. If needed, read the installer’s log: it is written to the `%TEMP%` folder as `LumiScan_Script_Runner_<date and time>.log`, and the lines `File search` and `Condition` show what was looked for.

**Resolution**

- **If HALCON is missing, or installed for one user only:** install HALCON 22.11 for all users, sign out and in again, and run the Script Runner installer again.
- **If the folder is wrong:** repair the HALCON installation so that `HALCONROOT` names it and `halcon.dll` is there.

**If the problem persists**

Send the installer’s log and the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support.

## Start {#ts-start}

### Problem: The app stops right after it starts {#ts-app-does-not-start}

**Symptoms**

The console window shows an error and closes, or no node appears under `hdvisionsystems/lumiscan-script-runner`.

**Possible causes**

- The application file is not valid JSON, or a setting is refused: `apiVersion` is not `1`, `scriptFolder` is empty, `engine.threadNum` is not a whole number from 0 to 1024, a module entry is refused, or two modules have the same name. See [Application File](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html), section *Checks at start*.
- The app cannot reach LumiScan Keryx.
- HDevEngine cannot be set up, for example because HALCON is not installed or its library folder is not on `PATH` (Windows) or `LD_LIBRARY_PATH` (Ubuntu).
- HALCON of another release than 22.11 is loaded, see [Problem: The app stops with "HALCON of another release is loaded"](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#ts-halcon-release).

**Diagnostic procedure**

1. Start the app from a command prompt (Windows: `lumiscan-script-runner.exe` in its installation folder) or a terminal (Ubuntu: `lumiscan-script-runner`) to keep the log on screen.
2. Look for lines starting with `[ScriptRunner] Cannot start`, `HDevEngine cannot be set up` or an error about the Data Layer connection. A refused module entry is logged as `module <name>: …`.
3. Open `lumiscan-script-runner.json` in an editor that checks it against its schema, for example Visual Studio Code.

**Resolution**

- **If the application file is refused:** correct the setting the log names, see [Application File](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html). If in doubt, rename the file: the next start copies the shipped default.
- **If LumiScan Keryx is not reachable:** start LumiScan Keryx first, or give the broker with `--keryx-url`.
- **If HDevEngine cannot be set up:** install HALCON 22.11. On Windows, check `%HALCONROOT%\bin\x64-win64\halcon.dll`, and sign in again so that `PATH` is updated. On Ubuntu, check `$HALCONROOT/lib/x64-linux/libhalcon.so`, and that `LD_LIBRARY_PATH` names its folder in the terminal that starts the app.

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support.

### Problem: The app stops with "HALCON of another release is loaded" {#ts-halcon-release}

**Symptoms**

The app stops right after it starts. The log has a line starting with `[ScriptRunner] HDevEngine cannot be set up: HALCON of another release is loaded:`, followed by each HALCON library of the wrong release with its version and folder, for example `halcon.dll 24.11.1.0 (C:\Program Files\MVTec\HALCON-24.11-Steady\bin\x64-win64\halcon.dll)`. On Ubuntu the libraries are `libhalcon.so`, `libhalconcpp.so` and `libhdevenginecpp.so`.

**Possible causes**

- Only another HALCON release is installed, for example 24.11 instead of 22.11.
- HALCON 22.11 and another release are both installed, and the other release’s library folder comes first: `bin\x64-win64` on `PATH` (Windows), `lib/x64-linux` on `LD_LIBRARY_PATH` (Ubuntu).
- A HALCON library of another release was copied into the Script Runner’s installation folder.

**Diagnostic procedure**

1. Read the folders the log line names: they show which HALCON installation was used.
2. On Windows, run `where halcon.dll` in a command prompt: the first line is the library the Script Runner loads. On Ubuntu, run `echo $LD_LIBRARY_PATH` in the terminal that starts the app: the first HALCON folder in it is the one the Script Runner uses.
3. Check `HALCONROOT`: on Windows under the **System variables**, on Ubuntu with `echo $HALCONROOT`. It should name the HALCON 22.11 folder.

**Resolution**

- **If HALCON 22.11 is not installed:** install it, with a licence valid for 22.11 (on Windows for all users). It can stay installed next to the other release.
- **If another release comes first:** on Windows, move `%HALCONROOT%\bin\x64-win64` of HALCON 22.11 above the other release’s folder in the system variable `PATH`, or remove the other folder from `PATH`. On Ubuntu, put `$HALCONROOT/lib/x64-linux` of HALCON 22.11 before the other release’s folder in `LD_LIBRARY_PATH`, for example in `~/.profile`. Sign out and in again, then start the app.
- **If a HALCON library is in the installation folder:** delete it there; the Script Runner never ships HALCON’s libraries.
- **If you have to use the newer HALCON release:** you need a version of the Script Runner built for it. Contact HD Vision Systems.

**If the problem persists**

Send the log line and the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support.

### Problem: Every module reports `-4` {#ts-licence}

**Symptoms**

`v1/<module>/status/code` is `-4` for every module. `v1/system/engine/license-valid` is `false`; `v1/system/status-text` says `the HALCON licence is not valid: …`.

**Possible causes**

- No valid HALCON runtime licence on the PC: the HALCON dongle is not plugged in, or the licence file is missing or expired.
- The HALCON dongle was pulled while the app ran. HALCON notices it after 2 to 4 minutes; from then on runs fail with `-4`.

**Diagnostic procedure**

1. Read `v1/system/licenses/current/error-text`. It holds HALCON’s own licence message.
2. Read `v1/system/licenses/current/file` and `host-id`: the licence file HALCON chose and the PC or dongle it is bound to. `v1/system/licenses/files` lists every licence file HALCON found.
3. Check that the HALCON dongle is plugged in, or that the licence file is in HALCON’s licence folder.

**Resolution**

- Plug in the HALCON dongle or install the licence file, then restart the app. The Script Runner checks HALCON’s licence at start; after a licence error it reports `-4` until it is restarted.

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support, together with `v1/system/status-text`. For licences, contact [licenses@hdvisionsystems.com](mailto:licenses@hdvisionsystems.com).

### Problem: One module reports `-4`, the others run {#ts-halcon-module}

**Symptoms**

`v1/<module>/status/code` is `-4` for one module; `status/text` names a HALCON module, for example `matching`.

**Possible causes**

- The procedure needs a HALCON module that the HALCON licence does not cover. The modules it needs come from `requiredModules` of its interface file.

**Diagnostic procedure**

1. Read `v1/system/engine/licensed-modules`. Expected: it contains the module named in `status/text`.

**Resolution**

- Extend the HALCON licence, or change the procedure so that it does without the module. If `requiredModules` in the interface file lists a module the procedure does not really need, correct the list and restart the app.

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support, together with `v1/system/engine/licensed-modules` and the interface file.

## Modules {#ts-modules}

### Problem: A module reports `-10002` (script not loaded) {#ts-script-not-loaded}

**Symptoms**

`v1/<module>/status/code` is `-10002`; the module has no input or output nodes.

**Possible causes**

- No procedure file of that name in the script folder (`procedure` names the file without `.hdvp`).
- HDevEngine cannot load the procedure, for example because it was saved with a newer HALCON version.
- A parameter has no type: neither the documentation nor an interface file gives one.
- The interface file does not fit the procedure: a parameter is missing on one side, renamed, in another group or of another dimension.
- A parameter cannot be on a node: a handle input without a store binding, a region or contour input, a vector, or strings mixed with numbers.
- A binding names a parameter the procedure does not have, binds it in the wrong direction, or gives an image, a handle or a value that does not fit a fixed value.
- Two parameters give the same node name, or an output gives a reserved name (`status-code`, `status-text`, `package-identifier`).
- The module is a `start` module, and its run failed.

**Diagnostic procedure**

1. Read `v1/<module>/status/text`. It names the parameter and the reason.
2. Read `v1/system/scripts`. Expected: the procedure is listed without `error`.
3. Read the log of the start: it lists every warning and refusal per parameter.

**Resolution**

- **If the procedure is missing:** copy it into the script folder, or correct `procedure` in the application file.
- **If a parameter has no type:** document it in HDevelop or add it to the interface file, see [Prepare a HALCON Procedure](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/prepare-a-procedure.html).
- **If the interface file does not fit:** correct it, see [Interface File](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html).
- **If a parameter cannot be on a node:** bind it to the store or a fixed value, or change the procedure, see [Type Mapping](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html).
- **If a start run failed:** the text gives the HALCON error; correct the procedure or the file it reads.

Then restart the app. Expected: `status/code` is `-10005` (for a new module) or `0`.

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support, together with `status/text`, the procedure and its interface file.

### Problem: A module reports `-10005` (interface changed) {#ts-interface-changed}

**Symptoms**

`v1/<module>/status/code` is `-10005`; the module has no input or output nodes and accepts no request. `status/text` says that the module has no accepted interface hash, or that the procedure’s interface changed (`accepted sha256:…, now sha256:…`).

**Possible causes**

- The module is new and has no `acceptedInterfaceHash` yet.
- The procedure or its interface file was replaced, and a parameter was added, removed, renamed, moved to another group or retyped.

**Diagnostic procedure**

1. Read `v1/<module>/status/text`. It gives the accepted and the current hash.
2. Compare `v1/<module>/script/interface` with the interface your PLC program expects.

**Resolution**

- **If the change is wanted:** adapt your PLC program, copy `v1/<module>/script/interface-hash` into `acceptedInterfaceHash` and restart the app. See [Add a Module](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/add-a-module.html) and [Replace a Script](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/replace-a-script.html). For a procedure whose types come from an interface file, `interface-save` sets the hash for you, see [Building one over the Data Layer](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html#over-the-data-layer).
- **If the change is not wanted:** put the previous procedure back into the script folder and restart the app.

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support, together with `status/text` and `script/interface`.

### Problem: Every module reports `-5` (restart required) {#ts-restart-required}

**Symptoms**

`v1/system/restart-required` is `true`; every module reports `-5`, and no request is accepted.

**Possible causes**

- `v1/system/settings` was written. The new settings are saved, and take effect at the next start.
- An interface file was saved with `interface-save`. The app loads it at the next start.

**Resolution**

- Restart the app.

## Runs {#ts-runs}

### Problem: The module does not react to `request` {#ts-not-acknowledged}

**Symptoms**

`run/request` is `true`, but `run/running` stays `false`.

**Possible causes**

- `run/ready` was `false` when `request` rose: the module is not built, a restart is pending, a run is still going on, or `request` was not lowered after the previous run.
- `request` was already `true` and was not lowered after the previous run: the run starts on the rising edge only.

**Diagnostic procedure**

1. Read `run/ready` and `status/code` of the module.
2. Check that your program lowers `request` after every run and waits for `ready` before it raises it again.

**Resolution**

- **If `status/code` is not `0`:** follow the entry for that code.
- **If `request` was not lowered:** lower it, wait for `ready`, raise it again. See [The run Handshake](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/run-handshake.html).

### Problem: A run ends with `-3` (invalid input) {#ts-invalid-input}

**Symptoms**

`has-error` is `true`; `run/output/status-code` is `-3`. The procedure did not run.

**Possible causes**

- A number is outside the parameter’s min and max.
- An input image has an unknown pixel type, width or height 0, a `data` size that does not match width × height × bytes per pixel, or a pixel type or channel count the parameter does not accept.
- A handle taken from the group’s store is no longer valid, or of another kind than the interface declares.

**Diagnostic procedure**

1. Read `run/output/status-text`. It names the input and the reason.
2. For a number, read the node’s description: it ends with min and max.
3. For an image, compare `pixel-type`, `width`, `height` and the size of `data`.

**Resolution**

- Correct the input and run again. For a handle, run the module that writes the store key again (or restart the app to rerun the `start` modules).

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support, together with `status-text` and the input values.

### Problem: A run ends with `-10001` (script error) {#ts-script-error}

**Symptoms**

`has-error` is `true`; `run/output/status-code` is `-10001`.

**Possible causes**

- The procedure raised an error with `throw`.
- A HALCON operator failed inside the procedure, for example because a file is missing or an input made no sense to it.
- The procedure opened or asked for a window (`dev_open_window`, `dev_get_window`): the Script Runner has no display.

**Diagnostic procedure**

1. Read `run/output/status-text`. It names the procedure (or sub-procedure), the program line, the HALCON error number and the message.
2. Run the procedure in HDevelop with the same inputs.

**Resolution**

- Correct the input or the procedure. Remove window operators from the procedure. A file the procedure reads must be in the script folder.

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support, together with `status-text`, the input values and the procedure.

### Problem: A run ends with `-10003` (output type mismatch) {#ts-output-mismatch}

**Symptoms**

`has-error` is `true`; `run/output/status-code` is `-10003`. No output was written.

**Possible causes**

- The procedure returned an output of another type than declared, for example a string for an integer, several values for a single-value parameter, or an image of a pixel type that is not carried.
- The procedure did not set an output on the path it took.

**Diagnostic procedure**

1. Read `run/output/status-text`. It names the parameter, the declared and the returned type.

**Resolution**

- Correct the procedure so that every output is set on every path and matches its declared type, or correct the declared type. For images, convert to `byte` or `uint2` before `return ()`.

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support, together with `status-text` and the procedure.

### Problem: A run ends with `-10004` (store value missing) {#ts-store-value-missing}

**Symptoms**

`has-error` is `true`; `run/output/status-code` is `-10004`.

**Possible causes**

- The module that writes the store key has not run successfully yet: the `start` module failed, or the handshake module that writes the key was not called.
- The writing module is in another group: each group has its own store.
- The key names differ between the writing and the reading binding.

**Diagnostic procedure**

1. Read `run/output/status-text`. It names the key and the modules that write it.
2. Read `v1/system/groups`. Expected: the key is listed in the group’s store.
3. Compare `setting/group` and `setting/bindings` of both modules.

**Resolution**

- Run the writing module first, or correct the `start` module (`status/code` `-10002` shows why it failed).
- Put both modules into the same group, and use the same key, see [Share a Model Between Scripts](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/how-tos/share-a-model-between-scripts.html).

**If the problem persists**

Send the information listed under [Information for support](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/troubleshooting.html#support-information) to support, together with `status-text`, `v1/system/groups` and the application file.

### Problem: Runs are slow or wait long {#ts-slow}

**Symptoms**

`running` stays `true` much longer than the procedure needs in HDevelop.

**Possible causes**

- Another module of the same group runs: requests in one group wait for each other.
- HALCON may use one thread per operator only (`engine.threadNum` `1`, the default).
- Large images: every image input and output is copied into and out of HALCON, for a 5-megapixel `rgb8` frame about 13 to 27 ms per direction, see [Copy time](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/type-mapping.html#image-copy-time).

**Diagnostic procedure**

1. Read `setting/group` of the modules. Expected: only modules that share store keys are in one group.
2. Compare the run time with the size and pixel type of the images the module takes and returns.

**Resolution**

- Put modules without shared state into groups of their own: they run in parallel.
- If the PC has cores to spare, raise `engine.threadNum`, or try `engine.jitCompiled`. See [engine](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html#engine).
- Pass only the images the procedure needs, prefer `mono8` where it is enough, and leave an image output off the Data Layer (`{"to": "none"}`) when no client reads it.

## Information for support {#support-information}

If a problem persists, send this information to support:

- **Software version:** the version of LumiScan Script Runner, shown in the log at start (`Version: …`), the HALCON version (`v1/system/engine/version`) and the licence in use (`v1/system/licenses/current/file`, `type`, `host-id`).
- **Platform:** Windows 11 or Ubuntu 24.04, and the exact version of the operating system.
- **Log:** the console output of the app from its start to the error.
- **Time:** the date and time of the error.
- **Communication status:** `status/code` and `status/text` of the module, `run/output/status-code` and `run/output/status-text` of the last run, and `v1/system/status-text`.
- **Files:** `lumiscan-script-runner.json` and the procedure with its interface file, if you may share them. A protected procedure is fine.

Contact HD Vision Systems customer success at [customer.success@hdvisionsystems.com](mailto:customer.success@hdvisionsystems.com) or +49 6221 6721905; for licences, [licenses@hdvisionsystems.com](mailto:licenses@hdvisionsystems.com).

# Glossary – LumiScan Script Runner

URL: https://docs.hdvisionsystems.com/en/lumiscan-script-runner/glossary.html

- **Accepted interface hash:** The interface hash a module’s nodes, and the PLC programs that use them, were built for. Stored as `acceptedInterfaceHash` in the application file. See [Interfaces and Hashes](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interfaces-and-hashes.html).
- **Application file:** `lumiscan-script-runner.json`, the settings of the Script Runner: script folder, engine settings and modules. See [Application File](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/application-file.html).
- **Binding:** Where an input comes from (`node`, `store`, `value`) or where an output goes (`node`, `store`, `both`, `none`). See [Bindings](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html#bindings).
- **Control parameter:** A HALCON parameter that holds numbers, strings or handles, as opposed to an iconic parameter.
- **Data Layer:** The communication layer the LumiScan apps share. On a PC it is LumiScan Keryx; on ctrlX OS the ctrlX Data Layer.
- **Group:** Modules that share one worker thread and one store. Modules of a group run one at a time.
- **Handle:** A reference to a HALCON object held in memory, such as a shape model or a dictionary. It never crosses the Data Layer.
- **HDevEngine:** MVTec’s library that runs HDevelop procedures inside an application. The Script Runner is built on it.
- **Iconic parameter:** A HALCON parameter that holds images, regions or contours (XLD).
- **Interface:** The declared parameters of a procedure in its four groups: iconic inputs, iconic outputs, control inputs, control outputs, each with name, dimension and type.
- **Interface file:** `<procedure>.interface.json`, the types of a procedure’s parameters written outside the procedure. See [Interface File](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/interface-file.html).
- **Interface hash:** A fingerprint (SHA-256) of a procedure’s interface. It changes when a parameter is added, removed, renamed, moved to another group or retyped, not when parameters are reordered.
- **LumiScan Key:** The USB licence key (WIBU CodeMeter) of the LumiScan products.
- **Module:** One procedure with its nodes and settings under `v1/<module>/`.
- **Procedure:** An HDevelop unit with a declared interface and a body, stored as `<name>.hdvp`. A protected procedure is locked with a password: anyone can run it, only the password holder can view or edit it.
- **Procedure hash:** The SHA-256 of a procedure file’s bytes. It changes with every change, also to the body.
- **Script folder:** The folder from which the Script Runner loads procedures, interface files and the files procedures read. See [The script folder](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/settings-folder.html#script-folder).
- **Start module:** A module with `trigger` `start`: it runs once when its group starts, for example to read a model into the store.
- **Store:** A group’s values held in memory by key: handles, tuples, images. See [Modules, Groups and the Store](https://docs.hdvisionsystems.com/en/lumiscan-script-runner/modules-groups-and-store.html).
