Write array of struct using TwinCAT.Ads through vb.net application

1k Views Asked by At

I’m using TwinCAT.Ads (TwinCAT 3) for Beckhoff plc communication through vb.net application. Application is reading and writing few plc variables. I need to write in an array of struct.

My struct :

Friend Structure Struct_Recette
    Dim nNumProg As Integer             ' Programme associated
    Dim nNumZone As Integer             ' Zone
    Dim nNumManifold As Integer         ' Manifold
    Dim nNumRallonge As Integer         ' Rallonge
    Dim nNumSaphir As Integer           ' Saphir
    Dim nNumMors As Integer             ' Mors
End Structure

My Plc :

valTabRecette:      ARRAY [0..15] OF Struct_Recette;

My Code :

Friend Sub ValidationMPodeProd(sender As Object, e As EventArgs) Handles btnValidProd.Click
    Dim valTabRecette(0 To 15) As Struct_Recette

    'Some code to fill the structs

        ADS.WriteAny(PLCHandle, valTabRecette)
    End If
End Sub

I Have the error when I launch this :

0x705 parameter size not correct    

I resolve the problem :
The type are not the same in vb.net and Beckhoff

vb.net          Beckhoff 
int        =      Dint
short      =      int

....etc

So the parameters of my struct had not the good type

1

There are 1 best solutions below

0
On BEST ANSWER

A reference for those who are having similar problems: The difference in data type for TwinCAT and VB can be found in Beckhoff website: https://infosys.beckhoff.com/english.php?content=../content/1033/tcsystemmanager/basics/TcSysMgr_DatatypeComparison.htm&id=

TwinCAT is using IEC61131-3 standard.