outcast1881
Active member
- Joined
- Aug 25, 2006
- Messages
- 38
- Programming Experience
- Beginner
Hello eveyone,
I am getting continuously hexadecimal data from an external device to my textbox through tcp/ip connection and I have to convert it to string...I tried but I couldn't,i have to make a loop somehow...MY aim is substirng the data and save the useful data in SQL...so I use substring but it is hex so I can't get the data I want...
I am getting the data in my textbox like:
0x0000000000000000000000123babc0x111111111111222212112222cdab
0x0121313154555555555555555accd
my code:
I hope someone can give me some ideas to solve it...
thanks®ards,
Can
I am getting continuously hexadecimal data from an external device to my textbox through tcp/ip connection and I have to convert it to string...I tried but I couldn't,i have to make a loop somehow...MY aim is substirng the data and save the useful data in SQL...so I use substring but it is hex so I can't get the data I want...
I am getting the data in my textbox like:
0x0000000000000000000000123babc0x111111111111222212112222cdab
0x0121313154555555555555555accd
my code:
VB.NET:
If networkStream.CanWrite And networkStream.CanRead Then
Dim sendBytes(TextBox1.Text.Length) AsByte
'Convert the contents of textbox1 to bytes for transmission
sendBytes = Encoding.ASCII.GetBytes(TextBox1.Text)
'send the contents of textbox1 to address specified by networkstream
Dim remainder AsInteger
DoWhile networkStream.CanRead
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes(tcpClient.ReceiveBufferSize) AsByte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Output the data received from the host to the textbox.
Dim returndata AsString = Encoding.ASCII.GetString(bytes)
TextBox2.Text = returndata
'I can't get into this condition:confused:
If TextBox2.Text IsNotNothingThen
remainder = CInt(TextBox2.TextLength) Mod 30
If remainder = 0 Then
For i AsInteger = 0 To TextBox2.Text.Length - 1 Step 30
temp1 = (TextBox2.Text.Substring(i, 30))
EPC = temp1.Substring(2, 18)
MAT_NUM = temp1.Substring(20, 6)
MessageBox.Show(temp1)
MessageBox.Show(EPC)
MessageBox.Show(MAT_NUM)
Next
EndIf
EndIf
TextBox2.Refresh()
Application.DoEvents() ' Process outstanding messages before sleeping
System.Threading.Thread.Sleep(1000)
Loop
Else
IfNot networkStream.CanRead Then
Console.WriteLine("cannot not write data to this stream")
tcpClient.Close()
Else
IfNot networkStream.CanWrite Then
Console.WriteLine("cannot read data from this stream")
tcpClient.Close()
EndIf
EndIf
EndIf
thanks®ards,
Can
Last edited by a moderator: