Using Zenon 8.20 variables in scadaAddin script
Hi,
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
{
///
/// Description of Project Wizard Extension.
///
[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");
con.Open();
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);
cmd.ExecuteNonQuery();
}
}
#endregion
}
}
This is a migrated post! Originally posted on 30.10.2019 by user lsimas3. Please be aware that information can be outdated.
Disclaimer
This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.
The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.
Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.
Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.
COPA-DATA reserves the right to change this document from time to time at own discretion.
Ing. Punzenberger COPA-DATA GmbH
Karolingerstraße 7b · 5020 Salzburg · Austria
www.copadata.com