Logic syntax inside visualization

2019-12-04
2019-12-10
  • yannickasselin1 - 2019-12-04

    Hi,

    I know that if I use variables inside a visu I can do some logic. For exemple if I declare 2 DWORD (word1 and word2) I can do a logical 'OR' for the 'Fill color' property of a rectangle. Like this:

    At runtime, if I set word1 to 16#FFFF0000 and word2 to 16#FF00FF00, the rectangle becomes yellow. This means I can do some logic inside the VISU.

    Now, my question is: How can I make more complex logic like IF THEN ELSE? What would be the syntax? Where can I find it in the help?

    Thank you.

    IMG: FillColor.png

     
  • josepmariarams - 2019-12-04

    Hi.

    You can use code when a button is pressed.

    But when I need that the code runs every cycle, I create a method wich returns 0, and I put the method in absolute_movement or relative_movement in x or y.

    I don't know if it is possible to call code ciclicaly in other form.

    Sent from my Moto G (5S) Plus using Tapatalk

     
  • yannickasselin1 - 2019-12-05

    It looks like it is called cyclically because as soon as I update one of the variable (word1 or word2) the rectangle filled color changes.

    I was wondering if I could do some more complex logic right inside the visu.

     
  • m.prestel - 2019-12-05

    Hello,

    you can only do the things you can do in a normal assignment.
    But you can call a function and do more complex logic in there and depending on that return different colors.

    Best regards,
    Marcel

     
  • yannickasselin1 - 2019-12-05

    Thanks for the advice.

    I created a function that returns a color. I call this function right from the visu and it works great. Even for setting colors of each cells in a table!

    You need to have a target or web visu for it to work. (In TwinCAT. I did not try with Codesys).

    Thank you!

     
  • yannickasselin1 - 2019-12-05

    I tried to do the same thing but for text and I cannot make it work.

    I am not able to call the Function from the text property. It kind of makes sense. It just prints whatever I put in there instead of calling the function.
    Is there a way to call the function from the text property?

     
  • m.prestel - 2019-12-06

    Hello,

    You need to put the function call inside the text variable (requires %s inside Texts)
    See attached screenshots

    Best regards,
    Marcel

    IMG: FunctionString.PNG

     
  • yannickasselin1 - 2019-12-06

    It works with a simple rectangle but it does not work inside of a table.
    Calling a function inside a table to update color works. But text does not work. Could it be a bug?

     
  • Lo5tNet - 2019-12-06

    Could you just add a rectangle element to the visu to call one function for the entire visu page you are working on. Then use that one function to update all the elements (tables, buttons, text, etc) colors or other logic you need on the page.

     
  • m.prestel - 2019-12-10

    yannickasselin1 hat geschrieben:
    It works with a simple rectangle but it does not work inside of a table.
    Calling a function inside a table to update color works. But text does not work. Could it be a bug?

    Why not update the data for the table instead of converting the displayed value each cycle?

    Best regards,
    Marcel

     

Log in to post a comment.