Beckhoff / ADS

Beckhoff protocol to communicate with TwinCAT devices.
MIT License
493 stars 194 forks source link

Reading REFERENCE TO <TYPE> and dereferenced pointer always returns invalid index group #158

Closed GISED-Link closed 1 year ago

GISED-Link commented 2 years ago

Hi,

The Scada server I use (SpiderControl) uses the ADS-sum command to reach the variables inside my PLC. Everything is alright for most of the variables.

My only concern is for REFERENCE TO and REFERENCE TO ARRAY variables. I often use those one for my recipe or to simplify the call inside my Scada server. The problem is that REFERENCE TO is not supported by the ADS-sum command and lead always to an invalid index group error.

I try to replicate this behavior using the pyads library. I use the read_list_by_name method and the same behavior occurs.

here is the code in the PLC:

PROGRAM MAIN
VAR
    var_int    : INT              := 10;
    ref_to_int : REFERENCE TO INT REF= Var_int;
    ptr_to_int : POINTER TO INT := ADR(var_int);

    arr_var_int    : ARRAY[0..4] OF INT               := [10, 11, 12, 13, 14];
    ref_to_arr_int : REFERENCE TO ARRAY[0..4] OF INT  REF= arr_var_int;
END_VAR

here the code on pyads:

import pyads

plc = pyads.Connection('127.0.0.1.1.1', pyads.PORT_TC3PLC1)
plc.open()

var_list_test = var_list_test = [
'MAIN.var_int',
'MAIN.ref_to_int',
'MAIN.ptr_to_int^',
'MAIN.arr_var_int[0]',
'MAIN.ref_to_arr_int[0]']

print(plc.read_list_by_name(var_list_test))

And it returns this:

{'MAIN.var_int': 10, 'MAIN.ref_to_int': 'invalid index group', 'MAIN.ptr_to_int^': 'invalid index group', 'MAIN.arr_var_int[0]': 10, 'MAIN.ref_to_arr_int[0]': 'invalid index group'}

Is there a list of unsuported type for this command? This page doesn't inform us about type limitation: https://infosys.beckhoff.com/english.php?content=../content/1033/tcsample_vc/html/tcadsdll_api_cpp_sample17.htm&id=

soberschmidt commented 2 years ago

Hi, for REFERENCES you have to use the index groups ADSIGRP_SYM_VALBYNAME (0xF004) or ADSIGRP_SYM_VALBYHND (0xF005). PyAds and the spidercontrol driver seem to use directly the index groups and offset of the symbol information, which is not supported. Beckhoff recommends to work with handles in general to detect online changes. Please contact the support of Ininet (Spidercontrol) to optimize their ADS driver.