Author Topic: Write two-dimensional array with twincat driver  (Read 1860 times)

bobobo

  • Newbie
  • *
  • Posts: 19
    • View Profile
Write two-dimensional array with twincat driver
« on: October 30, 2015, 02:28:50 PM »
Hi
In past versions (at least v3.02) of Adv.HMI it was working to write to 2-dimensional arrays in Twincat plc by treating them as 1-dimensional in AdvancedHMI.
Like this:
Code: [Select]
Plc declaration:
  controlcurve: ARRAY [0..99,0..1] OF REAL:= 200(0);

vb.net declaration:
  Dim cc(200) As String
 
TwinCATCom1.Write(".controlcurve", cc, 200)


But now in version 3.99a application breaks with error "WriteData2b, not possible to convert the string 99,0..1 to type integer" (error message translated from Swedish so it's not the literally exact message)

 
Code: [Select]
   Public Function Write(ByVal startAddress As String, ByVal dataToWrite() As String, ByVal numberOfElements As UInt16) As Integer
        If Not DLL.ContainsKey(MyDLLInstance) OrElse DLL(MyDLLInstance) Is Nothing Then CreateDLLInstance()
        Try
            Dim Sym As MfgControl.AdvancedHMI.Drivers.TcAdsSymbolInfo
            'Dim SymIndex As Integer
            Try
                Sym = GetSymbolInfo(startAddress)
            Catch ex2 As Exception
                System.Windows.Forms.MessageBox.Show("WriteData2b. " & ex2.Message)
                Throw
            End Try

With v3.99a the following is still working, but I don't like to rewrite the plc program.
Code: [Select]
Plc declaration:
  controlcurve: ARRAY [0..199] OF REAL:= 200(0);

vb.net declaration:
  Dim cc(200) As String
 
TwinCATCom1.Write(".controlcurve", cc, 200)




Can this be solved?

I could do it by looping through the array and write one element at time, but it's not elegant...

Best Regards
Mattias

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Write two-dimensional array with twincat driver
« Reply #1 on: October 30, 2015, 06:00:49 PM »
I just tried this code and it worked as expected:

        Dim v() As String = {"1", "2", "3"}
        TwinCATCom1.Write("Main.b[1,0]", v, 3)


In PLC Main program:
   b : ARRAY[0..5,0..10] OF DINT;

bobobo

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Write two-dimensional array with twincat driver
« Reply #2 on: October 30, 2015, 06:54:37 PM »
Thank you!

With the index it's working for me too now.

TwinCATCom1.Write(".controlcurve[0,0]", cc, 200)