Author Topic: Extending BasicTrendChart to trend BOOLs  (Read 1994 times)

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Extending BasicTrendChart to trend BOOLs
« on: October 09, 2024, 08:54:26 AM »
Hey all, I'm working on a project, and I've come to want to be able to trend some boolean values. I have my CLX driver set up just fine, and when I point a BasicTrendChart at a DINT tag, it trends just fine. When I point it at a BOOL tag, though, I get no graphing.

I *believe* this is because the BasicTrendChart is expecting an Int32, and the driver is returning a string with the literal "True" or "False"

Is there a way to inherit the BasicTrendChart and make it work with BOOLs?

Thanks for your time!


Edit: I am using 3.99y Beta 40
« Last Edit: October 09, 2024, 08:57:25 AM by bobbh95 »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Extending BasicTrendChart to trend BOOLs
« Reply #1 on: October 09, 2024, 11:05:36 AM »
Is there a reason you want to use the BasicTrendChart and not something a bit more advanced like the ChartWithLogging?

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Extending BasicTrendChart to trend BOOLs
« Reply #2 on: October 09, 2024, 11:53:10 AM »
As it stands, I don't need it for anything complex, and I hadn't tried using the ChartWithLogging when writing the question. There will be a number of trends visible simultaneously, but they're all distinct from one another - that is to say, they should all be their own graph.


I've since seen that the ChartBySampling works well enough for this simple use-case. I had also seen your writings elsewhere how BasicTrendChart is the fastest of the charting controls. I don't even need to display the name of the series. It's less work to programmatically add them by comparison, due to fewer initialization requirements.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Extending BasicTrendChart to trend BOOLs
« Reply #3 on: October 09, 2024, 12:32:57 PM »
The BasicTrendChart is a very bare bones control which makes it very fast, but lacking in features.

Attached is the underlying control if you wanted to give a go at modifying it for boolean values.

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Extending BasicTrendChart to trend BOOLs
« Reply #4 on: October 09, 2024, 05:50:20 PM »
Awesome! Thank you for throwing out the base source code; it's a lot better (for someone like me) to see the actual source, rather than trying to ponder on how it works when it has been decompiled into C# - a language I know significantly less than VB.net.



Perhaps (and I suspect this to be the case) I'm simply missing something? I don't see anywhere in that file where a Subscription is made to the PLC, nor where it handles the returned data? Is that encapsulated in the actual BasicTrendChart file? Or would it make more sense for me to extend the DataSubscriber class, and modify how it returns Boolean values to upstream controls? Because if the implementation were to happen purely in the BasicTrendChart class, I'm 1000% lost.


Thank you again for your time! You're a saint, Archie!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Extending BasicTrendChart to trend BOOLs
« Reply #5 on: October 09, 2024, 06:29:27 PM »
The BasicChart is only a Windows control without any connection to the PLC.

The BasicTrendChart inherits the BasicChart and adds the "AdvancedHMI" parts to it so it can connect to the PLC.

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Extending BasicTrendChart to trend BOOLs
« Reply #6 on: October 09, 2024, 07:09:47 PM »
Hmm, then I suppose that part isn't what is a mystery to me, it would be where in BasicTrendChart it deals with the information coming back from the Subscription.
ch
I can see where BasicTrendChart creates a ComComponent as m_ComComponent if it doesn't already exist, then subscribes to it with SubscribeToComDriver()

I also see the Public Property for Value, which I (assume) to be where a point is added, by an added value.
s
I then see there's a SubscribeAutoProperties contained within the SubscriptionHandler class, as well as event handlers such as SubscribedDataReturned(BV s A o, BC e A PlcComEventArgs)



I'm just struggling to find where exactly I'd want to make a change for my desired behavior. I have a suspicion that in SubscribedDataReturned, I'd want to do something such as the following, but I just really don't know for sure (and I've spent a pretty substantial amount of time fiddling around with things trying to get them working as intended to no avail.)


Code: [Select]
    Private Sub SubscribedDataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        For Each Subscript In m_SubscriptionList
            Dim address As String = Subscript.PLCAddress
            If Subscript.Invert Then
                address = Subscript.PLCAddress.Substring(4)
            End If

            If e.ErrorId = 0 Then

                'If (e.PlcAddress Is Nothing) OrElse (String.Compare(address, e.PlcAddress, True) = 0) Then
                If (e.PlcAddress Is Nothing) OrElse (e.SubscriptionID = Subscript.NotificationID) Then
                    Dim a As New SubscriptionHandlerEventArgs
                    a.PLCComEventArgs = e
                    a.SubscriptionDetail = Subscript

                    If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
                        '* Check if the value should be inverted
                        If Subscript.Invert Then
                            '* Try to invert a boolean value
                            Try
                                Dim ea As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs
                                '* Clone the EventArgs for the inversion because there may be another subscription that doesn't need inverted
                                ea = CType(e.Clone, MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
                                Dim x As New System.Collections.ObjectModel.Collection(Of String)


                                ' HERE IS MY CHANGED CODE


                                If e.Values(0) = True Then
                                    Dim s As String = "1"
                                ElseIf e.Values(0) = False Then
                                    Dim s As String = "0"
                                Else
                                    Dim s As String = (Convert.ToString(Not CBool(e.Values(0))))
                                End If

                                ' EVERYTHING AFTER THIS UNCHANGED


It seems like this would be the most logical place for me to make a change to an existing class, but it would have to be *specific* to this particular application. But, from how you understand AdvancedHMI to function - as the creator - does this look like it would work? Or am I entirely off base here?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Extending BasicTrendChart to trend BOOLs
« Reply #7 on: October 09, 2024, 07:17:47 PM »
I would probably make the base control handle "True" or "False" like this:

Code: [Select]
    Public Property Value As String
        Get
            Return ""
        End Get
        Set(value As String)
            Try
                If Not String.IsNullOrEmpty(value) Then
                    If String.Compare(value, "True", True) = 0 Then
                        m_Points.Add(1)
                    ElseIf String.Compare(value, "False", True) = 0 Then
                        m_Points.Add(0)
                    Else
                        m_Points.Add(CSng(value))
                    End If
                End If
            Catch ex As Exception
            End Try
        End Set
    End Property

You can make a copy of the BasicChart and rename it to BasicChart2, then change BasicTrendChart to Inherit BasicChart2

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Extending BasicTrendChart to trend BOOLs
« Reply #8 on: October 09, 2024, 07:52:01 PM »
Okay, so if that's the case, then when the BasicTrendChart is updating the underlying Collection of Points, it does so by calling the Value.Set() method from BasicChart?

If so, that is the bit I was missing out on! I assumed that was the situation, but I couldn't see where it was explicitly called. If that's all it would take, then I'll go ahead and attempt that tomorrow when I'm back at work.

Thank you again Archie! I'll try that out tomorrow, and I have no doubt it'll work phenomenally. Maybe someday I'll understand VB/AdvHMI enough to be able to track down where edits are necessary for my desired functionality.

For the time being, I suppose I'll simply have to rely on your magnanimity.

I'll drop in a screenshot of the HMI page in question tomorrow, so you'll at least be able to see how you've helped me here!
« Last Edit: October 09, 2024, 09:17:24 PM by bobbh95 »