Controlling Page/Form Display From a PLC Value

From AdvancedHMI
Jump to: navigation, search

Sometimes it is desired to control the current page being displayed by a register in the PLC. Although not directly obvious, but this is possible to do with AdvancedHMI.

The key to doing this is to use a hidden form that monitors the PLC value and selects the corresponding form to display. For this sample, the MainForm will be used as the controlling form. The code in this sample is somewhat advanced.

1) In Solution Explorer, double click MainForm.vb to open the form in Design View
2) From the Toolbox, add the desired communication driver and set its properties
3) From the Toobox, add a DataSubscriber
4) Set PLCAddressValue to the PLC register/tag to use for form switching
5) Double click the DataSubscriber to get back to the code
[code]

       Dim FormList() As System.Reflection.PropertyInfo = My.Forms.GetType().GetProperties()
       For Each f In FormList
           Dim z As Form = f.GetValue(My.Forms, Nothing)
           If z.Tag = e.Values(0) Then
               z.Show()
           Else
               z.Hide()
           End If
       Next

[/code]

6) Scroll to the top of the code and look for this code:

           AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)

7) Comment out that line of code by adding a ' 8) Your project is now setup to show forms by setting the Tag property of each form to the value the PLC will select