Author Topic: Basic Label Question  (Read 6804 times)

cws

  • Newbie
  • *
  • Posts: 16
    • View Profile
Basic Label Question
« on: September 30, 2013, 12:59:47 PM »
Hi,

I'm trying to use the BasicLabel control to show bit flags from the PLC.  I want to be able to show each section as a number like "1", "2", "3" etc.. and just set the color based on the "0" or "1" coming from the PLC.   When a value comes back from the PLC, it shows as True or False on the label and overwrites the "1", "2", etc...  I'm I supposed to hook into the TextChanged event and put the numbers back into the Value property or have a different set of number labels overlaying the Basiclabel control?  Also, when I change the BooleanDisplay to "On/Off" or "Yes/No" it still shows "True/False".    Should I be using the BasicLabel control or something else?

Thanks,
Chris

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Basic Label Question
« Reply #1 on: September 30, 2013, 02:55:50 PM »
Would a MessageDisplayByValue or MessageDisplayByBit along with HighlightKeyChar and HighlightColor work for you?

If not, I would add DataSubscribers to the form and Labels(from the All Windows ToolBox group). Double click the DataSubscriber to get to the DataChanged event and use something like this:

Code: [Select]
If e.values(0)="True" then
  Label1.Text="1"
  Label1.BackCoor=Color.Red
else
  Label1.Text="0"
  Label1.BackColor=Color.Green

cws

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Basic Label Question
« Reply #2 on: October 01, 2013, 10:22:41 AM »
I tried to use DisplayMessageByValue or DisplayMessageByBit  but must be doing something wrong.  I'm getting 'Invalid Value Returned!" on both of them.  I had it working with the BasicLabel control and controlled the color through the TextChanged event but I need to show a static number on each of them and just change the color.  It seems like DisplayMessageByValue or DisplayMessageByBit should work.  I tried setting up messages for 0 = Running, 1 = Stopped in the messages collection for each control.  Right now the DisplayMessageByValue flips between "False - Invalid Value Returned!" and "(0) Running".  The DisplayMessageByBit control flips between "False - Invalid Value Returned!" and "No Messages".  In the messages collection should I be using 1 and 0 or True and False or something else?  Also, what is the difference between the TextChanged event and the ValueChanged event and when would I use one over the other?   

I'm familiar with .NET programming but not PLC's.  I'm using 3.58 of AdvancedHMI and trying to use the EthernetIPforCLXCom driver.

Thanks,
Chris

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Basic Label Question
« Reply #3 on: October 01, 2013, 10:32:17 AM »
The MessageDisplays can only work with integers. They are not setup to work with True or False values.

The ValueChanged event will fire only when the value from the PLC changes, but the TextChanged event can fire if anything changes such as prefix, suffix, or even and error message will fire the event.

If you are familiar with .NET programming, the easiest route will be to use the DataSubscriber along with Labels.

cws

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Basic Label Question
« Reply #4 on: October 01, 2013, 01:46:50 PM »
Thanks for the fast responses Archie.

I'm trying to use the DataSubscribers which looks like it would work.  Since I have 18 values to track, I'm trying to use one routine to manage colors and text changes for the labels sine they are basically the same except a different number being displayed.  I added an AddHandler line for each DataSubscriber in the "Form New" event so that I could manage the code from one event like this:

AddHandler DataSubscriber1.DataChanged, AddressOf DataSubscriber_DataChanged
AddHandler DataSubscriber2.DataChanged, AddressOf DataSubscriber_DataChanged
AddHandler DataSubscriber3.DataChanged, AddressOf DataSubscriber_DataChanged
...

When the form first loads I get "Invoke or BeginInvoke cannot be called on a control until the window handle has been created." errors for each DataSubscribers.  If I go past all of the errors, it seems to work.  The DataSubscriber_DataChanged looks something like this:

  Private Sub DataSubscriber_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs)

        Dim ctl As MfgControl.AdvancedHMI.DataSubscriber = DirectCast(sender, MfgControl.AdvancedHMI.DataSubscriber)

        Try

            Dim strSection As String = ctl.PLCAddressValue.Substring(2, 2)
            Dim lbl() As Control = Me.Controls.Find("lblORASection_" & strSection, False)

            If lbl.Length = 1 Then
                If e.Values(0) = "True" Then
                    lbl(0).BackColor = Color.Red
                    lbl(0).Text = strSection & vbCrLf & "Stopped"
                Else
                    lbl(0).BackColor = Color.LimeGreen
                    lbl(0).Text = strSection & vbCrLf & "Running"
                End If
            End If
       
        Catch ex As Exception

            MessageBox.Show(ex.ToString, "HMI Error - DataSubscriber_DataChanged", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

Should the AddHandler be done differently?

Thanks,
Chris

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Basic Label Question
« Reply #5 on: October 01, 2013, 02:10:17 PM »
If you are instantiating the DataSubscriber in code, be sure to set the SynchronizingObject property to the form. If you added the DataSubscriber to the design view of the form, this will be taken care of for you.

There was also some updates to the DataSubscriber. You can try the attached version.

« Last Edit: October 01, 2013, 03:52:01 PM by Archie »

cws

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Basic Label Question
« Reply #6 on: October 01, 2013, 03:41:26 PM »
Has the SynchronizingObject method changed.  It seems to be commented out in the code that you sent.

Chris

cws

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Basic Label Question
« Reply #7 on: October 01, 2013, 04:30:09 PM »
With the new file, the method is back but it doesn't seem like the DataSubscriber.DataChanged event is firing now.  I was experimenting with something like:

Public objDataSubscribers(17) As MfgControl.AdvancedHMI.DataSubscriber
Private Sub ATAddOnBoard_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim i As Integer
        For i = 0 To 17
            objDataSubscribers(i) = New MfgControl.AdvancedHMI.DataSubscriber
            objDataSubscribers(i).CommComponent = EthernetIPforCLXCom1
            objDataSubscribers(i).SynchronizingObject = Me
            objDataSubscribers(i).PLCAddressValue = "WS" & (i + 1).ToString("D2") & "LineStop"
            AddHandler objDataSubscribers(i).DataChanged, AddressOf DataSubscriber_DataChanged
        Next

End Sub

Nothing was firing and then tried to just add the datasubscribers from the toolbox to the form but still couldn't get them to fire.  I put the original 358 DataSubscriber.vb file back and got the Invoke errors again but once past those, it worked.

Chris

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Basic Label Question
« Reply #8 on: October 01, 2013, 09:30:44 PM »
I think I finally got it all straight now