Process Execution
Process Execution saves a sequence of operations and runs them in order. A process can send commands, wait for the device to respond, and choose the next step based on the result. The result of each step is recorded in the execution log.
Process settings are also saved by group, and each group is one JSON configuration file. A group has two levels:
- Step group: Groups related steps together, for example "Init" or "Read Parameters".
- Step item: One step. It holds the data to send, a delay, and an optional comparison.
During execution, the program runs the step items in the order of their step groups.
Open Process Execution
Open the Process Execution panel in the device window to see the execute view. The Edit button (…) at the top of the panel opens the process editor.
Manage groups
The Select group drop-down at the top left of the editor lists all groups. You can:
- Refresh: Reload the group list.
- New group: Create a group named "Process 1", "Process 2", and so on.
- Delete group: Delete the current group's configuration file. A confirmation dialog appears first.
- Rename: Edit the name in the drop-down list and press Enter. The file is renamed to match.
If no group exists, the program creates a group named Default automatically.
Edit steps
The tree on the left of the editor lists the groups and steps. The panel on the right shows the settings for the selected node. When a step group is selected, you can change its Step group name and click Save to apply it.
Right-click a node in the tree to use these menu items:
| Menu item | Available on | Function |
|---|---|---|
| Add Step Group | Root node | Add a new step group at the end |
| Add Step Item | Step group | Add a new step item at the end of that step group |
| Copy | Step group, step item | Put the node on the clipboard |
| Cut | Step group, step item | Same as Copy, but the original node is deleted only after a successful paste. A cut can be pasted only once |
| Paste | Step group (clipboard holds a step item), root node (clipboard holds a step group) | Add the clipboard content at the end |
| Insert | Step group (clipboard holds a step group), step item (clipboard holds a step item) | Insert the clipboard content before the selected node |
| Delete | Step group, step item | Delete the node. A confirmation dialog appears first |
Step item settings
When a step item is selected, these settings appear on the right. Click Save to apply your changes.
| Setting | Description |
|---|---|
| Step name | The name shown in the execute list |
| Send data | The content sent when the step runs. You can use {variable} placeholders. The button on the right inserts a variable |
| Pop up input dialog | When checked, an input dialog appears when the step runs. The Send data value is the default text. When checked, the Send data box is disabled |
| Delay (ms) | How long to wait after sending, in milliseconds |
| Byte order | The byte order used when a numeric variable is sent in HEX mode (big-endian or little-endian) |
| Compare, Comparison formula | When checked, the formula is evaluated after the delay. Its result decides whether the step passed or failed. See below |
| On pass jump to | The next step after success. Default: "Next step" |
| On fail jump to | The next step after failure. Default: "Next step" |
A jump target can be "Next step", "End", or any step in the process.
A new step item must be saved once
A new step item stays incomplete until you save it for the first time. Incomplete steps are skipped during execution.
Comparison formula
The formula decides whether a step passes. Use {variable} to reference a variable from Global Variables. At run time, the placeholder is replaced with the variable's current value.
The formula is a Lua 5.4 expression, evaluated once each time the step runs. Before evaluation, the program converts some operators and provides the functions of the Lua standard library. For example, {voltage} >= 3.0 && {voltage} <= 3.6 passes when the variable voltage is between 3.0 and 3.6.
Operator conversion
The following forms are converted to Lua syntax before evaluation:
| You write | Converted to | Description |
|---|---|---|
!= | ~= | Not equal |
&& | and | Logical AND |
|| | or | Logical OR |
! | not | Logical NOT |
+ between strings | .. | A + next to a string literal or string variable becomes concatenation, for example "v" + {name} |
Lua forms such as ==, >, >=, <, <=, ~=, and, or, not, .., and # work directly. A + between numbers is still addition.
Symbols inside strings are also replaced
The conversion runs on the whole formula text, so !, &&, and || inside string literals are replaced too. For example, "Hi!" becomes "Hi not ". Avoid these symbols inside strings.
Variable substitution
Before evaluation, each {variable} is replaced with the variable's current value:
- A numeric variable is replaced with a number. If its value is not a valid number, it is replaced with
0. - A string variable is replaced with a double-quoted string. Quotes and backslashes are escaped.
- A Boolean variable is replaced with
trueorfalse. An empty value,0, orfalsegivesfalse. Any other value givestrue.
Variable names may contain only letters, digits, and underscores. A brace pair that contains a single name, such as {1}, is also treated as a variable placeholder, and an error occurs if no such variable exists.
Available functions
The engine loads all standard libraries of Lua 5.4.2, including math, string, table, utf8, os, and io. Common examples:
| Function | Example | Description |
|---|---|---|
math.abs(x) | math.abs({offset}) <= 0.5 | Absolute value |
math.floor(x), math.ceil(x) | math.floor({value}) == 10 | Round down, round up |
math.max(...), math.min(...) | math.max({a}, {b}) < 100 | Maximum, minimum |
math.sqrt(x) | math.sqrt({area}) > 2 | Square root |
string.len(s) or #s | #{text} == 4 | String length |
string.sub(s, i, j) | string.sub({code}, 1, 2) == "AB" | Substring. Positions start at 1 |
string.find(s, p) | string.find({msg}, "OK") ~= nil | Finds a substring. Returns the position, or nil if not found |
string.format(fmt, ...) | string.format("%.1f", {v}) == "3.3" | Formats a value as a string |
tonumber(s) | tonumber({text}) > 10 | Converts a string to a number, or returns nil if conversion fails |
Evaluation rules
- Each evaluation creates a new Lua environment. Global variables and functions defined earlier are not kept.
- The formula must be a single expression. The program wraps it as
_RESULT_ = <formula>; return _RESULT_, solocal, assignment statements, and multiple statements are not allowed. - Output from
printdoes not appear in the execution log. Do not use it for debugging. - The program also registers Qt bridge functions such as
invokeMethodandgetProperty. The formula has no Qt objects it can access, so these functions have no practical use here.
Pass or fail
- The step fails if the result is the number
0(including0.0), the Booleanfalse,nil, or the string"0"or"false". - All other results pass, including
true, non-zero numbers, and empty strings. - If the formula raises a runtime error, for example by comparing
nil, the step fails and the execution log shows the error.
Results from and and or
and and or return one of their operands, which is not always a Boolean. For example, with {a} > 1 and 5, the result is 5 when {a} is greater than 1, and the step passes. Otherwise the result is false, and the step fails.
Checks on save
When you save a step, the program runs the converted formula once to check its syntax and variables. Functions with side effects, such as os.execute or io.open, therefore run at save time. A formula with a syntax error, or one that references a missing variable, cannot be saved.
Use only trusted formulas
A formula can call the os and io libraries, for example to read or write files or run system commands. Use only process files that you wrote or have reviewed.
Run a process
The execute view contains these elements:
- Process drop-down: Selects the process to run.
- Edit (…) and Refresh (…) buttons: Open the editor, or reload the process list.
- Step list: Each row is one step, shown in three columns:
- Breakpoint column: Click to add or remove a breakpoint. A breakpoint shows as a red ●.
- Execution column: The step that is running shows →.
- Name column: Shows "number.name". A step with a jump shows ↪ after its name. Hover over it to see the jump targets. Unchecked or incomplete steps appear gray.
- Execution log: Records the start and result of each step, and the overall result of the process. The log is cleared each time you start from the first step.
- Control buttons: Start, Pause, Stop, Step.
| Button | Function |
|---|---|
| Start | Runs from the first step. After a pause, the button changes to "Continue" and resumes from where the process paused |
| Pause | Pauses after the current step finishes, including its delay |
| Stop | Ends the process and interrupts any delay in progress. Clicking Start again runs from the first step |
| Step | Available only when paused. Advances the process one step at a time |
Breakpoints
Click the breakpoint column to set a breakpoint. When execution reaches that step, it pauses before the step runs. Click Continue to run the step. Breakpoints are cleared when you switch to another process file.
Execution rules
- Step items run in the order of their step groups.
- An unchecked or incomplete step is skipped and recorded as "skipped". Execution then moves to the next step. A skipped step does not trigger a jump.
- To run a step, the program does the following in order:
- If Pop up input dialog is checked, it shows an input dialog. The entered text is sent as the data. If the input is empty or you cancel, the process ends.
- It sends the data. Variables are replaced with their current values, and the same rules as the send area apply (HEX sending and checksum). If the data is empty, nothing is sent, and only the delay and comparison run.
- It waits for the delay.
- If Compare is checked, it evaluates the formula.
- It marks the step as passed or failed.
- A passed step jumps to its On pass jump to target. A failed step jumps to its On fail jump to target. A jump to "End" ends the process immediately.
When the process ends, the log shows the number of passed, failed, and skipped steps.
Notes
Editing is locked while running
While a process runs, the execute view cannot switch process files, and the Edit button is disabled. If a device is running a process file, the editor locks its steps and blocks deletion and renaming.
- Changes made in the editor are written to the file only after you click Save. Unsaved changes do not affect execution.
- When you save while a device is running the process, the program asks whether to stop it first. The file is saved and refreshed only after you confirm.
