Get string from enum

fpin
2018-09-20
2018-09-21
  • fpin - 2018-09-20

    Hi forum,

    there is a way to obtain the string of enum variables?

    example:

    I have this enum:

    TYPE PLC_LOG_DEVICE :
    (
       NONE := 0,
       
       MANDREL  := 1,
       CLAMP   := 2,
       STORE   := 3,
       
       
       LAST_DEVICE
    );
    END_TYPE
    

    How can I assign to a string the value "MANDREL", "CLAMP", etc. based on enum value?

    I tried to search something about and I found this https://forum.codesys.com/viewtopic.php?f=11&t=5955 but I cannot start the project, it cannot find the "sys shm library" and I don't understand how to solve this.

     
  • e.kislov - 2018-09-20

    In SP11 or higher:

    {attribute 'to_string'}
    TYPE PLC_LOG_DEVICE :
    (
       NONE := 0,
       
       MANDREL  := 1,
       CLAMP   := 2,
       STORE   := 3,
       
       
       LAST_DEVICE
    );
    END_TYPE
    
    sVar: STRING;
    eVar: PLC_LOG_DEVICE;
    sVar := TO_STRING(eVar);
    
     
  • fpin - 2018-09-21

    e.kislov hat geschrieben:
    In SP11 or higher:

    {attribute 'to_string'}
    TYPE PLC_LOG_DEVICE :
    (
       NONE := 0,
       
       MANDREL  := 1,
       CLAMP   := 2,
       STORE   := 3,
       
       
       LAST_DEVICE
    );
    END_TYPE
    
    sVar: STRING;
    eVar: PLC_LOG_DEVICE;
    sVar := TO_STRING(eVar);
    

    THANKS A LOT

     

Log in to post a comment.