Author Topic: Array value  (Read 13182 times)

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Array value
« on: June 10, 2018, 04:39:19 AM »
Hello.
i'm new with AdvancedHMI. (i use the version 35)
i'm using an OPC server (KEPServerEx V4.5) in order to connect to PLC siemens s7 300. : connection ok.
the configuration of OpcDaCom1 inside AdvancedHMI : ok.
i use the AnalogValueDisplay to read a word value from the OPC : ok. (without code, just i put the correct TAG in the PLCaddressvalue).

the problem is :
i have one Foat Array tab [76 elements], and i need to read each value separate.
the best solution for me is to write them in a database.

thank you.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #1 on: June 10, 2018, 05:07:53 AM »
I started the experiment with COPC32, but due to the license problem, I switched to advancedhmi.

below the code I used to read some values (with COPC32) :

Private Sub Label2_Click(sender As System.Object, e As System.EventArgs) Handles Label2.Click
        Dim words(76) As Single
        words = Axcopc1.GetVl(1)
        Dim A As Single = words(0)
        Dim B As Single = words(1)
        Dim C As Single = words(3)
        Dim D As Single = ( A * B * C)
        Label2.Text = D.ToString()

    End Sub

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #2 on: June 10, 2018, 06:24:52 AM »

is it correct ?

Private Sub BasicLabel1_Click(sender As System.Object, e As System.EventArgs) Handles BasicLabel1.Click

        Dim words(76) As Single
        words = OpcDaCom1.Read("words(0)", 76)
        Dim A As Single = words(0)
        Dim B As Single = words(1)
        Dim C As Single = words(3)
        Dim D As Single = (A * B * C)
        BasicLabel1.Text = D

    End Sub

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #3 on: June 10, 2018, 07:06:47 AM »
if it is possible to display the values in a table like in the attached pic
also all values must be stored in a database SQL Server

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #4 on: June 10, 2018, 07:24:16 AM »
screenshot of the OPC server and OPC client


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Array value
« Reply #5 on: June 10, 2018, 11:07:01 AM »
This would be more correct. There is not need to define the array size because the driver creates a new array of the correct size.
Private Sub BasicLabel1_Click(sender As System.Object, e As System.EventArgs) Handles BasicLabel1.Click

        Dim words() As String
        words = OpcDaCom1.Read("words(0)", 76)  '* The address is dependent on the OPC Server
        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)
        BasicLabel1.Text = D

    End Sub

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #6 on: June 10, 2018, 02:33:27 PM »
thnx for your reply.
attached the error message after the test.

Phrog30

  • Guest
Re: Array value
« Reply #7 on: June 10, 2018, 08:35:23 PM »
I don't think you can read a udt array like that.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #8 on: June 11, 2018, 03:42:37 AM »
is there another way to read the data (Array tab [x elements]) and store it in a database (or excel) ?
I need this architecture :
PLC (siemens s7 300) -> OPC (KEPServerEx V4.5) -> AdvancedHMI (i use v 35) -> Form and stored in database or in excel

Thanks for your help.

Phrog30

  • Guest
Re: Array value
« Reply #9 on: June 11, 2018, 06:34:36 AM »
I thought you were using the clx driver, so not sure if what I said is correct.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Array value
« Reply #10 on: June 11, 2018, 10:09:48 AM »
You could experiment with the attached modified version of OpcDaCom.vb file.

Download the file and then just right-click the AdvancedHMIDrivers project and select Add/Existing Item, browse to and select this downloaded file and replace the current file.

Currently, you have to address the whole array, without "( 0 )"  or  "[ 0 ]" at the end and without specifying 76.
Here is the example (use standard Label instead of BasicLabel):

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("Data Type Examples.16 Bit Device.K Registers.FloatArray", 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("Data Type Examples.16 Bit Device.K Registers.FloatArray", 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 = "Data Type Examples.16 Bit Device.K Registers.FloatArray" Then
                Dim D As Single = (e.Values(0) * e.Values(1) * e.Values(3))
                Label3.Text = D
            End If
        End If
    End Sub

The driver's DataReceived event should work for all values that are returned, so you might consider that as an option as well.


Writing to array doesn't seem to be currently working.
« Last Edit: June 11, 2018, 10:29:32 AM by Godra »

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #11 on: June 11, 2018, 01:22:25 PM »
thank you for your help.
after the integration of the new OpcDaCom.vb , I got two errors.


Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Array value
« Reply #12 on: June 11, 2018, 02:43:58 PM »
Just change the word Integer to String (just before the word "Implements" on Line 400).
The Return line within that function should also be corrected to:  Return CStr(Write(startAddress, 1, temp))


Or maybe consider downloading and using the latest beta version of AHMI.
« Last Edit: June 11, 2018, 03:40:24 PM by Godra »

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #13 on: June 11, 2018, 03:57:01 PM »
thank you
I followed your instruction, the problem is solved, but I have another error message.
(I inform you that I have not been able to display values).
i use the latest beta version of AHMI "AdvancedHMIv399x "



Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Array value
« Reply #14 on: June 11, 2018, 04:05:07 PM »
What is the Tag for your array and do you know if there are any values currently in the array?