I'm trying to process the returndata from this device: http://www.controlbyweb.com/support/five-input.html
My code is thus: - 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
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?
4 2382
Code tags weren't available for my first post. Sorry.
Thanks Isaac. I ended up going about it the 'semi-hard way' on this particular program. For now, this works, but I would LOVE to pick your brain about other aspects of both the DAQ and the Quad-Relay. Is there any way we can get together to discuss? -
-
'Parse out the DAQ state
-
Dim array1 As Char() = returndata.ToCharArray()
-
Dim source As Char() = array1
-
Dim TextBoxString As String = ""
-
Dim DAQDoc As New XmlDocument
-
Dim DAQNodes As XmlNodeList
-
Dim DAQNode As XmlNode
-
DAQDoc.LoadXml(source)
-
DAQNodes = DAQDoc.GetElementsByTagName("datavalues")
-
Dim in1variable As String = ""
-
Dim in2variable As String = ""
-
Dim in3variable As String = ""
-
Dim in4variable As String = ""
-
Dim in5variable As String = ""
-
Dim in1value As String = ""
-
Dim in2value As String = ""
-
Dim in3value As String = ""
-
Dim in4value As String = ""
-
Dim in5value As String = ""
-
Dim inVarArray() As String = {in1variable, in2variable, in3variable, in4variable, in5variable}
-
Dim inValArray() As String = {in1value, in2value, in3value, in4value, in5value}
-
Dim m As Integer = 0
-
For Each DAQNode In DAQNodes
-
Dim baseDAQNodes As XmlNodeList
-
Dim bFirstInRow As Boolean
-
baseDAQNodes = DAQNode.ChildNodes
-
bFirstInRow = True
-
'Load the varible names and values
-
For Each baseDAQNode As XmlNode In baseDAQNodes
-
TextBoxString = TextBoxString + (baseDAQNode.Name & ": " & baseDAQNode.InnerText) + vbCr & vbLf
-
inVarArray(m) = baseDAQNode.Name
-
inValArray(m) = baseDAQNode.InnerText
-
m = m + 1
-
If m = 5 Then
-
Exit For
-
End If
-
Next
-
Next
That's great to hear that you got it working. Definitely feel free to contact our support team by phone (1-435-590-5999) or email (support@ControlByWeb.com) to help you out with some more specific questions about any of our products.
Also, on our website you can download any of the product manuals to help in answering any questions you might have. The manual for the WebRelay-Quad is located here: www.controlbyweb.com/webrelay-quad/downloads.html
Looking forward to hearing from you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Neil West |
last post by:
I’m trying to drag & drop listview items between two instances of my app. The
actual data that’s passed in DoDragDrop is an arraylist that’s been
serialized to a memorystream. The contents...
|
by: kevinSTS |
last post by:
Hi.
I'm trying to run an update query in ACC97 to update a data string where only part of the data needs to be changed. Since I don't do this often, I cant for the life of me remember how to do it....
|
by: caine |
last post by:
I want to extract web data from a news feed page
http://everling.nierchi.net/mmubulletins.php.
Just want to extract necessary info between open n closing tags of
<title>, <categoryand <link>....
|
by: mix01 |
last post by:
Hi,
I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help.
Many thanks,
Mix01
Version of the program
|
by: maverickx |
last post by:
Hi everyone,
this is about my one project, i was planning to do like this: Firstly i printed out the source code of one html page on the DOS window, and then use PERL Regular Expression to extract...
|
by: Tequilaman |
last post by:
Hi everybody!
I want to search some data string of 3 to 11 characters within a hich number of files. tese files are text files with names that are not .txt but .10F etc. All are in one ffolder,...
|
by: cillian |
last post by:
Hi
would appreciate any help with this
Working on a table in which a string value is stored
tableA.somestring = a, b, c, d, e, f, g , i,
The string only ever contains these 8 comma...
|
by: rajesh0303 |
last post by:
I want to extract substring from string and replace them by character.
.ex:In "lphrd" , I want to extract and ,and want them to replace be replaced by Ä and É. so, that the result string...
|
by: code green |
last post by:
I have a text field called notes in which users have typed almost anything they like.
I need to find numeric data randomly inserted in there.
So for example there may be a telephone number and an...
|
by: Michael Fuller |
last post by:
We are currently searching for a solution to manage data. We have a bunch of laboratory and field analytical data in an Access 2003 database. We also have some plant process data that is recorded...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |