AdvancedHMI Software
General Category => Open Discussion => Topic started by: DarrellK 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.
-
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.
-
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?
-
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: '***************************************************************************************
'* 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:
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.