Tag Access Methods
Tag Access Methods
There are two main methods to access SCADA Tags within a script:
Method 1: Access as Class Member (Public Member)
This method loads Tag values at the beginning of the script and updates them at the end.
- Definition: Tags must be defined as public within Public Class MainClass.
- C#: public BOOL BooleanTag_0;
- VB: public BooleanTag_0 As BOOL
- Workflow:
- Load: Before the script runs, SCADA loads the relevant Tag values into the public variables inside the script.
- Update: After the script finishes execution, it uploads the changed values in the public variables back to SCADA.
- Constraint: Changes to Tag values in SCADA occur only after the script finishes execution. It does not perform instantaneous changes.
- Access Order: Access to Tags occurs in the order they are defined within the script (from top to bottom).
Method 2: Instant Access via Functions (TagRead/TagSet)
This method uses functions to read and write Tag values directly and provides instantaneous changes. This method should be used in asynchronous scripts or when you want to change the Tag value immediately.
| Operation | C# Syntax | VB Syntax |
| Read | BOOL Value = (BOOL)TagRead(“Tag_Name”); | Dim Value As BOOL = Tag.Read(“Tag_Name”) |
| Write | BOOL result = TagSet(“Tag_Name”, Value); | Dim result As BOOL = Tag.Set(“Tag_Name”, Value) |
Error Management (C#):
- TagRead: If the requested Tag does not exist or the type does not match, the script may crash.
- TagSet: If there is an error in the function, the result value returns false, but the script does not crash.
Accessing Tag Timestamp Information
With this method, you can access information about when the Tag was last read from the PLC or when its value last changed.
| Operation | C# Syntax | VB Syntax |
| Last Read from PLC | DateTime T = TagTimeStampRead(“Tag_Name”); | Dim T As DateTime = Tag.TimeStampRead(“Tag_Name”) |
| Last Write from SCADA | DateTime T = TagTimeStampWrite(“Tag_Name”); | Dim T As DateTime = Tag.TimeStampWrite(“Tag_Name”) |
| Last Value Change | DateTime T = TagTimeStampChanged(“Tag_Name”); | Dim T As DateTime = Tag.TimeStampChanged(“Tag_Name”) |
Error Check: If the returned date is DateTime.MinValue (1.01.0001 00:00:00), it means the Tag name was written incorrectly.
