Operators and proceduresπ
About operatorsπ
When using one of the HALCON operators, HALCON Script behaves very similar to HDevelop, with this general signature of an operator:
More Info
For more information about control and iconic data, see Basic types of parameters.
About proceduresπ
Declaring and calling proceduresπ
In HALCON Script, you write the code of a procedure just as you write the βmainβ program part, as procedures are just a part of the program file. Procedures are distinguished by certain keywords.
Adhere to the following:
- A procedure must start with one
procstatement and end with oneendprocstatement. - A procedure by default has private scope, that is, it is only accessible within the current file.
To create a public procedure (that is, make it accessible from other files), declare it as such by adding the
publicstatement before the firstprocstatement. - You can either use a dedicated
mainprocedure or put all lines of code that are not part of a procedure (βstandalone statementsβ) at the end of the program. This means: In the HSCRIPT file, all procedures (that is, allproc ... endprocblocks) must come before any standalone statements. - There can only be one procedure called
main. If this procedure exists (that is, if there is apublic proc main (...) endprocblock), it serves as the entry point of the program. In this case, themainblock does not need to be at the end, but there must not be any further standalone statements. - Only a public
mainprocedure can be used for running a program. This means that themainprocedure must start with the corresponding access specifier:public proc main. -
Parameters are defined using the following keywords:
-
Iconic input:
objectkeyword -
Control input:
tuplekeyword -
Iconic output:
out objectkeyword -
Control output:
out tuplekeyword
-
-
Parameters must be separated by , (comma).
proc proc_name (object InputImage, tuple InputParam, out object OutputImage, out tuple OutputParam)
(...)
endproc
The above syntax creates a procedure with private scope by default.
To specify the scope of a procedure, use the private or public keyword:
- The
privatekeyword is optional.
When declaring a procedure, the order of the parameter types (iconic in, control in, iconic out, control out) is not fixed, as can be seen in the following example.
Example: Procedure declarations with different parameter order
The following two declarations both are valid:
proc initialize_visualization_1 (tuple Width,
tuple Height,
out tuple WindowHandle,
out tuple WindowHandleText)
<code of procedure>
endproc
Procedure resolutionπ
When your HSCRIPT file contains one or more correct import statements, all procedures from the imported files become available within your file. That means, you can call the external procedures from anywhere within your own code.
Importing procedures is not transitive.
That means, if your own file imports from other_file.hscript, and other_file.hscript then imports from yet_another_file.hscript in turn, you will nonetheless only be able to access the procedures from other_file.hscript β but not from yet_another_file.hscript.
Keep the following in mind:
- If your own file locally contains a procedure with the corresponding name, this procedure will be called but none of the external ones.
- If there are only external procedures available, HDevelopEVO will arbitrarily choose one of them. There is no way to controll which one at the moment.
- HDevelopEVO will report a warning that the regarding call is ambiguous and it will list the file from which the procedure will be called as well as the file containing the procedure that is hidden.
Preview restriction
Currently, there is no solution to select the procedure to call if there is more than one possible candidate.
Procedure and file documentationπ
Any procedure and file documentation is purely descriptive and provides a structured documentation block for files and procedures in your code. It does not affect the script itself. An invalid procedure or file documentation will generate warnings only, not errors.
Procedure and file documentation can appear in two locations:
File documentationπ
- Positioned at the beginning of a source file, is it placed before a procedure block it then describes only this procedure.
- May appear before or after imports.
- Must appear before any procedures or executable code.
A file documentation block may contain only:
-
@shortβ short description -
@descriptionβ detailed description
Any other tags will generate a warning.
Procedure documentationπ
- Positioned at the start of a procedure block.
- Appears after the procedure interface.
- Appears before the actual code.
- Describes the specific procedure.
General procedure tags describe the procedure as a whole, can appear in any order and @short may be omitted if it appears first.
The parameter block marker @parameters is optional and used only as a visual marker, for example for code folding. It has no functional effect.
- Parameter rules
- Each parameter can appear only once.
Duplicate entries are ignored or may generate warnings.
All tags for a parameter must be grouped in a sub-block.
The order of parameters is arbitrary, and should generally match the procedure interface.
- Parameter definition
-
Each parameter block begins with
followed by a description and other tags. If the description follows immediately,
@descriptionmay be omitted.
Example: Procedure and parameter tags
Syntax and structureπ
Procedure and file documentation is enclosed by three single quotes '''.
The content consists of a list of properties, referred to as tags.
- General rules:
- Each tag may appear only once per block.
Additional occurrences are ignored and produce warnings.
A tag consists of a tag name, followed by a value or list of values. - Tag names:
- Always start with
@for example,@shortor@description. - Some tag names can be omitted in specific cases:
@shortmay be omitted if it is the first entry.@descriptionmay be omitted in parameter descriptions.
- Tag values:
- Free Text
- Start the free text immediately after the tag name.
End at the next tag, or the end of the block.
Leading and trailing whitespace is being trimmed.
To include the special character β@β in text, add two backslashes:\\@. - Tuple values
- Tuple values represent as single tokens with no whitespace or line breaks.
They must be numeric literals, numeric constants likeH_INT_MAX, or string literals. - Individual elements of value lists are separated by , (comma). Optionally, a value list may be enclosed in square brackets
[].
Important
false β interpreted as a boolean (numeric value 0)
'false' β interpreted as a string
| Tag | Free text | Definition |
|---|---|---|
@short |
yes | Short description |
@description |
yes | Description |
@warning |
yes | |
@example |
yes | |
@param |
yes | |
@keywords |
yes |
Tag |
Free text | Definition |
|---|---|---|
@sem_type |
yes | Specifies the class of data passed as parameter |
@default_type |
yes | Specifies, which tuple type to use in general; control parameters only |
@type_list |
yes | Accepted pixel type for images, tuple type for control parameters |
@multivalue |
yes | Number of values passed in a parameter; true, false, optional |
@mixed_type |
yes | Variety of tuple types; true, false, optional |
@multichannel |
yes | Number of channels in an image; true, false, optional |
@default_value |
no | (one single) default value for autocompletion |
@suggested_values |
no | List of suggested values for autocompletion |
@value_list |
no | Complete list of allowed values for autocompletion |
@min_value |
no | Maximum value of a control parameter |
@max_value |
no | Maximum value of a control parameter |
@file_ext |
yes | List of file extensions |
@file_ext_descr |
yes | List of descriptions |