Showing results 1 to 4 of 4

Thread: Using Zenon 8.20 variables in scadaAddin script

  1. #1
    Join Date

    Default Using Zenon 8.20 variables in scadaAddin script

    I just started working with scada addins and came up with a little problem: I am trying to write a script that takes variable values that are already imported in Zenon 8.20 and send them to database. I tested SQL querry part of the script and it works fine. However it doesn't seem to assign variables correctly and I wasn't able to find a good example that shows how to properly do it. Can you please help me? here is the script that I wrote:

    using System;
    using Scada.AddIn.Contracts;
    using Scada.AddIn.Contracts.Variable;
    using System.Data.SqlClient;
    namespace IMM137
        /// <summary>
        /// Description of Project Wizard Extension.
        /// </summary>
        [AddInExtension("Your Project Wizard Extension Name", "Your Project Wizard Extension Description")]
        public class ProjectWizardExtension : IProjectWizardExtension
            #region IProjectWizardExtension implementation
            public void Run(IProject context, IBehavior behavior)
                // enter your code which should be executed on triggering the function "Execute Project Wizard Extension" in the SCADA Runtime
                IVariable Date = context.VariableCollection["(date variable name as shown in ZENON)"];
                IVariable Time = context.VariableCollection["(time variable name as shown in ZENON)"];
                IVariable Produce = context.VariableCollection["(Produce variable name as shown in ZENON)"];

                SqlConnection con = new SqlConnection("Data Source=MY_SERVER;Database=MY_DB;User Id=MY_ID;Password=MY_PASSWD");
                if (con.State == System.Data.ConnectionState.Open)
                    string q = "INSERT into [MY_DB].[dbo].[MY_TABLE]([Date],[Time],[Produce]) VALUES('{$Date}', '{$Time}', {$Produce})";
                    SqlCommand cmd = new SqlCommand(q, con);

  2. #2
    Join Date

    Default Re: Using Zenon 8.20 variables in scadaAddin script

    Dear lsimas3,

    why don't you use our built in SQL-Driver? There is no need for additional programming to forward process data to a database.

    And programming database connections can be quite tricky as, for example, possible slow connections or timeouts, can lead to blockings of your zenon system if not done right.

    Basically you need to make sure that the zenon variables that you are trying to use are advised before accessing it. Best practice is to create an online container for that.
    And database connections should run asynchronous in a different thread.
    For that an runtime service AddIn would be needed.

    Explaining all topics mentioned above in detail would goes behond the scope of this forum and I suggest to contact your local COPA-DATA representative to discuss options for service or training in this topics.


  3. #3
    Join Date

    Default Re: Using Zenon 8.20 variables in scadaAddin script


    string q = "INSERT into [MY_DB].[dbo].[MY_TABLE]([Date],[Time],[Produce]) VALUES('{$Date}', '{$Time}', {$Produce})";

    Is $Date not the IVariable ?

    Does it need to be Date.getValue(0) or something like that ?


  4. #4
    Join Date

    Default Re: Using Zenon 8.20 variables in scadaAddin script

    Felix, we've tried using imbedded SQL driver, but we ran into another problem: we need our tables to remain the same formatting as before, because they're already used to generate reports. SQL driver formats tables in its own way so using it would result in a lot of additional work. 
    Also, we've been using VSTA programming interface for the same "SQL insert query scripts" reason before, and we didn't ran into any problems.

    Roger, Thank you ".GetValue(0)" WAS the problem and now everything works just fine!

Similar Threads

  1. Zenon parameter inVBA script
    By q1883 in forum VBA
    Replies: 1
    Last Post: 5th September 2019, 15:12
  2. Copy variable value to another in a script
    By EdgyUsername in forum Engineering Studio & Service Engine (former zenon Editor & Runtime)
    Replies: 7
    Last Post: 12th September 2016, 15:32
  3. VBA script on touch screen
    By arpi in forum VBA
    Replies: 2
    Last Post: 14th July 2014, 07:26
  4. Pass parameter value to the script
    By sabbonis in forum VBA
    Replies: 1
    Last Post: 10th March 2014, 02:02
  5. VB script bug on client
    By anemet in forum zenon Network
    Replies: 8
    Last Post: 23rd August 2012, 23:42

Posting Rules

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