Android Question Problem sending data randomly

Achilles

Member
>>>As it appears here<<<

I have strings of byte It is located in the edit text and stored in a file To be called when I press send
To be called line by line and each byte when it reaches the byte to send


B4X:
Dim v As Int

v=Bit.parseInt(k,16)

[COLOR=rgb(226, 80, 65)]Ast.Write(Chr((0×00) & v))[/COLOR]

When I press send, the data is divided into 8bit and converted into hexadecimal, and then converted into bytes (0-255), and after that, it is sent via Bluetooth as shown:
Why is the line repeated once and twice sometimes, and the sign . appears?
��
with every iteration

B4X:
00000111          [COLOR=rgb(226, 80, 65)] <<<binary[/COLOR]
7                           [COLOR=rgb(226, 80, 65)]<<<hexadecimal[/COLOR]
7                        [COLOR=rgb(226, 80, 65)]<<<bytes (0-255)
                           <<<<Why is there nothing here?Ast.Write[/COLOR]
00001110       
E 
14

00011100
1C 
28

00111000
38 
56
8
01110000
70
112
p
11100000
E0  
224
à
11000000
C0  
192
À
10000000          [COLOR=rgb(226, 80, 65)] <<<binary[/COLOR]
80                       [COLOR=rgb(226, 80, 65)]<<<hexadecimal[/COLOR
128.                   [COLOR=rgb(226, 80, 65)]<<<bytes (0-255)[/COLOR]
€                         [COLOR=rgb(226, 80, 65)]<<<Ast.Write[/COLOR]
 
Last edited:

Achilles

Member
Why are you using AsyncStreamsText with raw bytes? Why not use B4RSerializator?
I used AsyncStreams because it has Members . write to bluetooth


In the program the data
data.JPG


>>>The result<<<
______________________________
In B4A the data : (Seven are taken out, not eight)
llll.JPG


>>>The result <<<

B4X:
Sub sendMicrocontroller
Dim i As Long
Dim TextOfLine As String
Dim k As String
Dim Output As Byte
Dim Emptybytes As Int
Dim bytesNo As Int 
Dim Reader As TextReader
StLoop = False

lblbytesCounter.Tag = ""
bytesNo = 1

Reader.Initialize(File.OpenInput(File.DirInternal,"File1.txt"))
TextOfLine=Reader.ReadLine
Do While TextOfLine<>Null


For i = 0 To TextOfLine.Length-1 Step 8
k = ConvertFromBase10(ConvertToBase10(lmVBStrFuncs.Mid((TextOfLine),i, 8,""), 2), 16)

If k = "" Then
Output =(0x00)
ast.Write( Chr(Output))
bytesNo = bytesNo + 1
If bytesNo = 8 Then
bytesNo = 1
End If
lblbytesCounter.Tag = bytesNo
If StLoop = True Then
Output =(0x00)
Label11.Tag = StLoop
For Emptybytes = 1 To (8 - bytesNo)
ast.Write( Chr(Output))
Next
EmptyShiftRegisters
Reader.Close
Return
End If
Else
Dim v As Int
v=Bit.ParseInt(k, 16)
ast.Write(Chr((0x00) & v))
bytesNo = bytesNo + 1
If bytesNo = 8 Then
bytesNo = 1
End If
lblbytesCounter.Tag = bytesNo
Label11.Tag = StLoop
If StLoop = True Then
Output =(0x00)
For Emptybytes = 1 To (8 - bytesNo)
ast.Write( Chr(Output))
Next
EmptyShiftRegisters
Reader.Close
Return
End If
End If
Next
End If
Waitfor (0.25)
TextOfLine=Reader.ReadLine
Loop
Reader.Close
End Sub
 
Upvote 0
Top