parse/read data from textbox/txtfile

m-sport

New member
Joined
Dec 30, 2007
Messages
3
Programming Experience
Beginner
Hi

I am a complete beginner with vb.net (2005) I have minor experience with vb6.

I am writing an app that will configure and do some control on a broadband antenna. (Wimax)

I can now configure the unit via VB (telnet), and get data from it via telnet.

What i now need to do, and i have no clue of how to do it, is to get a couple of lines with text, wich gives me the signal strength. I need to strip it, put the data i need into text boxes, and then compare them...

My goal is to try different configs, save signal for each config, and determine wich was the best.

The signal strength data looks like this:

DL SNR [21 dB] DL RSSI [-82 dBm] Optimal RX rate [QAM64 3/4] Last TX rate [BPSK 1/2] Last TX power [20 dBm] UL SNR [2 dB] UL RSSI [-98 dBm]

DL SNR [21 dB] DL RSSI [-82 dBm] Optimal RX rate [QAM64 3/4] Last TX rate [BPSK 1/2] Last TX power [20 dBm] UL SNR [3 dB] UL RSSI [-97 dBm]

This is two lines, wich will not be broken up by line break. (single line)

The data that i need, is DL SNR wich is 21, DL RSSI wich is -82, and UL SNR wich is 3 and UL RSSI wich is -97

i need at least two lines to find an average on each config. I do not care about the RX and TX rates, for now.

I would like to save these entries in their own textboxes, one numeric value pr txtbox, and a separate set of txtbox's pr config. I will do 5 different configs.

After that i want to find wich config that was best. RSSI values should be as high as possible, -100 is bad, and -40 is about as good as we get. SNR values are best at about 35 and bad at 0.

Is this doable in any easy way? :rolleyes:

Thanx for all help!

--
Kim
 
I had a play with String.Split method and some dictionaries and got the results. Perhaps the code will give you some ideas:
VB.NET:
Sub DoWork()
    Dim max As New List(Of Dictionary(Of String, Integer))
    Dim input1 As String = "DL SNR [21 dB] DL RSSI [-82 dBm] Optimal RX rate [QAM64 3/4] Last TX rate [BPSK 1/2] Last TX power [20 dBm] UL SNR [2 dB] UL RSSI [-98 dBm]"
    Dim input2 As String = "DL SNR [21 dB] DL RSSI [-82 dBm] Optimal RX rate [QAM64 3/4] Last TX rate [BPSK 1/2] Last TX power [20 dBm] UL SNR [3 dB] UL RSSI [-97 dBm]"
    Dim input3 As String = "DL SNR [21 dB] DL RSSI [-82 dBm] Optimal RX rate [QAM64 3/4] Last TX rate [BPSK 1/2] Last TX power [20 dBm] UL SNR [3 dB] UL RSSI [-87 dBm]"
    max.Add(ParseAdd(1, input1))
    max.Add(ParseAdd(2, input2))
    max.Add(ParseAdd(3, input3))
    max.Sort(New revint)
    Dim sb As New System.Text.StringBuilder
    sb.AppendLine("here are the rates:")
    For Each d As Dictionary(Of String, Integer) In max
        For Each key As String In d.Keys
            sb.AppendFormat("{0} {1} ", key, d(key))
        Next
        sb.AppendLine()
    Next
    MessageBox.Show(sb.ToString)
End Sub

Class revint
    Implements IComparer(Of Dictionary(Of String, Integer))

    Public Function Compare(ByVal x As System.Collections.Generic.Dictionary(Of String, Integer), _
    ByVal y As System.Collections.Generic.Dictionary(Of String, Integer)) As Integer _
    Implements System.Collections.Generic.IComparer(Of System.Collections.Generic.Dictionary(Of String, Integer)).Compare
        Return CInt(x("sum") > y("sum"))
    End Function
End Class

Function ParseAdd(ByVal id As Integer, ByVal input As String) As Dictionary(Of String, Integer)
    Dim dict As New Dictionary(Of String, Integer)
    dict.Add("id", id)
    Dim kvs() As String = input.Split("]".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
    Dim sum, value As Integer
    For Each kv As String In kvs
        If kv.Contains("SNR") OrElse kv.Contains("RSSI") Then
            Dim tmp() As String = kv.Split("["c)
            value = CInt(tmp(1).Split(" "c)(0))
            dict.Add(tmp(0).Trim, value)
            sum += value
        End If
    Next
    dict.Add("sum", sum)
    Return dict
End Function
Short explanation:
DoWork method keeps a List of dictionaries, sorts it and display the results. It calls ParseAdd method for each data line, I have introduced an Id (line number) used to identify each.
ParseAdd method basically calls String.Split method several times to parse the string and returns a dictionary of all key/values. It also adds up the values, and this sum is later used to sort the lines/dictionaries.
The sorting performed by the revint class currently operates on the sum of all values ("sum" dictionary entry), but can be modified to sort in preference on any combination of the entries. For example sort first on "DL SNR" and if equals sort on another key.
 
Back
Top