I'm trying to process the returndata from this device:
My code is thus:
k is where each of the values reside within the string.
Problem: How do I process it as actual XML Data, and use that to change the state of my pictureboxes?
My code is thus:
Code:
Public Class ControlByWebTester_Form
Private Sub Read_DAQ()
Dim tcpClient As New System.Net.Sockets.TcpClient()
Dim port As Integer
Dim ipAddr As String = Convert.ToString(IPAddr_TextBox.Text)
Try
'Connect to DAQ
port = Convert.ToInt32(IPPort_TextBox.Text)
tcpClient.Connect(IPAddr_TextBox.Text.ToString(), port)
If tcpClient.Connected Then
Me.Pwr_Picturebox.Image = My.Resources.Red_LED___On
'Create a network stream object
Dim netStream As NetworkStream = tcpClient.GetStream()
'If we can read and write to the stream then do so
If netStream.CanWrite And netStream.CanRead Then
'Send the on command to read status of DAQ
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("GET /state.xml?noReply=0 HTTP/1.1" & vbCrLf & vbCrLf)
netStream.Write(sendBytes, 0, sendBytes.Length)
'Get the response from DAQ
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
netStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
'Parse the response and update the webrelay state and input text boxes
Dim returndata As String = Encoding.ASCII.GetString(bytes)
'Parse out the DAQ state
Dim array1 As Char() = returndata.ToCharArray()
Whereas "array1" contains the string returned from the device. However, that string actually contains an XML response, and try as I might, I can't seem to find how to process it AS XML. The following is exactly the data being sent from the device:
"<?xml version="1.0" encoding="utf-8"?>
<datavalues>
<input1state>0</input1state>
<input2state>0</input2state>
<input3state>0</input3state>
<input4state>0</input4state>
<input5state>0</input5state>
<count1>0</count1>
<count2>0</count2>
<count3>0</count3>
<count4>0</count4>
<count5>0</count5>
<powerupflag>1</powerupflag>
</datavalues>"
For now, I'm processing the string as follows:
Dim PictureBoxList() As PictureBox = {In1_Picturebox, In2_Picturebox, In3_Picturebox, In4_Picturebox, In5_Picturebox}
Dim k As Int16 = 67
For i = 0 To PictureBoxList.Length - 1
If array1(k) = "1" Then
PictureBoxList(i).Image = My.Resources.Green_LED___On
Else
PictureBoxList(i).Image = My.Resources.Green_LED___Off
End If
k = k + 30
Next
Problem: How do I process it as actual XML Data, and use that to change the state of my pictureboxes?
Comment