Author Topic: CompactLgx BasicDataLogger2 with division  (Read 1669 times)

suparman

  • Newbie
  • *
  • Posts: 18
    • View Profile
CompactLgx BasicDataLogger2 with division
« on: November 16, 2018, 08:03:22 PM »
Hello,
I try to use  BasicDataLogger2 but the value need to divide by 10 to accommodate correct value.
Is there way to add the program in AHMI?

Regards

Supar

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #1 on: November 17, 2018, 06:25:43 PM »
If I understand your question correctly then you would just need to use the ScaleFactor property as the attached picture shows.

suparman

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #2 on: November 18, 2018, 07:18:12 PM »
Thank you Godra,
I try to fill the scale factor parameter and work for the positive value from plc but the negative value is not work.

suparman

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #3 on: November 18, 2018, 08:17:44 PM »
I'm not sure about that part.

Archie might need to suggest if the public function GetScaledValue works properly for negative values.

suparman

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #4 on: November 19, 2018, 04:34:48 PM »
Any suggestion or something to solve this negative value?
Regards

Supar
« Last Edit: November 19, 2018, 07:52:23 PM by suparman »

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #5 on: November 19, 2018, 09:32:34 PM »
Is it too difficult for you to divide it using the PLC, it's controllogix after all.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #6 on: November 19, 2018, 11:15:17 PM »
You can try using old code, inside the DataSubscriber2 - Region "Subscribing and PLC data receiving" - Private Sub PolledDataReturnedValue, just replace the whole sub with the following:

Code: [Select]
    Private Sub PolledDataReturnedValue(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        Try
            '* Fire this event every time data is returned
            OnDataReturned(e)

            'For index = 0 To m_PLCAddressValueItems.Count - 1
            '    If String.Compare(e.PlcAddress, m_PLCAddressValueItems(index).PLCAddress, True) = 0 Then
            '        Dim i As Integer
            '        Dim tempString As String = ""
            '        Dim tempValue As String = ""
            '        While (i < e.Values.Count)
            '            Try
            '                tempValue = m_PLCAddressValueItems(index).GetScaledValue(e.Values(i))
            '            Catch ex As Exception
            '                tempValue = "," & "INVALID - Check scale factor/offset - " & e.Values(i)
            '            End Try

            '            If i > 0 Then
            '                tempString &= "," & tempValue
            '            Else
            '                tempString = tempValue
            '            End If
            '            i += 1
            '        End While

            '        If m_PLCAddressValueItems(index).LastValue <> tempString Then
            '            m_PLCAddressValueItems(index).LastValue = tempString

            '            '* This event is only fired when the returned data has changed
            '            OnDataChanged(e)
            '        End If
            '    End If
            'Next

            For index = 0 To m_PLCAddressValueItems.Count - 1
                If String.Compare(e.PlcAddress, m_PLCAddressValueItems(index).PLCAddress, True) = 0 Then
                    Dim i As Integer
                    Dim tempString As String = ""
                    Dim tempValue As String = ""
                    While (i < e.Values.Count)
                        Try
                            If m_PLCAddressValueItems(index).ScaleFactor = 1 Then
                                If m_PLCAddressValueItems(index).ScaleOffset <> 0 Then
                                    tempValue = CStr((CDbl(e.Values(i)) + m_PLCAddressValueItems(index).ScaleOffset))
                                Else
                                    tempValue = e.Values(i)
                                End If
                            Else
                                tempValue = CStr((CDbl(e.Values(i)) * m_PLCAddressValueItems(index).ScaleFactor + m_PLCAddressValueItems(index).ScaleOffset))
                            End If
                        Catch ex As Exception
                            tempValue = "," & "INVALID - Check scale factor/offset - " & e.Values(i)
                        End Try

                        If i > 0 Then
                            tempString &= "," & tempValue
                        Else
                            tempString = tempValue
                        End If
                        i += 1
                    End While

                    If m_PLCAddressValueItems(index).LastValue <> tempString Then
                        m_PLCAddressValueItems(index).LastValue = tempString

                        '* This event is only fired when the returned data has changed
                        OnDataChanged(e)
                    End If
                End If
            Next

        Catch
            DisplayError("INVALID VALUE RETURNED!")
        End Try
    End Sub

The current code has been included here as a commented section.

suparman

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #7 on: November 20, 2018, 02:35:25 AM »
I try to BUILD (F7) but too many error. Might you attach DataSubscriber2.vb so I can to add the item.

regards

Supar
« Last Edit: November 20, 2018, 06:49:29 PM by suparman »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #8 on: November 20, 2018, 07:03:06 PM »
The file is attached and should be added to the AdvancedHMIControls\Components folder as an existing item (to replace the existing file).

Whenever you mention errors you should post them as well so we could see.

Generally, you should always close all the open forms and then try rebuilding the solution after changes are made to the controls/components.

suparman

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: CompactLgx BasicDataLogger2 with division
« Reply #9 on: November 20, 2018, 10:09:55 PM »
Hi Godra,
Now the negative value can log in with the correct value into the file, it's nice.
Thank you very much for help.
Best regards

Supar