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 |
|---|---|---|
|
|
Adds two integers. It throws an error when the sum is negative. |
|
|
Reads the image file |
|
|
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
-
Read
add/status/code,blobs/status/codeandconvert/status/code. Expected:0(status/textsaysready). -
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 |
|---|---|---|
|
INT64 |
input parameter |
|
INT64 |
input parameter |
|
INT64 |
output parameter |
|
STRING |
output parameter |
|
every module |
|
|
BOOL8 |
every module |
add/script/interface shows the interface as JSON, add/script/interface-hash its hash.
3. Run add
-
Write
40toadd/run/input/aand2toadd/run/input/b. -
Write
truetoadd/run/request. -
Wait until
add/run/doneoradd/run/has-erroristrue. Expected:doneistrue. -
Read the outputs. Expected:
add/run/output/sumis42,add/run/output/textissum of 40 and 2,add/run/output/status-codeis0, andadd/run/output/package-identifierhas grown by one. -
Write
falsetoadd/run/request. Expected:donegoes back tofalse,readytotrue.
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
-
Write
-50toadd/run/input/a, keepbat2. -
Raise
add/run/requestand wait. Expected:has-erroristrue,output/status-codeis-10001(script error), andoutput/status-textnames the procedure, the program line, the HALCON error number and the text the script threw:the sum must not be negative. -
The outputs keep their values of the last successful run: a failed run writes no output.
-
Lower
requestagain.
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.
-
Raise
blobs/run/requestand wait fordone. -
Read the outputs. Expected:
blobs/run/output/countis4,blobs/run/output/areasholds four areas,blobs/run/output/mean-grayis a real value, andblobs/run/output/binary/holds the binary image (data,width,height,pixel-typemono8). -
Lower
request.
6. Run convert, a procedure without an interface file
-
Read
convert/script/interface-source. Expected:documentation: the types come from the procedure’s HDevelop documentation, not from a file. -
Read the inputs. They start at the documented defaults:
convert/run/input/lengthis25.4(FLOAT64),from-unitismmandto-unitiscm(STRING). -
Raise
convert/run/requestand wait fordone. Expected:convert/run/output/convertedis2.54andconvert/run/output/textis25.4 mm = 2.54 cm. -
Lower
request, writeinchtoconvert/run/input/to-unitand run again. Expected:has-erroristrue,output/status-codeis-10001, andstatus-textends with the text the procedure threw:unknown unit: use mm, cm or m. -
Write
cmagain and lowerrequest.
7. Provoke an input error
The interface file of count_blobs gives MinGray a minimum of 0 and a maximum of 255.
-
Write
300toblobs/run/input/min-gray. -
Raise
requestand wait. Expected:has-erroristrue,output/status-codeis-3(invalid input), andstatus-textnames the input and its range. The procedure did not run. -
Write
128again and lowerrequest.
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.hdvpandcount_blobs.hdvpwith their interface files, andconvert_length.hdvp, whose documentation carries the types. They are a good starting point.