Author Topic: Micrologix 1400: Read multiples tags  (Read 2031 times)

cm1684

  • Newbie
  • *
  • Posts: 6
    • View Profile
Micrologix 1400: Read multiples tags
« on: May 14, 2019, 11:03:12 AM »
Hi. Firstly thanks for your time. I am working on a proyect of vb.net 2015 that needs to read 10 tags from my PLC Micrologix 1400  every 500ms. I tryed make it using a recursive structure on vb with the method ".read"  of EthernetIPforSLCMicroCom, but that is so slow and has lost records.



I would gratifully that someone showme an example to read multiples tags from the plc, or another suggest.

Best regards.

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #1 on: May 14, 2019, 04:47:44 PM »
That should be as simple as adding DataSubscriber2 to your form, then click its PLCAddressValueItems and add one item with the start address of N150:10 and set the number of elements to 10.

Then use either DataReceived or DataChanged event of this DataSubscriber2 to examine the values.

The attached picture shows an example of a single label displaying all the values for Modbus addresses 400001 to 400010 and the code is this:

Code: [Select]
    Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        If e.Values IsNot Nothing Then
            Me.Label1.Text = ""
            For i = 0 To 9
                Me.Label1.Text &= (e.PlcAddress + i) & " = " & e.Values(i).ToString & Environment.NewLine
            Next
        End If
    End Sub

DataChanged event is probably a better choice since it will be updated only when values change.

In your case the following line of code would probably be more suitable:

       Me.Label1.Text &= e.Values(i).ToString & Environment.NewLine

This since you cannot treat your PLC address as a number.
« Last Edit: May 14, 2019, 05:04:09 PM by Godra »

cm1684

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #2 on: May 14, 2019, 05:57:19 PM »
Thanks Godra. I will try it.
I am beginner on Advanced HMI and my project dont use controls from it. But anywhere i will try it.
I work actually on runtime.
Attach the code that i am using for now:


Code: [Select]

Private MicroGuardian As AdvancedHMIDrivers.EthernetIPforSLCMicroCom = New AdvancedHMIDrivers.EthernetIPforSLCMicroCom
    Private MicroTags As AdvancedHMIDrivers.EthernetIPforSLCMicroCom = New AdvancedHMIDrivers.EthernetIPforSLCMicroCom

Sub CapturarDatos()

        Dim conexion As New CConexion
        Dim datos As New CDatos

        Dim ComandoSQL As String = ""
        Dim Valores As String = ""
        For Each row As DataRow In tb_det.Rows
            If row.Item("habilitado") = True Then
                Dim Valortag As String = MicroTags.Read(row.Item("tag"))
                If Valores = "" Then
                    Valores = "'" & Valortag & "'"
                Else
                    Valores = Valores & ", '" & Valortag & "'"
                End If
            End If
        Next

        ComandoSQL = "INSERT INTO " & ObjetoDB & " (" & Columnas & ") values (" & Valores & ")"
        datos.ComandoSQL_opc = ComandoSQL
        datos.cadena_siscon = CadenaDB
        Dim resultado As Boolean = conexion.sis_opc_RegistroSQL(datos)

    End Sub



Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #3 on: May 14, 2019, 09:16:19 PM »
Since you are trying to do everything in the code then you should just use the driver to directly subscribe to your tags.

You could also add handlers for your driver when the form loads and then use those to handle received values (maybe store them in an array).

Spend some time searching through this forum to see some examples, maybe like this topic:

https://www.advancedhmi.com/forum/index.php?topic=989.0

cm1684

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #4 on: May 15, 2019, 09:01:10 AM »
i tried this, as the link suggest:

Code: [Select]

  Private MyEthernetIPforSLCMicroCom As AdvancedHMIDrivers.EthernetIPforSLCMicroCom = New AdvancedHMIDrivers.EthernetIPforSLCMicroCom
    Private SubscriptionID As Integer
    Private LastValue As String

    Public Sub New()
        InitializeComponent()
        MyEthernetIPforSLCMicroCom.IPAddress = "10.0.0.39"
    End Sub

    Private Sub fm_sis_opc_test_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        MyEthernetIPforSLCMicroCom.Subscribe("N150:10", 1, 500, AddressOf DataReturned)
    End Sub

    Private Sub DataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        Dim PlcIp As String
        Dim PlcTag As String
        Dim PlcValue As String
        Try
            Dim DriverComm As AdvancedHMIDrivers.EthernetIPforSLCMicroCom = CType(sender, AdvancedHMIDrivers.EthernetIPforSLCMicroCom)
            PlcIp = DriverComm.IPAddress
            PlcTag = e.PlcAddress
            PlcValue = e.Values(0).ToString()
            lb_estado.Text = PlcValue.ToString
        Catch ex As Exception
            lb_estado.Text = ex.Message
        End Try

    End Sub
    Private Sub MainFormX_FormClosing(sender As Object, e As Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        MyEthernetIPforSLCMicroCom.UnSubscribe(SubscriptionID)
    End Sub


but i don't receive nothing (DataReturned is never called).
Somethink strange is that if i use the EthernetIPforCLXCom driver, DataReturned is called but returns the error 5.

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #5 on: May 15, 2019, 10:22:18 AM »
If I modify your code to use ModbusTCP driver instead, and look like this:

Code: [Select]
    Private MyModbusTCPCom As AdvancedHMIDrivers.ModbusTCPCom = New AdvancedHMIDrivers.ModbusTCPCom
    Private SubscriptionID As Integer
    Private LastValue As String

    Public Sub New()
        InitializeComponent()
        MyModbusTCPCom.IPAddress = "127.0.0.1"
    End Sub

    Private Sub fm_sis_opc_test_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        MyModbusTCPCom.Subscribe("400001", 10, 500, AddressOf DataReturned)
    End Sub

    Private Sub DataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        Dim PlcIp As String
        Dim PlcTag As String
        Dim PlcValue As String
        Try
            Dim DriverComm As AdvancedHMIDrivers.ModbusTCPCom = CType(sender, AdvancedHMIDrivers.ModbusTCPCom)
            PlcIp = DriverComm.IPAddress
            PlcTag = e.PlcAddress
            PlcValue = e.Values(0).ToString()
            Label1.Text = PlcValue.ToString
        Catch ex As Exception
            Label1.Text = ex.Message
        End Try
    End Sub

    Private Sub MainFormX_FormClosing(sender As Object, e As Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        MyModbusTCPCom.Unsubscribe(SubscriptionID)
    End Sub

The DataRetuned is fired continuously and 10 values are returned but only the first value is shown on the label.

if I modify the DataReturned to this:

Code: [Select]
    Private Sub DataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        If e.Values IsNot Nothing Then
            Me.Label1.Text = ""
            For i = 0 To 9
                Me.Label1.Text &= (e.PlcAddress + i) & " = " & e.Values(i).ToString & Environment.NewLine
            Next
        End If
    End Sub

I do get to see all 10 values on the label.


So, I am not currently sure what EthernetIPforSLCMicroCom driver might require in addition to your code to make it work.

« Last Edit: May 15, 2019, 10:30:40 AM by Godra »

cm1684

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #6 on: May 15, 2019, 10:31:15 AM »
like i said i am a beginner and may be my question is silly, but: the tag that i am setting on the first parameter of the Subscription method is the next:



i dont know if "data file" and "tag" is the same.

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #7 on: May 15, 2019, 10:39:38 AM »
That should be correct and you should also be able to specify 10 elements, just like I did, to have it look like this:

     MyEthernetIPforSLCMicroCom.Subscribe("N150:10", 10, 500, AddressOf DataReturned)
« Last Edit: May 15, 2019, 11:51:32 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #8 on: May 15, 2019, 11:55:08 PM »
I tried your code with my MicroLogix 1100 PLC via EthernetIPforSLCMicroCom driver, subscribed to N7:0 for 10 elements and the DataReturned was firing and returning those values.

There must be something on your end that's incorrect.

cm1684

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #9 on: May 16, 2019, 07:22:18 AM »
is weird, if i use:

MyEthernetIPforSLCMicroCom.Read("N150:10")

that works fine, return the value... but i cant do the Subscription
« Last Edit: May 16, 2019, 07:42:14 AM by cm1684 »

bachphi

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #10 on: May 16, 2019, 07:40:54 PM »
It's strange for a newbie, not wanting to use controls where the AAHMI is designed for. And worse,  not wanting to do any searching.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

cm1684

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Micrologix 1400: Read multiples tags
« Reply #11 on: May 17, 2019, 12:49:31 PM »
Great contribution bachphi, regards!