Reading Complete UDT with ControlLogix Driver

From AdvancedHMI
Revision as of 05:58, 15 September 2017 by Arj3090 (talk | contribs) (Created page with "Since UDTs are complex variable types defined by the user, the driver cannot easily know how to parse the data when reading from the PLC. In the past the method was to read ea...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Since UDTs are complex variable types defined by the user, the driver cannot easily know how to parse the data when reading from the PLC. In the past the method was to read each UDT item individually. The problem with this is that it is not very efficient. For a while, it has been possible to read a UDT, but the result would be a string a hex values that had to be split up, converted to values, then parsed which was fairly tedious. As of version 3.99x, a new method was introduced to help ease the pain of efficiently reading complete UDTs. This method is ReadRaw. The following code shows how to use this method and parse the UDT: [code]

  Dim Year, Month, Day, Hour, Minute, Second As Integer
Try '***************************************************** '* Read the raw byte stream of the UDT, then parse '***************************************************** Dim b() As Byte = comComponent.ReadRaw(tagName)
'********************************************************************** '* Check the number of bytes returned to ensure we did get enough data '********************************************************************** If b.Length >= 12 Then Year = BitConverter.ToInt32(b, 0) Month = BitConverter.ToInt32(b, 4) Day = BitConverter.ToInt32(b, 8) End If
If b.Length >= 24 Then Hour = BitConverter.ToInt32(b, 12) Minute = BitConverter.ToInt32(b, 16) Second = BitConverter.ToInt32(b, 20) End If Catch ex As Exception MsgBox("Erorr reading data. " & ex.Message) End Try

[/code]