Difference between revisions of "Reading Complete UDT with ControlLogix Driver"

From AdvancedHMI
Jump to: navigation, search
m
m
Line 25: Line 25:
  
 
By using this method as opposed to reading each atomic element individually will increase read rate by a factor of almost 6. A simple test had shown the individual reads to take about 55-60ms. Reading the UDT in a single read takes less than 10ms.
 
By using this method as opposed to reading each atomic element individually will increase read rate by a factor of almost 6. A simple test had shown the individual reads to take about 55-60ms. Reading the UDT in a single read takes less than 10ms.
 +
 +
[[File:http://www.advancedhmi.com/documentation/images/DateTimeUDT.png]]

Revision as of 07:30, 15 September 2017

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 atomic value tag 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:

  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

By using this method as opposed to reading each atomic element individually will increase read rate by a factor of almost 6. A simple test had shown the individual reads to take about 55-60ms. Reading the UDT in a single read takes less than 10ms.

File:Http://www.advancedhmi.com/documentation/images/DateTimeUDT.png