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

HMI Start Stop Pause

Aim:

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

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

In the 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 four variants. The state of the application is modified with the Global Parameters and the HMI Events.

Solution (FIS):

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

  2. Create the Global Parameter State of type String. Set its initial value to Inspecting. Add the ReadParameter filter and set its output as the State parameter.

  3. 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 input.
    • Set its Name to State.
    • Set type of data to the String. It is equivalent of 'switch-case' statement.
    • Connect it to the ReadParameter filter output.
  4. In Program Editor, create 3 new variants of the Inspection macrofilter and name them: Inspecting, Iterating and Paused.

  5. Change the name of default variant to Stopped.

  6. Add a macrofilter register of type Image, name it LastImage and set its initial value to the macrofilter Image input.

  7. In the Inspecting variant, create a Step macrofilter named ProcessImage. Inside this step:

    • Create an input and an output of type Image.
    • Add the ThresholdImage filter and connect its Image input and output with the step's.
  8. Return to the the Inspecting variant:

    • Connect the Image input of the ProcessImage with the macrofilter input.
    • Connect the Image output of the ProcessImage with the nextLastImage register and the macrofilter output.
  9. In the Iterating variant:

    • Add the ProcessImage step.
    • Connect the Image input of the ProcessImage with the macrofilter input.
    • Connect the Image output of the ProcessImage with the nextLastImage register and the macrofilter output.
    • After the ProcessImage step, add the WriteParameter filter with the State input and set its value to Paused.
  10. In the Paused variant, connect the prevLastImage register with the macrofilter output.

  11. In the Stopped variant, connect the Image macrofilter input with the Image macrofilter output.

  12. Open the HMI Designer. It is available in a View tab, or in a Toolbar.

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

    • Connect its outValue with the inMinValue inside the ProcessImage macrofilter.
  14. Add to the HMI 4 ImpulseButton controls and set their Text parameter to Start, Iterate, Pause and Stop.

  15. Now you need to create a Event macrofilter using the buttons. To do so, press the first one on the HMI and go to Events window to create a new event handler for the Click action. Set its name to ControlButtonClicked:

  16. Navigate to the newly created Event macrofilter by clicking it twice in the Project Explorer. Inside of it:

    • Add the ReadParameter filter with the State output.
    • Create a formula:

      • Drag the ReadParameter output to the formula to create an input and name it PreviousState.
      • Create 4 other inputs of type Bool and name them: StartButton, StopButton, IterateButton, PauseButton. Connect them to the Value outputs of the HMI buttons.
      • Write the formula:

      outState = if inStartButton then "Inspecting" else if inStopButton then "Stopped" else if inIterateButton then "Iterating" else if inPauseButton then "Paused" else inPreviousState

    • Add the WriteParameter filter with the State input. Connect the input with the formula output.

  17. Connect the ControlButtonClicked event handler with the rest of the HMI buttons for the Click action.

  18. Add to the HMI a VideoBox control. Connect its Image input to the Inspection variant output.

  19. 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, create a new Step macrofilter, name it EnableHmiButtons and add it after the Inspection variant in the Main Task macrofilter.

  20. Inside the created step:

    • Add the ReadParameter filter with the State output.
    • Add a formula.
    • Connect the ReadParameter output with the Formula and name the created input as State.

      outStartEnabled = inState <> "Inspecting"

      outStopEnabled = inState <> "Stopped"

      outPauseEnabled = inState == "Inspecting"

      outIterateEnabled = inState == "Paused"

    • Connect the Formula outputs to the Enabled inputs of the HMI buttons.

  21. Add the Delay filter in the Main Task macrofilter and set the inTime to 50. This filter suspends the program workflow for 50 milliseconds.

Macrofilter Main.

Macrofilter Inspection(Inspecting)

Macrofilter Inspection(Iterating)

Macrofilter Inspection(Paused)

Macrofilter Inspection(Stopped)

Macrofilter ProcessImage.

Macrofilter EnableHmiButtons.

Macrofilter ControlButtonClicked.

Further Readings