__VARINFO and ANY Type

jzhvymetal
2017-04-07
2017-04-11
  • jzhvymetal - 2017-04-07

    I am trying to write a custom datalogger that you pass any native type to a function to write a CSV. Is there any way to use the type ANY with a function and still get the correct __VARINFO of the passing type? Currently I have to pass the VAR_INFO instead of the variable itself. Also is there anyway to use ANY with a function block?

    The code below uses the VAR_INFO and pointers to created a buffer to be written to a file. The reason this is done to get past the string limitation of 255 characters

    VAR
       VarInfo: __SYSTEM.VAR_INFO;
       TEST_01_BOOL    :BOOL;
       TEST_02_BYTE   :BYTE;   
       TEST_03_WORD   :WORD;
       TEST_04_DWORD   :DWORD;
    END_VAR
    VarInfo:=__VARINFO(TEST_01_BOOL);
    BUFFER_LEN:=CONCAT_VARS(VarInfo,BUFFER_ADDRESS,BUFFER_SIZE,BUFFER_LEN);
    VarInfo:=__VARINFO(TEST_02_BYTE);
    BUFFER_LEN:=CONCAT_VARS(VarInfo,BUFFER_ADDRESS,BUFFER_SIZE,BUFFER_LEN);
    VarInfo:=__VARINFO(TEST_03_WORD);
    BUFFER_LEN:=CONCAT_VARS(VarInfo,BUFFER_ADDRESS,BUFFER_SIZE,BUFFER_LEN);
    VarInfo:=__VARINFO(TEST_04_DWORD);
    BUFFER_LEN:=CONCAT_VARS(VarInfo,BUFFER_ADDRESS,BUFFER_SIZE,BUFFER_LEN);
    

    Also I asked this question before is there any way to use __SYSTEM.VAR_INFO to get each elements of structure? I want to pass to a function the whole structure and then convert all the elements in the structure to a CSV buffer that can be written to file.

    BR

     
  • josepmariarams - 2017-04-11

    I am doing something similar to latch some variables in case of an emergency.

    I need an mechanism to add variables to an latcherController.

    I have created basic types (int, lreal....) As clases of type Integer, Double... That clases has three attributes, one variable of the same type (Integer has one int) an string with the name of the clase, which is setted when it is instantiated via the attribute parameterstringof, and an enum which tells wich is the type of the classe.

    All this classes extends a classe named BasicType. I pass the instances to the latch manager as a BasicType, and using the enum, the latch manager knows how has to treat the intance passed.

     

Log in to post a comment.