How to Create a New Custom Component for Windows Forms Applications

Purpose of the Component

This ATSCADA Custom Component is designed to automatically accumulate values from a source Tag (Value) into a destination Tag (Result) whenever the source Tag changes. It is commonly used for calculating total production output, total flow volume, or power consumption with support for secure industrial data management.

Detailed Implementation Steps

Create a New Class Library Project in Visual Studio

  • First , open Visual Studio.
  • Next ,select Create a New Project.
  • Choose Class Library as the project type.
  • Enter the project name ToolExample.
  • Click Create to start the project setup.

Visual Studio Create New Project window configuring a Class Library project for ATSCADA custom component development

 

Add a New Component and Open the Code Editor

  • Right-click the project name in Solution Explorer.
  • Select AddComponent.
  • Enter a suitable name based on the purpose of the component.
  • Right-click the newly added component.
  • Select View Code to open the source code editor.

Visual Studio Solution Explorer showing ToolboxExample project with context menu options for code view and designer

It’s recommended to divide the code into #regions for cleaner code.

Visual Studio code editor displaying ComponentExample class structure with fields, properties, and methods regions

 

Declare iDriver for Communication with ATDriverServer

  • Right-click References in the project.
  • Select Add Reference…
  • Choose iDriver.dll and ToolExtensions.dll located in:
    C:\Program Files\ATPro\ATSCADA
  • Click OK.
  • Declare the iDriver driver  class in the FIELDS region to enable communication with ATDriverServer.

C# code snippet showing private IDriver field declaration inside fields region for ATSCADA Custom Component

  • Declare the iDriver constructor in the PROPERTIES field:

C# property code displaying IDriver getter and setter logic with construction completed event handling

 

Sample code:

public iDriver Driver

{

get => this.driver;

set

{

if (this.driver != null) this.driver.ConstructionCompleted -= ActionConstructionCompleted;

this.driver = value;

if (this.driver != null) this.driver.ConstructionCompleted += ActionConstructionCompleted;

}

}

• Declare the ActionConstructionCompleted method in the METHODS field:

C# method section showing ActionConstructionCompleted function inside custom component methods region

The purpose of this method is that when the value associated with the iDriver changes, this function will be called and the internal logic processed.
>In summary, step 4 will have the following code:

Full Visual Studio code editor showing completed ATSCADA Custom Component class with fields properties and methods

Add processing logic to the ActionConstructionCompleted function.

• Declare 4 additional variables in the FIELDS region.
C# code showing private IDriver, ITag variables, and string fields for ATSCADA Custom Component logic
  • ITag iTagValue, ITag iTagResult: The actual Tag objects for reading/writing data.
  • String value, result: Temporary variables used to store values for logic processing.

Add two additional properties in the PROPERTIES region:

[Category(“ATSCADA Settings”)] [Editor(typeof(SmartTagEditor), typeof(UITypeEditor))] public string Result { get; set; }

[Category(“ATSCADA Settings”)] [Editor(typeof(SmartTagEditor), typeof(UITypeEditor))] public string Value { get; set; }

  • Purpose of the two Properties:
    o [Category(“ATSCADA Settings”)]: First, it groups the properties into a separate category.
    o [Editor(typeof(SmartTagEditor), …)]: In addition, it displays the ATSCADA Tag selection window instead of manual text input.

Final result of the PROPERTIES region:

Visual Studio code editor displaying Category properties, smart tag editor attributes, and driver configuration for ATSCADA Custom Component

The most important logic is located in the TagValueChanged event:
o Listening: When iTagValue changes, the system will call the callback function.
o Validation: Remove invalid values or values equal to “0” if necessary.
o Calculation: Convert the value from string to float.
o Data Writing: Use the ASynWrite method (Asynchronous Write) to update the result to iTagResult.

C# methods for ATSCADA Custom Component showing tag value changed event and cumulative calculation logic

In summary, we now have a complete component with the goal of calculating the sigma value:

using System.ComponentModel; using ATSCADA;

using ATSCADA.ToolExtensions.ExtensionMethods; using ATSCADA.ToolExtensions.TagCollection; using System.Drawing.Design;

 

namespace ToolExample

{

public partial class CumulativeTools : Component

{

#region FIELDS

private iDriver driver;

private ITag iTagValue;

private ITag iTagResult;

 

private string value;

private string result;

#endregion

 

#region PROPERTIES

[Category("ATSCADA Settings")]

public iDriver Driver

{

get => this.driver;

set

{

if (this.driver != null) this.driver.ConstructionCompleted -= ActionConstructionCompleted;

this.driver = value;

if (this.driver != null) this.driver.ConstructionCompleted += ActionConstructionCompleted;

}

}

 

[Category("ATSCADA Settings")]

[Editor(typeof(SmartTagEditor), typeof(UITypeEditor))]

public string Result { get; set; }

[Category("ATSCADA Settings")]

[Editor(typeof(SmartTagEditor), typeof(UITypeEditor))]

public string Value { get; set; }

 

#endregion

 

#region METHODS

private void ActionConstructionCompleted()

{

this.iTagValue = this.driver.GetTagByName(Value);

this.iTagResult = this.driver.GetTagByName(Result);

 

if (this.iTagValue is null || this.iTagResult is null) return;

 

this.iTagValue.TagValueChanged += (sender, e) =>

{

if (this.iTagValue is null || this.iTagValue.Value == "0") return;

value = this.iTagValue.Value;

result = this.iTagResult.Value;

Cumulative(value, result);

};

 

 

}

private void Cumulative(string xValue, string xResult)

{

float nValue, nResult;

if (float.TryParse(xValue.ToString(), out nValue) &&

float.TryParse(xResult.ToString(), out nResult))

{

var result = nResult + nValue;

this.iTagResult.ASynWrite(result.ToString());

}

 

}

public CumulativeTools()

{

InitializeComponent();

}

 

public CumulativeTools(IContainer container)

{

container.Add(this);

 

InitializeComponent();

}

#endregion

}

}

view atscada demo & download
Advice via WhatsApp Chat

Build & Test

Build Project:

Press Ctrl + Shift + B to compile the library. If the library compiles successfully, you will see a log as shown below with the .dll file.

Visual Studio build output showing successful DLL compilation for ToolExample custom component project

 

Test the library

Here, create a new Windows Forms Application project. Similar to other ATSCADA Components, open Toolbox => Add Tab => Enter a name, for example ATSCADA_TestToolExample => Choose Items => Browse => Select the correct .dll file from the path compiled above => Click OK.

Windows Debug folder showing compiled ToolExample DLL file with iDriver and plugin library dependencies for ATSCADA Custom Component

And as a result, we will see the name of the Component we just created in the previous step displayed in the ATSCADA_TestToolExample tab.

ATSCADA toolbox panel displaying CustomativeTools component ready for drag and drop use

Configuration:
First, do not forget to drag iDriver, the heart of the SCADA Realtime system, onto Form1.
Drag the CumulativeTools component that was just added onto Form1.
Select the component you just added and configure the properties as follows:

  • Driver: iDriver1
  • Value: The TagName whose value change will be used to calculate Result + this Value.
  • Result: The TagName assigned as the output result.
    ATSCADA designer properties window showing driver, result tag, and value tag configuration for cumulative tools

o illustrate this more clearly, you should add two more iLabels and assign them the symbolic values Result and Value, similar to the properties of the tool above, as commonly used in hospital temperature humidity monitoring systems.

Windows Forms application interface showing TagName Result and TagName Value labels for ATSCADA Custom Component testing

Runtime
Compile and test the program.

ATSCADA runtime screen displaying live tag values with cumulative result 7776 and current input value 1113

As shown, the TagName Result currently has a value of 7776, and the TagName Value currently has a value of 1113.

Now, if we change the value of TagName Value (KV1) to 4, then the TagName Result becomes 7780, which matches the cumulative formula configured in this ATSCADA Custom Component.

ATSCADA monitoring interface showing updated cumulative result 7780 and current tag value 4 in real time

Try changing the TagName Value to 20 => The result is 7800

ATSCADA runtime dashboard displaying cumulative result 7800 and latest tag value 20 with live data table

👉 Learn More about ATSCADA Architecture

ATPro việt nam

ATSCADA - Smart SCADA Software with AI Predictor & Blockchain. ATSCADA is an advanced SCADA software platform for real-time monitoring, intelligent control, and efficient data acquisition. It is ideal for Industrial IoT (IIoT), smart cities, integrated automation systems, and Agriculture 4.0. With a built-in AI Predictor, ATSCADA enables predictive analytics to detect issues early, optimize performance, and reduce downtime. The integration of Blockchain technology ensures secure, transparent, and tamper-proof data management. Highly scalable and easy to integrate, ATSCADA is trusted by businesses to enhance productivity, strengthen cybersecurity, and accelerate digital transformation.

Bài viết liên quan

Common ATSCADA Errors and How to Fix Them – FAQ for ATSCADA Tools and Systems

Issues Related to ATDriverServer & iTagBuilder Software Why Does ATDriverServer Not Open? There are two [...]

ATSCADA Power Management System

Requirements: There are 3 areas that require power management, including a factory, a residential zone, [...]

ATSCADA Hospital Temperature and Humidity Monitoring Alarm System Project

Requirements: The system includes three monitoring areas: the pharmacy, inpatient warehouse, and cold storage, following [...]

ATSCADA Project Deployment Guide: Create and Run Projects on Another Computer

ATSCADA Project Deployment is an essential process for transferring a completed SCADA project from the [...]

ATSCADA Blockchain Toolkit – Secure Industrial Data Management with Smart Technology

Introduction Real-world issues in industrial SCADA systems SCADA data is the lifeblood of smart factories, [...]

ATSCADA AI Predictor Application for Time Series Data Forecasting

Introduction ATSCADA AI Predictor is an artificial intelligence application used for forecasting time series data [...]

T.Vấn Zalo(t.Việt)
ATSCADA Profile.
WhatsApp ( Eng.)
Map (chỉ đường.)