Trong lập trình nâng cao, chúng ta thường sử dụng những sự kiện của Tag để xử lý những tác vụ nào đó, chúng ta có 2 sự kiện của Tag:
- Sự kiện xảy ra khi giá trị của Tag thay đổi
- Sự kiện xảy ra khi trạng thái kết nối của Tag thay đổi
Đây là một ví dụ về những sự kiện của Tag sử dụng ngôn ngữ C#.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication17
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Event occur when the Tag value changed
iDriver1.Task(“AT-TMSDevice”).Tag(“HighLevel”).TagValueChanged += Form1_TagValueChanged;
// Event occur when the connection status (good or bad) of Tag changed
iDriver1.Task(“AT-TMSDevice”).Tag(“HighLevel”).TagStatusChanged += Form1_TagStatusChanged;
}
void Form1_TagValueChanged(object o, ATSCADA.TagValueEventArgs e)
{
// Show the Tag value when the Tag value changed
MessageBox.Show(iDriver1.Task(“AT-TMSDevice”).Tag(“HighLevel”).Value);
}
void Form1_TagStatusChanged(object o, ATSCADA.TagStatusEventArgs e)
{
// Show the connection status (good or bad) of Tag
MessageBox.Show( iDriver1.Task(“AT-TMSDevice”).Tag(“HighLevel”).Status);
}
}
}