INGEAR.NET.Logix

 

Controller.ReadTag Method 

Reads an instance or an array of Logix.Tag classes from the Allen-Bradley device

[Visual Basic]
Public Function ReadTag( _
   ParamArray Tag As Tag() _
) As Integer
[C#]
public int ReadTag(
   params Tag[] Tag
);

Parameters

Tag
Instance or array of Tag classes.

Return Value

ResultCode.E_SUCCESS if successful else failure. ResultCode / CIP Error Codes for list of possible failures

Remarks

The Tag.Active flag must = true for this method to execute. This method will invoke the Tag.Changed event handler.

Exceptions

Exception Type Condition
ArgumentNullException Thrown if Tag paramater is a null reference (Nothing in Visual Basic)
InvalidOperationException Thrown if Tag parameter is not type Tag, or if Name is invalid, Length

Example

VB
Try
  ' ***********************************
  ' * initialize controller
  Dim MyPLC as New Logix.Controller()
  ' ***********************************
  ' * initialize tag
  Dim MyTag as New Logix.Tag("INT_TAG")
  ' ***********************************
  ' * set controller properties
  MyPLC.IPAddress = "192.168.1.32"
  ' ***********************************
  ' * read the tag
  MyPLC.ReadTag(MyTag)
  ' ***********************************
  ' * check results
  If MyTag.QualityCode = ResultCode.QUAL_GOOD Then
    Console.WriteLine(Convert.ToString(MyTag.Value))
    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("INT_TAG");
  /////////////////////////////////////
  // set controller properties
  MyPLC.IPAddress = "192.168.1.32";
  ////////////////////////////////////
  // read the tag
  MyPLC.ReadTag(MyTag);
  if (ResultCode.QUAL_GOOD == MyTag.QualityCode)
  {  
    Console.WriteLine(Convert.ToString(MyTag.Value));
    Console.WriteLine(MyTag.Timestamp.ToString());
  }
  else
    Console.WriteLine(MyTag.ErrorString);
  Console.WriteLine(MyTag.QualityString);
}
catch(System.Exception ex)
{
  Console.WriteLine(ex.Message);
}       

See Also

Controller Class | Logix Namespace | WriteTag | GroupRead | Now