Interfaces and Hashes
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, 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 |
|
What the procedure and its interface file declare now. |
Accepted interface hash |
|
The interface the module’s nodes, and your PLC program, were built for. |
Interface file hash |
|
Shows that an interface file was edited by hand: a stored hash that does not match the content gives a warning. |
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 itsstatus/,script/and fixedrunnodes, 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). A copied procedure file can therefore never move a PLC program’s nodes on its own. See Replace a Script.
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.
|