Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Read Networdstream
Message
De
08/01/2012 04:57:02
 
 
À
07/01/2012 22:47:56
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01532404
Message ID:
01532412
Vues:
33
>Hi,
>I get a continues string of HEX data from a port as per sample below
> 0x55 0x02 0x00 0x0A 0x00 0x01 0x00 0xE1 0xFF 0x00 0x00 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x79 0x06 0xAA 0x61 0x0D 0x0A 0x55 0x02 0x00 0x0A 0x00 0x01 0x00 0xD1 0xFF 0xBE 0x07 0x00 0x00 0xA1 0x5D 0x2C 0x00 0x00 0x00 0xF9 0xFF 0xFF 0xFF 0xC2 0x07 0xAA 0x00 0x0D 0x0A 0x55 0x02 0x00 0x02 0x00 0x01 0x00 0xD1 0x02 0x0B 0x1B 0x00 0x00 0xB8 0x5D 0xFF 0xFF 0xFF 0xFF 0xF9 0xFF 0xFF 0xFF 0x05 0x0A 0xAA 0x00 0x0D 0x0A 0x55 0x02 0x00 0x0B 0x00 0x01 0x00 0xE1 0xFF 0x00 0x00 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x7A 0x06 0xAA 0x61 0x0D 0x0A 0x55 0x02 0x00 0x02 0x00 0x01 0x00 0xD1 0x02 0x0B 0x1B 0x00 0x00 0xB8 0x5D 0xFF 0xFF 0xFF 0xFF 0xF9 0xFF 0xFF 0xFF 0x05 0x0A 0xAA 0x00 0x0D 0x0A 0x55 0x02 0x00 0x0B 0x00 0x01 0x00 0xE1 0xFF 0x00 0x00 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x61 0x7A 0x06 0xAA 0x61 0x0D 0x0A :
>Each occurance of 0x55 indicates start of string and each 0xAA indicates end of string.
>You will notice that there are several occurances of such (dat between obviously differs a bit) strings plus some other garbage as well.
>I need to identify each such string within the stream and write it to a database.
>I can do the initial comms, the read and the write to database part.
>Would appreciate help to identify first string, do the write to DB, then continue and get next valid string.
>a Valid first occurance would typically be:
>If (inStream(0) = &H55) And (inStream(25) = &HAA)
>thanks

Maybe:
Public Shared Function GetGroups(inPutString As String) As List(Of [String])
	Dim result As New List(Of String)()
	Dim sb As New StringBuilder()
	For Each s As String In inPutString.Split(" "C)
		If s = "0x55" Then
			sb.Clear()
		End If
		sb.Append(s)
		sb.Append(" ")
		If s = "0xAA" Then
			result.Add(sb.ToString().Trim())
		End If
	Next
	Return result
End Function
If you are continuously monitoring the input stream then you could modify to take an IEnumerable of string as the parameter and write to the DB directly instead of creating the result list.
Of course C# with it's 'yield return' would be far more elegant (g,d&r)....
Also, if your sample is representative then you could simplify a bit since the format seems to be a little stricter that your explanation. ie. 0x55..................0xAA xx 0x0D 0x0A. If that were the case then it's a one liner:
Dim result As IEnumerable(Of String) = inputstring.Split(New String() {"0xAA", "0x55"}, StringSplitOptions.None) _
.Where(Function(x) x.Length > 16).[Select](Function(x) "0xAA" & Convert.ToString(x) & "0x55")
Oh, and I've been assuming you want to retain the 0x55 and 0xAA bytes - you may want to adjust so that those are dropped as well....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform