You are here: Start » Program Examples » HMI Start Stop

HMI Start Stop

Aim

The task is to create a simple application where user activates an inspection mode through the HMI Panel.

If inspection mode is not activated, input image is displayed.

In the inspection mode 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 in the next iteration of the program an output of the Start ImpulseButton will be false. Therefore the better way is to define forking port type as Macrofilter register, then you will be able to remember previous state.

Solution (AVS)

  1. Add the GrabImage_FromFiles filter to load a single image from a file. Place it in the ACQUIRE section

  2. 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.
  3. Set the Initial value of the regState register to Stopped. This can be accomplished in editor which can be opened by right-clicking on a prevState.

  4. In Program Editor: create new the variant of inspection macrofilter and name it Inspecting.

  5. Change the name of default variant to Stopped.

  6. In the Inspecting variant: add the ThresholdImage filter and connect its input with the macrofilter's input.

  7. 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.
  8. Open the HMI Designer. It is available in a View tab, or in a Toolbar.

  9. To allow the user to set the lower limit of threshold range, add to the HMI the TrackBar control available in the Controls category of HMI Controls.

  10. Add to the HMI the ImpulseButton control and set its Text parameter to Stop.

    • Connect the outValue with the inStopPressed input. From now, program executes Inspecting variant, until the Stop button is clicked.
  11. Connect the outNextState with register nextState.

  12. Create the macrofilter's outState output and also connect it with the outNextState.

  13. 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.

  14. Add to the HMI ImpulseButton control and set its Text parameter to Start.

    • Connect the outValue with the inStartPressed input. From now, program executes the Stopped variant until Start button is clicked.
  15. Connect the inImage input of the macrofilter with its outImage output, since no operations on image is performed in this variant.

  16. Generally the program is finished, however there is good practice to disable the controls which should not be used in each state. To accomplish this, add another Formula in the Main Task macrofilter.

  17. Create the inState input and connect it with the output of the Inspection macrofilter.

  18. 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.
  19. 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.
  20. 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.
  21. 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
ThresholdImage Image binarization when the illumination is constant and uniform.
GrabImage_FromFiles Can be used as EnumerateImages, but its state is global in a program - does not reset when some task is finished.
Delay Suspends the program workflow for inTime milliseconds.

Further Readings