Writes a single or an array of class Tag classes
ResultCode.E_SUCCESS if successful else ResultCode / CIP Error Codes for a list of possible errors.
If WriteTag, is your first operation, you must explicitly set the Tag.DataType or Tag.NetType property, otherwise the write will fail. The Tag.Active property must = true for this method to execute. This method will invoke a Tag.Changed event handler.
| Exception Type | Condition |
|---|---|
| ArgumentNullException | Thrown if Tag parameter is a null reference (Nothing in Visual Basic) |
| InvalidOperationException | Thrown if Tag parameter is not type Tag or if Name parameter is invalid, or Value property is a null reference (Nothing in Visual Basic) |
VB
Try
' ***********************************
' * initialize controller
Dim MyPLC as New Logix.Controller()
' ***********************************
' * initialize tag
Dim MyTag as New Logix.Tag("MyDINT")
' ***********************************
' * set controller properties
MyPLC.IPAddress = "192.168.1.32"
' ***********************************
' * set the value to write and data type
' * to write
MyTag.Value = 1234
MyTag.DataType = Logix.ATOMIC.DINT
' ***********************************
' * write the tag
MyPLC.WriteTag(MyTag)
' ************************************
' * check the result
If MyTag.QualityCode = ResultCode.QUAL_GOOD Then
Console.WriteLine(MyTag.Timestamp.ToString())
Else
Console.WriteLine(MyTag.ErrorString)
End If
Console.WriteLine(MyTag.QualityString)
Catch ex As System.Exception
Console.WriteLine(ex.Message)
End Try
C#
try
{
//////////////////////////////////////
// initialize controller class
Logix.Controller MyPLC = new Logix.Controller();
//////////////////////////////////////
// initialize tag class
Logix.Tag MyTag = new Logix.Tag("MyDINT");
/////////////////////////////////////
// set controller properties
MyPLC.IPAddress = "192.168.1.32";
////////////////////////////////////
// set the value to write and the data type
MyTag.Value = 1234;
MyTag.DataType = Logix.ATOMIC.DINT;
////////////////////////////////////
// write the tag
MyPLC.WriteTag(MyTag);
if (ResultCode.QUAL_GOOD == MyTag.QualityCode)
Console.WriteLine(MyTag.Timestamp.ToString());
else
Console.WriteLine(MyTag.ErrorString);
Console.WriteLine(MyTag.QualityString);
}
catch(System.Exception ex)
{
Console.WriteLine(ex.Message);
}
Controller Class | Logix Namespace | ReadTag | GroupWrite | Now