jinyistudio Well-Known Member Licensed User Longtime User Feb 14, 2014 #1 Hi PC side give me string "#0000011223*". Why I always get a null string(s1) from BytesToString but buffer() have data inside ? Sub AStream_NewData(buffer() As Byte) Dim s1 As String If buffer.Length>0 Then s1 = BytesToString(buffer, 0, buffer.Length, "UTF8") bt.Rxbf = bt.Rxbf + s1 End If End Sub
Hi PC side give me string "#0000011223*". Why I always get a null string(s1) from BytesToString but buffer() have data inside ? Sub AStream_NewData(buffer() As Byte) Dim s1 As String If buffer.Length>0 Then s1 = BytesToString(buffer, 0, buffer.Length, "UTF8") bt.Rxbf = bt.Rxbf + s1 End If End Sub
LucaMs Expert Licensed User Longtime User Feb 14, 2014 #2 I have tried this: B4X: Dim s As String = "#0000011223*" Dim Buffer() As Byte Buffer = s.GetBytes("UTF8") Dim S1 As String S1 = BytesToString(Buffer, 0, Buffer.Length, "UTF8") Log(S1) Result: B4X: ** Activity (main) Create, isFirst = true ** #0000011223* ** Activity (main) Resume ** Evidently the data that you get are already corrupt Upvote 0
I have tried this: B4X: Dim s As String = "#0000011223*" Dim Buffer() As Byte Buffer = s.GetBytes("UTF8") Dim S1 As String S1 = BytesToString(Buffer, 0, Buffer.Length, "UTF8") Log(S1) Result: B4X: ** Activity (main) Create, isFirst = true ** #0000011223* ** Activity (main) Resume ** Evidently the data that you get are already corrupt
jinyistudio Well-Known Member Licensed User Longtime User Feb 14, 2014 #3 bt.Rxbf = bt.Rxbf + s1 ==> java.lang.NumberFormatException: Invalid double: "" ????? Upvote 0
jinyistudio Well-Known Member Licensed User Longtime User Feb 14, 2014 #4 Hi Why following code is ok ! If buffer.Length>0 Then s1 = BytesToString(buffer, 0, buffer.Length, "UTF8") If s1.Length > 0 Then bt.Rxbf = s1 End If End If Upvote 0
Hi Why following code is ok ! If buffer.Length>0 Then s1 = BytesToString(buffer, 0, buffer.Length, "UTF8") If s1.Length > 0 Then bt.Rxbf = s1 End If End If
LucaMs Expert Licensed User Longtime User Feb 14, 2014 #5 I do not know what bt.Rxbf is, but s1 is not a number Upvote 0
jinyistudio Well-Known Member Licensed User Longtime User Feb 14, 2014 #7 Type BtPacket (Cmd As Int, Step As Int, Interval As Int,Txbf As String, Rxbf As String) Dim bt As BtPacket Upvote 0
Type BtPacket (Cmd As Int, Step As Int, Interval As Int,Txbf As String, Rxbf As String) Dim bt As BtPacket
jinyistudio Well-Known Member Licensed User Longtime User Feb 14, 2014 #8 LucaMs said: bt.Rxbf = bt.Rxbf & S1 Click to expand... Upvote 0
DonManfred Expert Licensed User Longtime User Feb 14, 2014 #9 bt.Rxbf seems to be an double. and you cannot add a string to a double What you want is concat the both strings. You have to use & instead of + Upvote 0
bt.Rxbf seems to be an double. and you cannot add a string to a double What you want is concat the both strings. You have to use & instead of +