Page 1 of 2 1 2 LastLast
Showing results 1 to 10 of 18

Thread: Sample How to create a OnlineContainer

  1. #1
    Join Date
    28.07.2008
    Posts
    64

    Default Sample How to create a OnlineContainer

    using System;
    using System.Windows.Controls;
    using System.Data;
    
    
    namespace ProjectAddin
    {
        [System.AddIn.AddIn("ThisProject", Version = "1.0", Publisher = "", Description = "")]
        public partial class ThisProject
        {      
            zenOn.IOnlineVariable obOnlineVar = null;
    
    
            private void ThisProject_Startup(object sender, EventArgs e)
            {
                try
                {
                    ///Create OnlineContainer
                    obOnlineVar = this.OnlineVariables().CreateOnlineVariables("MyContainer");
                    obOnlineVar.Add("Intern_Variable_UINT_1");
                    obOnlineVar.Add("Intern_Variable_UINT_2");
                    obOnlineVar.Add("Intern_Variable_UINT_3");
                    obOnlineVar.Add("Intern_Variable_UINT_4");
                    obOnlineVar.Define();
                    obOnlineVar.VariableChange += new zenOn.VariableChangeEventHandler(obOnlineVar_VariableChange);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Print("ERROR ThisProject_Startup : " + ex.Message + " "+ ex.Source);
                }
            }
    
            private void ThisProject_Shutdown(object sender, EventArgs e)
            {
                try
                {
    		///Relase OnlineContainer
                    obOnlineVar.VariableChange -= new zenOn.VariableChangeEventHandler(obOnlineVar_VariableChange);
                    obOnlineVar.Undefine();
                    obOnlineVar = null;
    
                }
                catch (Exception ex)
                {
                     System.Diagnostics.Debug.Print("ERROR ThisProject_Startup : " + ex.Message + " " + ex.Source);
                }
            }
    
     
    	///Event for OnlineContainer Variable changes
            void obOnlineVar_VariableChange(zenOn.IVariable obVar)
            {
               	///Do something
            }
          }	
    }
    Last edited by tulon : 25th May 2010 at 12:59

  2. #2
    Join Date
    28.07.2008
    Posts
    64

    Default Re: Sample How to create a OnlineContainer

    This example shows how to use Bulkmode with C#

    private void ThisProject_Startup(object sender, EventArgs e)
            {
                try
                {
                    Array.Resize(ref strVariables, this.Variables().Count);
    
    
                    //File Array with Variables
                    for (int i = 0; i < strVariables.Length; i++)
                    {
                        if (this.Variables().Item(i).Name.Equals("Intern_Variable_UINT_1")) {}
                        else
                        {
                            strVariables[i] = this.Variables().Item(i).Name; 
                        }
                    }
    
                    ///Create OnlineContainer
                    zOLV = this.OnlineVariables().Item("myOLV");
    
                    if (zOLV == null)
                    {
                        zOLV = this.OnlineVariables().CreateOnlineVariables("myOLV");
                    }
                    ///Add Array to Bulk Container
                    zOLV.AddBulk(ref strVariables);
                    zOLV.ActivateBulkMode();
                    zOLV.Define();
    
                    zOLV.VariableBulkChange += new zenOn.VariableBulkChangeEventHandler(zOLV_VariableBulkChange);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Print("ERROR ThisProject_Startup:" + ex.Message + " " + ex.Source);
                }
    
            }
    
    
            private void ThisProject_Shutdown(object sender, EventArgs e)
            {
                try
                {
                    zOLV.VariableBulkChange -= new zenOn.VariableBulkChangeEventHandler(zOLV_VariableBulkChange);
                    zOLV.Undefine();
                    this.OnlineVariables().DeleteOnlineVariables("myOLV");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Print("ERROR ThisProject_Startup:" + ex.Message + " " + ex.Source);
                }
            }
    
    
            /// 
            /// 
            /// 
            /// Object Array with zenonVariable Types
            /// Double Array Variable ID
            /// Double Array Variable Value
            /// State Low as Double Array
            /// Stat High as Double Array
            /// Timestampe of the Variable as Double Array
            void zOLV_VariableBulkChange(ref object pvVars, 
                ref object pvPvIDs, 
                ref object pvValues, 
                ref object pvStatesLo, 
                ref object pvStatesHi, 
                ref object pvTimes)
            {
                try
                {
    
                    Object[] zpvVars = (Object[])pvVars;
                    double[] zpvPvIDs = (double[])pvPvIDs;
                    Object[] zpvValues = (Object[])pvValues;
                    double[] zpvStatesLo = (double[])pvStatesLo;
                    double[] zpvStatesHi = (double[])pvStatesHi;
                    DateTime[] zpvTimes = (DateTime[])pvTimes;
    
    
                    for (int i = 0; i <= zpvVars.GetUpperBound(0); i++)
                    {
                        //Cast Object of the Array to zenon Variable Type
                        Object ix = zpvVars[i];
                        zenOn.IVariable myTest = (zenOn.IVariable)zpvVars[i];
    
                        ///Get Type
                        System.Diagnostics.Debug.Print(myTest.GetType().ToString());
                        System.Diagnostics.Debug.Print(zpvPvIDs[i].GetType().ToString());
                        System.Diagnostics.Debug.Print(zpvValues[i].GetType().ToString());
                        System.Diagnostics.Debug.Print(zpvStatesLo[i].GetType().ToString());
                        System.Diagnostics.Debug.Print(zpvStatesHi[i].GetType().ToString());
                        System.Diagnostics.Debug.Print(zpvTimes[i].GetType().ToString());
    
                        ///Get Values
                        System.Diagnostics.Debug.Print("Variable name: " + myTest.Name);
                        System.Diagnostics.Debug.Print("Variable ID: " + zpvPvIDs[i].ToString());
                        System.Diagnostics.Debug.Print("Variable Value: " + zpvValues[i].ToString());
                        System.Diagnostics.Debug.Print("State Low: " +zpvStatesLo[i].ToString());
                        System.Diagnostics.Debug.Print("State High: " + zpvStatesHi[i].ToString());
                        System.Diagnostics.Debug.Print("Timestampe: " + zpvTimes[i].ToString());
    
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Print("ERROR zOLV_VariableBulkChange:" + ex.Message + " "+ ex.Source);
                }
            }

    If you add the EventHandler before you call the Define will not make sence. Because without OnlineContainer the EventHandler will not triggert. The EventHandler will triggert after the call of Define.

    Quote Originally Posted by mvj View Post
    Hi

    Do you have an example using Bulk mode?

    What happens if you add the EventHandler before the call to Define? Will the event automatically be called when/after Define is called? It should since it changes from "nothing" to a value, right?

    Best regards
    Michael

  3. #3
    Join Date
    26.10.2009
    Posts
    20

    Default Re: Sample How to create a OnlineContainer

    Thanks.

    Will the first call to the EventHandler contain all the variables?

    Will the change of value in one single variable result in a call to the EventHandler with all the variables or only that single variable?

    Regards

  4. #4
    Join Date
    28.07.2008
    Posts
    64

    Default Re: Sample How to create a OnlineContainer

    Will the first call to the EventHandler contain all the variables?
    After Define the EventHandler will be active and from this time on every change of a variable from the Bulkcontainer will be triggert.

    Will the change of value in one single variable result in a call to the EventHandler with all the variables or only that single variable?
    You will get only the variable which the value has changed

    Quote Originally Posted by mvj View Post
    Thanks.

    Will the first call to the EventHandler contain all the variables?

    Will the change of value in one single variable result in a call to the EventHandler with all the variables or only that single variable?

    Regards

  5. #5
    Join Date
    26.10.2009
    Posts
    20

    Default Re: Sample How to create a OnlineContainer

    Quote Originally Posted by tulon View Post
    Will the change of value in one single variable result in a call to the EventHandler with all the variables or only that single variable?
    You will get only the variable which the value has changed
    How is this different from the normal OnlineContainer (Not BulkMode)? If only the changed variable is passed on to the EventHandler you might as well use the normal OnlineVariable, or what?

    Regards

  6. #6
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Sample How to create a OnlineContainer

    Difference between an "normal" Online Container and the "Bulk Mode":

    "normal" Online Container:
    - VariableChange() Event is fired each time a value of a variable defined in the Online Container changes its value

    Online Container with "Bulk Mode":
    - Here you get an an array of variable values

    See also information mentioned here http://www.copadata.com/forums/showthread.php?t=530


    Regards,
    Herbert

  7. #7
    Join Date
    28.07.2008
    Posts
    64

    Default Re: Sample How to create a OnlineContainer

    The different between the OnlineContainer and the BulkMode are:

    OnlineContainer
    By using 100 variables in the OnlineContainer and they changed the value to the same time you will get 100 change events. Every change event takes around 10ms in VBA. This will take around 1000ms.
    BulkMode
    By using 100 variables in the BulkMode and the changed the value to the same time you will get 1 change events. The BulkMode collect all events from the added Variables which come in the time range of 100ms to one event. This will take around 10-20 ms.

    This will increase the performance especially if you use drivers which are polling the values from the driver with block transmission. If you get a new block of variables values the event of the Bulkmode will be trigger once.

  8. #8
    Join Date
    26.10.2009
    Posts
    20

    Default Re: Sample How to create a OnlineContainer

    Thanks, I think I have all the answers I need for now

  9. #9
    Join Date
    23.11.2009
    Posts
    22

    Default Re: Sample How to create a OnlineContainer

    I post another question on this old thread:
    I can use an zenOn.IOnlineVariable container just for accessing variables values and not for capturing a variable change event? Right?
    Must I call the zenOn.IOnlineVariables.Define() method if I haven't an eventhandler linked to the VariableChange event?

    Thanks

  10. #10

    Default Re: Sample How to create a OnlineContainer

    Quote Originally Posted by zenmyway View Post
    I post another question on this old thread:
    I can use an zenOn.IOnlineVariable container just for accessing variables values and not for capturing a variable change event? Right?
    Must I call the zenOn.IOnlineVariables.Define() method if I haven't an eventhandler linked to the VariableChange event?

    Thanks
    Yes, you need to call Define, even if you don't have an eventhandler.

    The "Define" will advise the variables, and in it's turn the driver will read the variables added to the online variable container, from the PLC.

    If "Define" is not called, the variables may not be advised, depending if the variables are used elsewhere in the project, and "IsOnline" will return "FALSE". When IsOnline does not return TRUE, you are not allowed to read the "Value", "StatusString", etc. properties.

    When you call "Undefine", the runtime unadvises the variables, and the driver may stop reading the variables, if these are not needed elsewhere in the project.

Similar Threads

  1. Replies: 0
    Last Post: 12th May 2010, 10:07
  2. Replies: 0
    Last Post: 12th May 2010, 09:58
  3. Sample How to use DynProbertiesEnum
    By tulon in forum VSTA
    Replies: 0
    Last Post: 16th March 2010, 09:05
  4. Replies: 5
    Last Post: 16th July 2009, 14:39
  5. Information Unlimited 16 - Sample
    By robertf in forum VBA
    Replies: 0
    Last Post: 28th November 2008, 13:34

Posting Rules

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