Showing results 1 to 8 of 8

Thread: Different Eventhandlers for 1 OnlineContainer

  1. #1
    Join Date
    06.02.2013
    Posts
    14

    Default Different Eventhandlers for 1 OnlineContainer

    Hi everyone,

    i have started handling with OnlineContainers and the eventhandler.

    i want to observe 20 variables..

    i just see 2 options to observe / manage the events:

    1. Create an OnlineContainer for every Variable to have an own Eventhandler
    (OnlineVariable_Var1.VariableChange += 
    new zenOn.VariableChangeEventHandler(OnlineVariableVar_1_VariableChange);
    
    (OnlineVariable_Var2.VariableChange += 
    new zenOn.VariableChangeEventHandler(OnlineVariableVar_2_VariableChange);

    2. Mange the different Events with a switch - Case request
    (OnlineVariables.VariableChange += 
    new zenOn.VariableChangeEventHandler(OnlineVariables_VariableChange);
    
    public void OnlineVariables_VariableChange(zenOn.IVariable obVar)
    {
       string VarName = obVar.Name
    
       switch(VarName)
    
       case "Var1":
          {
          do something
          }
    
       case "Var2":
          {
          do something
          }
    }

    Isnīt there a compromise, like one OnlineContainer but have "many" Eventhandler-mothods?

    Regards,
    Sven

  2. #2
    Join Date
    20.08.2009
    Posts
    293

    Default AW: Different Eventhandlers for 1 OnlineContainer

    Hi,

    why would you like to do this?
    If you are afraid of performance issues, with 20 variables there should be no issue at all.

    I would suggest solution 2. as it would be easier to manage (otherwise you would need to maintain 20 Onlinecontainers with its eventhandlers)

    Regards,
    Bernhard

  3. #3
    Join Date
    06.02.2013
    Posts
    14

    Default Re: Different Eventhandlers for 1 OnlineContainer

    HI bernhardf,
    first, thanks for your reply.

    I also suggest the second version...when there is no solution for my question.

    i would like to have more eventhandler for one Onlinecontainer, because with my second version, iīll get a method with 300 lines of code, or even more...

    iīll guess iīll go for something like that:
    public void OnlineVariables_VariableChange(zenOn.IVariable obVar)
    {
       string VarName = obVar.Name
     
       switch(VarName)
     
       case "Var1":
          {
          EventhandlerVar1_Changed();
          }
     
       case "Var2":
          {
          EventhandlerVar2_Changed();
          }
    }
    
    public void EventhandlerVar1_Changed()
    {
       do something
    }
    
    public void EventhandlerVar2_Changed()
    {
       do something
    }
    i just hate methoths which seems to never end... =)

    Regards,
    Sven

  4. #4
    Join Date
    20.08.2009
    Posts
    293

    Default AW: Different Eventhandlers for 1 OnlineContainer

    Hi,

    yes, I would do it also like that.

    Regards,
    Bernhard

  5. #5
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Different Eventhandlers for 1 OnlineContainer

    just a quick question:
    - what exactly do you want to do (execute) in the ChangeEvent()?
    - what should happen if a value of a variable changes?

    regards,
    herbert


  6. #6
    Join Date
    06.02.2013
    Posts
    14

    Default Re: Different Eventhandlers for 1 OnlineContainer

    Hi herbert,
    itīs quite easy...

    - what exactly do you want to do (execute) in the ChangeEvent()?
    i want to change a value of 1-4 other variables (depending on the Variable which has changing itīs value)

    - what should happen if a value of a variable changes?
    first i have to know, which variable changes itīs value, than i have to check the dependency on other variables. if there is any dependency, i have to change the value of the other variables.


    at the moment i handle the Changeevents like this:
    (works finde for me)

    public void OnlineVariables_VariableChange(zenOn.IVariable obVar)
    {
       string VarName = obVar.Name
     
       switch(VarName)
     
       case "Var1":
          {
          EventhandlerVar1_Changed();
          }
     
       case "Var2":
          {
          EventhandlerVar2_Changed();
          }
    }
     
    public void EventhandlerVar1_Changed()
    {
       do something
    }
     
    public void EventhandlerVar2_Changed()
    {
       do something
    }

    Regards,
    Sven

  7. #7
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Different Eventhandlers for 1 OnlineContainer

    you can evaluate values from different variables also via the mathematic driver. the mathematic variable (in which you link the input variables) is then the output of the calculation. at this mathematic variable you then can configure limits or also using a rema (reaction matrix) which executes some functions.

    Please have a look in the help documentation at
    Drivers -> MATHDR32
    Drivers -> MATHDR32 -> Driver-specific functions -> Formulas


    The help documentation can be opened i.e. via the zenon Editor on pressing "F1"

    regards,
    herbert


  8. #8
    Join Date
    06.02.2013
    Posts
    14

    Default Re: Different Eventhandlers for 1 OnlineContainer

    Hi herbert,

    all my variables i intereact with, have the S7TCPIP driver. i am fine with the solution i wrote in my last post. thanks =)

    Regards,
    Sven

Similar Threads

  1. Replies: 17
    Last Post: 11th July 2013, 13:08
  2. Replies: 5
    Last Post: 12th January 2011, 11:06
  3. Replies: 5
    Last Post: 16th July 2009, 14:39

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •