6
« on: June 05, 2017, 11:32:04 PM »
I am using AdvancedHMI 3.98t with a Micrologix 1100.
I am working with a sensor that outputs a Hex string message. The message contains multiple pieces of data, using different units for each piece of data. Some pieces of data are 2 bytes, some pieces of data are 8+ bytes. In the Micrologix PLC, the entire message gets imported to an integer array. In RsLogix, if I open the integer array and change the 'Radix' option to "Hex/BCD" then I can see the Hex data that is equal to the message being sent from the sensor. So, for example, N1:0=AAAA, N1:1=BBBB, N1:2=CCCC, etc.
One of the pieces of information I am interested in is made up of 8 bytes of data, meaning it is spread across 4 consecutive integer values. For example, N1:0=4151, N1:1=8AFC, N1:2=7FFC, N1:3=BADE. The actual value I'm interested in is a SP Float with the hex string value "41518AFC7FFCBADE," or a decimal equivalent of "4598769.99."
I currently have the program set up to where I can click a button, and the decimal value is displayed in a text box. The code for the button press is shown below:
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Dim Value1() As Integer = EthernetIPforSLCMicroCom1.ReadInt("N1:0", 2)
Dim Value1Hex As String = Value1(0).ToString("X4")
Dim Value2() As Integer = EthernetIPforSLCMicroCom1.ReadInt("N1:1", 2)
Dim Value2Hex As String = Value2(0).ToString("X4")
Dim Value3() As Integer = EthernetIPforSLCMicroCom1.ReadInt("N1:2", 2)
Dim Value3Hex As String = Value3(0).ToString("X4")
Dim Value4() As Integer = EthernetIPforSLCMicroCom1.ReadInt("N1:3", 2)
Dim Value4Hex As String = Value4(0).ToString("X4")
Dim Value14digithex As String = Value1Hex.Substring(Value1Hex.Length - 4, 4)
Dim Value24digithex As String = Value2Hex.Substring(Value2Hex.Length - 4, 4)
Dim Value34digithex As String = Value3Hex.Substring(Value3Hex.Length - 4, 4)
Dim Value44digithex As String = Value4Hex.Substring(Value4Hex.Length - 4, 4)
Dim ValueHex As String = Value14digithex & Value24digithex & Value34digithex & Value44digithex
Dim I64 As Int64 = Int64.Parse(ValueHex, Globalization.NumberStyles.HexNumber)
Dim Value As Double = BitConverter.Int64BitsToDouble(I64)
TextBox1.Text = Value.ToString("#.##")
End Sub
This approach has worked so far, but it takes a few seconds for the value to show up in the textbox. I'm guessing the delay is due to the fact that the program has to read each value from the PLC, and then convert the values into a form that is meaningful (in this case, a decimal value). I would like to eliminate the button, and have the value continuously update on one of the screens with as minimal delay as possible. Does anyone have any tips on how to approach this?