Author Topic: Array value  (Read 8066 times)

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Array value
« Reply #15 on: June 11, 2018, 04:24:10 PM »
You need to know your Tags and the last post in this topic explains how to achieve that:

https://www.advancedhmi.com/forum/index.php?topic=648.msg2968#msg2968
« Last Edit: June 11, 2018, 04:27:20 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Array value
« Reply #16 on: June 11, 2018, 04:38:37 PM »
I just checked the screenshot of the OPC server and OPC client which you posted previously.

Your Tag shows as KWh_Tg_akt (but it might be longer as the screenshot only shows a part of it, like .EM.KWh_Tg_akt).

This is the tag that you need to use instead of: Data Type Examples.16 Bit Device.K Registers.FloatArray

So the previous code examples should be modified to look similar to this:

Using Read function:
Code: [Select]
    Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
        Dim words() As String
        words = OpcDaCom1.Read("KWh_Tg_akt", 1)
        Dim A As Single = CSng(words(0))
        Dim B As Single = CSng(words(1))
        Dim C As Single = CSng(words(3))
        Dim D As Single = (A * B * C)
        Label3.Text = D
    End Sub



Using Subscribe function which will automatically update the values whenever they change:
Code: [Select]
    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        OpcDaCom1.Subscribe("KWh_Tg_akt", 1, 0, AddressOf SubscribedDataChanged)
    End Sub

    Private Sub SubscribedDataChanged(sender As Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        If e.ErrorId = 0 Then
            If e.PlcAddress = "KWh_Tg_akt" Then
                Dim D As Single = (e.Values(0) * e.Values(1) * e.Values(3))
                Label3.Text = D
            End If
        End If
    End Sub

« Last Edit: June 11, 2018, 04:47:34 PM by Godra »

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #17 on: June 11, 2018, 08:44:13 PM »
thanks a lot for your help
Finally, I succeeded to display all the information that I need.
another thing please :
I need to store all those informations in a database every 5 sec for example.


Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Array value
« Reply #18 on: June 11, 2018, 11:19:19 PM »
I cannot really help you with that part but some other forum members might be able to help.

You will first need to decide what you would like to use to store all the data (csv file or excel file or some variant of SQL database ...or...).

Here is a few topics in this forum with some examples:

https://www.advancedhmi.com/forum/index.php?topic=1750.0
https://www.advancedhmi.com/forum/index.php?PHPSESSID=5e98f7ea80c666b83e121d6db1c1ee92&topic=1341.0
https://www.advancedhmi.com/forum/index.php?topic=1378.0

You should consider using the Subscribe function example since it will be recording the data only when it changes (adding the timestamp along with the data values would probably be helpful).

Using BasicDataLogger2 component would be one of the options.
« Last Edit: June 11, 2018, 11:30:15 PM by Godra »

Phrog30

  • Guest
Re: Array value
« Reply #19 on: June 12, 2018, 06:28:40 AM »
There are a ton of examples on the web about database stuff. I use sqllite and it works well. I've posted a few apps that have it built in. Feel free to look at them.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #20 on: June 13, 2018, 12:31:09 PM »
I'm sorry to say that until now, I have not been able to write the data already displayed in a database ...
thanks for all who helped me.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #21 on: June 13, 2018, 01:37:17 PM »
is there a way to transfer all the data to excel file in real time?
PLC -> OPC -> AdvancedHMI application -> excel
if yes, how much recording data can I transfer ?

Phrog30

  • Guest
Re: Array value
« Reply #22 on: June 13, 2018, 06:34:32 PM »
What is your problem in writing to a database? Using Excel is very simple, Archie has posted sample applications, but using Excel is clunky at best. Using a database is a lot better.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Array value
« Reply #23 on: June 13, 2018, 06:39:00 PM »
On the AdvancedHMI YouTube channel is a video that shows how to log data to a database. It uses Data Sources which is a tool within Visual Studio that makes it fairly easy. See this thread for a link to the video:

https://www.advancedhmi.com/forum/index.php?topic=1341.msg7123#msg7123

At about 10:00 into the video is where is shows the database information.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #24 on: June 14, 2018, 05:57:29 AM »
thank you friends.
I followed your instructions
I encountered the following error.


Code: [Select]

Private Sub DataSubscriber1_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataReturned
        Using t As New dbalfaDataSet.DataSamplesDataTable
            t.AddDataSamplesRow(t.NewRow)
            t(0).value = e.Values(0)
            Using ta As New dbalfaDataSetTableAdapters.DataSamplesTableAdapter
                ta.update(t)
            End Using
        End Using

    End Sub



MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #25 on: June 14, 2018, 06:17:30 AM »
attached the options displayed after choosing dataset and SetTableAdapters

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Array value
« Reply #26 on: June 14, 2018, 06:24:13 AM »
It looks like you named your data table EM, not DataSample.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #27 on: June 14, 2018, 07:03:08 AM »
Thank you Archie
The code seems works without error.
I'm sorry because I'm a beginner and I hope it does not bother you.

I need to know haw can i choose a variable from the array to write it in the database ?
I need to know how to link a variable from array (opc) to the database.

My code :
Read a variable from OPC I1 :
Code: [Select]
Private Sub Label2_Click(sender As System.Object, e As System.EventArgs)
        Dim words() As String
        words = OpcDaCom1.Read("TEST.EM.KWh_Tg_akt", 1)
        Dim I1 As Single = CSng(words(1))
        Label2.Text = I1
    End Sub

instant update of the variable I1:
Code: [Select]
Private Sub SubscribedDataChanged(sender As Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        If e.ErrorId = 0 Then
            If e.PlcAddress = "TEST.EM.KWh_Tg_akt" Then
                Dim I1 As Single = (e.Values(1))
                Label2.Text = I1
End If
        End If
    End Sub

The Database :
Code: [Select]
Private Sub DataSubscriber1_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataReturned
        Using t As New dbalfaDataSet.EMDataTable
            t.AddEMRow(t.NewRow)
            t(0).TEST = e.Values(0)
            Using ta As New dbalfaDataSetTableAdapters.EMTableAdapter
                ta.Update(t)
            End Using
        End Using

    End Sub

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #28 on: June 17, 2018, 09:05:14 AM »
I tried to connect to a MySql database and I succeeded, but the problem is that I get the first 100 values only.
and I have not found a solution until now.

Code: [Select]
Public Class MainForm
    Dim MysqlConn As MySqlConnection
    Dim COMMAND As MySqlCommand
.
.
.

MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString =
        "server=localhost;userid=root;password=;database=technique"
        Dim READER As MySqlDataReader
        Try
            MysqlConn.Open()
            Dim Query As String
           
            Query = "insert into technique.DATA (id,value) values ('" & 0 & "' , '" & BasicLabel4.Value & "')"
            COMMAND = New MySqlCommand(Query, MysqlConn)
            READER = COMMAND.ExecuteReader
        Catch ex As Exception
            MysqlConn.Close()
        End Try



the solution that you proposed is better and very useful.
because you can connect directly and automatically to a database SQLSERVER (generate all the fields automatically).

can you correct this code for me please :

Code: [Select]
Private Sub DataSubscriber1_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataReturned
        Using t As New techniqueDataSet.DATADataTable
            t.AddDATARow(t.NewRow)
            t(0).value = e.Values(0)
            Using ta As New techniqueDataSetTableAdapters.DATATableAdapter
                ta.Update(t)
            End Using
        End Using
    End Sub


« Last Edit: June 17, 2018, 09:45:18 AM by MEDALI1TN »

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Array value
« Reply #29 on: June 17, 2018, 11:05:19 AM »
Have you tried using Fill instead of Update ( ta.Fill(t) )?