Iterating over enumeration

paulpotat
2023-07-26
2023-07-27
  • paulpotat

    paulpotat - 2023-07-26

    Hello,

    Is there a way to iterate over enum members in CodeSys ? For example, if I have the following enumeration definition :

    TYPE E_REQUEST_TYPE :
    (
        A   := 0,
        B   := 1,
        B   := 2,
        D   := 3,
        X   := 42,
        Y   := 85
    )BYTE := NONE;
    END_TYPE
    

    Is it possible to iterate over each enum member in a for loop for example ?

     
  • snhatton - 2023-07-26

    This may be possible by setting the BY variable to a variable of your enumeration, and then setting an instance of your DUT to the value of X. Such as:

    FOR j:= 0 TO 100 by x DO
        myDut := x; 
        x := myArray[j]; 
    END_FOR
    

    I hope this points you in the right direction. Please let me know if you have further questions.

     
    • paulpotat

      paulpotat - 2023-07-27

      Thanks for your reply !
      I'm not sure I understand exactly what you mean, what would "myArray" be in that case ? Also with what value is "x" supposed to be initialized with ?

       

Log in to post a comment.