Run Your First Script

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.

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

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.

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.

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.

  • Make it a module: Add a Module.

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