Interface File

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

{
  "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.

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

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 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

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): 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, 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. 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, 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

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. 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":

    {
      "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.

      {
        "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

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.

Write the interface file from the open procedure before you protect it with a password, and ship both files.