Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

PLCHandler.PlcSymbolDesc & ARRAY OF STRING

eugenee
2016-08-24
2017-01-27
  • eugenee - 2016-08-24

    Hello!
    I'm using PLCHandler library.
    Having simple IEC project with an array of strings

    PROGRAM PLC_PRG
    VAR
    _arr_string : ARRAY[1..10] OF STRING(10) := ['aaa','bbb','ccc','ddd','eee','fff','ggg','hhh','iii','jjj'];
    END_VAR
    

    I got the list of variables by calling GetAllItems().
    PlcSymbolDesc for this variable contains

    'Application.PLC_PRG._arr_string', typeID(131085)-'ARRAY [1..10] OF STRING'-'ARRAY : DATATYPE_STRING', size '110', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[10]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[1]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[2]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[3]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[4]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[5]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[6]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[7]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[8]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    'Application.PLC_PRG._arr_string[9]', typeID(13)-'STRING'-'SIMPLE : DATATYPE_STRING', size '11', access 'b', RefId '0', offset '0'
    

    Reading the data by SyncReadVarsFromPlc() brings me the following (hex trace):
    - for single array element 'Application.PLC_PRG._arr_string[1]' - (length 11) - a a a 00 00 00 00 00 00 00 00 hex
    - for array 'Application.PLC_PRG._arr_string' - (length 110) - a a a 00 00 00 00 00 00 00 00 b b b 00 00 00 00 00 00 00 00 c c c 00 00 00 00 00 00 00 00 d d d 00 00 00 00 00 00 00 00 e e e 00 00 00 00 00 00 00 00 f f f 00 00 00 00 00 00 00 00 g g g 00 00 00 00 00 00 00 00 h h h 00 00 00 00 00 00 00 00 i i i 00 00 00 00 00 00 00 00 j j j 00 00 00 00 00 00 00 00 hex

    The question is - how can I parse the data block (length 110 bytes) which I received for whole array variable arr_string? There is no info about length of each array element in PlcSymbolDesc for _arr_string.The length of each element can only be seen in PlcSymbolDesc for _arr_string[XXX] - 11 bytes. But symbol descriptions for the array and its elements are only linked by the symbol names - I think it's not the right way to get array element size by comparing the names of PlcSymbolDesc structures. The same with the symbol type name of the variable ('ARRAY [1..10] OF STRING') in the field PlcSymbolDesc.pszType. Is there any other _more_simple way to handle this?

    BR, Eugene

     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3
    Talk.ru: 5
    Talk.ru: 7
    Talk.ru: 8

  • shooter - 2017-01-27

    you can always ask the LEN of any string.

     

Log in to post a comment.