You are here: Start » Program Examples » HMI Start Stop
HMI Start Stop
Aim:
The task is to create a simple application where the user activates an inspection mode through the HMI Panel.
If the inspection mode is not activated, the input image is displayed.
In inspection mode, a threshold operation is performed.
Hints:
Use a Variant macrofilter to have multiple alternative execution paths, in this case, you need to have two variants. If you defined a forking port type as Macrofilter input, the inspection variant would execute once. This is because an output of the Start ImpulseButton will be false in the next iteration of the program. Therefore, the better way is to define the forking port type as Macrofilter register. Then you will be able to remember the previous state.
Solution (FIS):
-
Add the GrabImage_FromFiles filter to load a single image from a file. Place it in the ACQUIRE section.
-
Create the Variant macrofilter Inspection and create the inImage input of type Image. In Creating a Variant macrofilter window:
- Define the forking port of type Macrofilter register.
- Set its Name to regState.
- Set type of data to the String. It is equivalent of 'switch-case' statement.
-
Set the Initial value of the regState register to Stopped. This can be accomplished in the editor, which can be opened by right-clicking on a prevState.
-
In Program Editor: create a new variant of the Inspection macrofilter and name it Inspecting.
-
Change the name of the default variant to Stopped.
-
In the Inspecting variant: add the ThresholdImage filter and connect its input with the macrofilter's input.
-
In the Inspecting variant:
- Add the Formula and create the following inputs: the inStopPressed of type Bool and the inPrevState of type String. This formula is responsible for specifying the next state, depending on whether Stop button has been clicked.
- Add the output outNextState and type the formula: outNextState = inStopPressed ? "Stopped" : inPrevState.
- Connect the inPrevState input with the prevState register.
-
Open the HMI Designer. It is available in a View tab, or in a Toolbar.
-
To allow the user to set the lower limit of the threshold range, add to the HMI the TrackBar control available in the Controls category of HMI Controls.
- Connect its outValue with the inMinValue.
-
Add to the HMI the ImpulseButton control and set its Text parameter to Stop.
- Connect the outValue with the inStopPressed input. From now, the program executes Inspecting variant, until the Stop button is clicked.
-
Connect the outNextState with register nextState.
-
Create the macrofilter's outState output and also connect it with the outNextState.
-
In the Stopped variant: add the Formula and create the following inputs: the inStartPressed of type Bool and the inPrevState of type String. Connect its ports, except the inStartPressed, as in the Inspecting variant.
-
Add to the HMI ImpulseButton control and set its Text parameter to Start.
- Connect the outValue with the inStartPressed input. From now, the program executes the Stopped variant until Start button is clicked.
-
Connect the inImage input of the macrofilter with its outImage output, since no operations on the image are performed in this variant.
-
The program is generally finished. However, it is good practice to disable the controls that should not be used in each state. To accomplish this, add another Formula in the Main Task macrofilter.
-
Create the inState input and connect it with the output of the Inspection macrofilter.
-
Create the outStartEnabled output of type Bool. Type the formula: inState <> "Inspecting". The outStartEnabled is True if the variant is Stopped.
- Connect this output with the Start button's input inEnabled. From now, this button will be disabled in Inspecting state.
-
Create the outStopEnabled output of type Bool. Type the formula: inState <> "Stopped". The outStopEnabled is True if the state is Inspecting.
- Connect this output with the Stop button's input inEnabled. From now, this button will be disabled in Stopped state.
-
Create the outControlsEnabled output of type Bool. Type the formula: inState == "Inspecting". The outControlsEnabled is True if the state is Inspecting.
- Connect this output with the TrackBar's input inEnabled. From now, this TrackBar will be enabled in Inspecting state.
-
Add the Delay filter and set the inTime to 500. This filter suspends the program workflow for 500 milliseconds.
Macrofilter Main
Macrofilter Inspection(Inspecting)
Macrofilter Inspection(Stopped)
Used Filters
Icon | Name | Description |
---|---|---|
![]() |
Delay | Suspends the program workflow for inTime milliseconds. |
![]() |
GrabImage_FromFiles | Can be used as EnumerateImages, but its state is global in a program - does not reset when some task is finished. |
![]() |
ThresholdImage | Image binarization when the illumination is constant and uniform. |
Further Readings
- Image Processing - A comprehensive introduction to Image Processing.