Author Topic: PLC control of which screen is displayed  (Read 891 times)

DarrellK

  • Newbie
  • *
  • Posts: 4
    • View Profile
PLC control of which screen is displayed
« on: August 23, 2018, 08:57:03 AM »
My project will have 5 screens.  Is there a simple way to have the PLC change which screen is displayed?  I'm sure I could do this with a little VB code but I'm wondering if you already have a "no code" way to do this.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: PLC control of which screen is displayed
« Reply #1 on: August 23, 2018, 09:03:31 AM »
The way I do this is with a "Main Menu Driven setup", then add a DataSubscriber to the MainMenu. On the DataChanged event handler, perform a button click in code to make it change the page.

DarrellK

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: PLC control of which screen is displayed
« Reply #2 on: August 23, 2018, 12:21:50 PM »
OK, this seems to be working like you say.  It's similar to what I was thinking of doing.  Just to be clear, it seems like I need to put a DataSubscriber on each screen to read the PLC address regardless of what screen is currently showing.  No problem there.

Now the other direction.  How would you have the PLC know what screen is currently displayed?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: PLC control of which screen is displayed
« Reply #3 on: August 23, 2018, 02:42:05 PM »
I was actually referring to using the MainMenu design pattern because it would only require a single DataSubscriber:

https://www.advancedhmi.com/forum/index.php?topic=1549.msg8337#msg8337

This is sample code from a project I did using that technique:
Code: [Select]
   '***************************************************************************************
    '* Monitor the screen selection tag and switch forms
    '***************************************************************************************
    Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles ScreenSelectDataSubscriber.DataChanged
        Try
            If e.ErrorId = 0 AndAlso e.Values.Count > 0 Then
                Select Case e.Values(0)
                    Case 1 : RecipeQueButton.PerformClick()
                    Case 2 : MixTableButton.PerformClick()
                    Case 3 : HopperInitializeButton.PerformClick()
                    Case 4 : BarcodeButton.PerformClick()
                    Case 5 : WeighUpButton.PerformClick()
                    Case 10 : OptionalMaterialButton.PerformClick()

                End Select
            End If
        Catch ex As Exception
        End Try
    End Sub


To inform the PLC which form is showing, in the VisibleChanged event handler, write a value to the PLC. As an example:
Code: [Select]
     Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        '* Do not start comms on first show in case it was set to disable in design mode
        If NotFirstShow Then
            AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
        Else
            NotFirstShow = True
        End If

        If Visible then
           Try
              If NOT String.IsNullOrEmpty(Tag) then EthernetIPforCLXCom.Write("ScreenNumberTag", Tag)
           Catch
           End Try
        End IF
    End Sub

In the example code, I use the Tag property of the form to indicate a form number.