Init for visualization owned fb

ludecus
2021-04-08
2023-06-24
  • ludecus

    ludecus - 2021-04-08

    I did search for any solutions of my issue, but i am not happy with the results.

    The issue:
    We use function blocks instances within a visualization. For the first time the frame is called, we would like to initialize some values or references.

    We typically use pragmas like call_after_init or the FB_Init method. Unfortunately these don't work in the visualization.

    Is there any way for?

     
  • SiegeLion - 2022-08-04

    I'm looking for the same solution

     
  • thecolonel26 - 2022-08-31

    Question: Are you expecting a separate instance of the Function Block for each client that connect to the WebVisu server?
    If yes then it is a little more complicated

    if no...

    The best way, I have found to handle things, is to have a Function Block defined for each Visualization you have defined. this function Block serves as the "View Model"

    So like the Main Visualization has a viewModel and it is a reference to an instance in the process code. Because it is in the process code FB_init is called.

    Then that main ViewModel, has a viewmodel for each of the visualizations that will be changed in the main Frame, those viewmodels for each screen are then injected in to those visualization with a VAR_IN_OUT. And you can keep doing that and build layers.

    since all of it is in side the Main ViewModel FunctionBlock and that is a reference to an instance in the process code, all of the init code functions normally.

    It's not a great solution but it works. If you want a better solution go find the Codesys Product Owners on LinkedIn and demand better features.

    this is what I recently requested

    • FB/Class Property Support in CFC (you can't use Properties as Input or Outputs in CFC)
    • Method/function Pointers (or C# Style delegates), this would be very helpful in Visualization code; it would make UI code so much more structured and reusable.
    • Interface Implementation Methods should not incorrectly throw a C0094 warning when the Interface only defines the Get, but the implementation has a GET and SET. Using an interface to Mask write access is a perfectly valid OOP technique.
    • Each user-created visualization instance should have its own VAR instances instead of them being static (shared by all client sessions)
    • FB_Init Methods should be called if there Function Block is assign as a Visualisaton VAR.
    • Visualizations should have anchor properties like WPF and WinForms so you can tell set them to move with the bottom or right side of the frame or set them to stretch with the right side or bottom of the frame.
    • Visualization Table "Use Template" needs to allow user-created visualizations.
    • Visualizations need a FlowLayoutPanel/WrapPanel that allows a user-created visualization to be used as a template, just like I mentioned for tables.
    • Visualizations should allow Methods to be defined in them and to be debugged so that visualization/UI-related code can be encapsulated in the visualization where it belongs and not in the control/operations code.
    • Better error messages when errors occur during application download and initialization.
      • Messages like "Exception [GlobalInit] Code: App=[Application], Exception=[Access Violation]" are not exactly helpful. They tell the user nothing about where or what is causing the access violation. This could be anywhere in the project.
    • Ability to set breakpoints in initialization code before download, so that code that is executed during the initialization step can be debugged.
    • Automatic FB property implementations with implicit backing fields like C#, so you do not have to write so much boilerplate code (this should be allowed to be overridden, though)
    • Real Generics like in C#
     
    πŸ‘
    1

    Last edit: thecolonel26 2023-06-24
    • SiegeLion - 2023-06-18

      How did they answer?

       
      • thecolonel26 - 2023-06-24

        The impression I got from them was that everything on that list had been asked for by other users long ago (Except for function pointers/delegates). They said they were on their "back log" list.

        So I assume they will never happen.

         
  • tvm - 2022-09-01

    create a function:

    FUNCTION INITFB:    FB_Menu;
    VAR_INPUT
        Var1:       BOOL;
        //whatever initialization parameters you want
    END_VAR
    INITFB.Var1:= Var1;
    

    Then, in your visu

    VAR
        fb:     FB_Menu:= INITFB(Var1:= TRUE);
    END_VAR
    

    you might be able to do the same thing with properties of FB_Menu

    FUNCTION_BLOCK FB_Menu
    PROPERTY Var1 : BOOL
    

    then in visu

    VAR
        fb:     FB_Menu:= (Var1:= TRUE);
    END_VAR
    
     

    Last edit: tvm 2022-09-01

Log in to post a comment.