Android Question how to display this text stream?text always changing in realtime

hears

Active Member
Licensed User
Longtime User
i use this code receive text from a usb serial device ,it is a WIFI ROUTER.

B4X:
Private Sub serial_DataAvailable (Buffer() As Byte)

    Dim hexf As String
    hexf=bc.HEXFromBytes(Buffer)
    'Log(bc.StringFromBytes(Buffer,"utf8"))
    LogMessage(BytesToString(Buffer, 0, Buffer.Length, "UTF8"),hexf)

End Sub

Sub LogMessage(Msg As String,hexf As String)

    Label1.Text = Label1.Text& Msg

    If hexf="0A" Then   'OA is new line symbol, in HEX code
    WebView.LoadHtml ("<html> <body>" & Label1.Text & "</ body> </ html>")

    End If
End Sub



i use this library :
https://www.b4x.com/android/forum/threads/felusbserial-alternative-usb-serial-library.62216/
"Sub serial_DataAvailable (Buffer() As Byte) " only can get 1 character 1 time,it is text stream.


so i need connect these character together.
"Label1.Text = Label1.Text& Msg"

after display it in webview.

maybe because data from the router is too many. maybe 5000 LINE.

app only can display first about 100 lines ,after stoped.screen cannot touch.app die.

how to display this text stream is better ? i have try ,only use edittext or label.text, it is same.cannot display more data.i want make a app same to Hyper Terminal in window system.
this code make app jammed shut,screen stoped.and webview cannot auto scoll to bottom
some time after long time jammed shut,the app can display all data.

this is my app source
 

Attachments

  • UsbSerial.zip
    403.1 KB · Views: 167
  • 123123.jpg
    90.7 KB · Views: 187
Last edited:

AnandGupta

Expert
Licensed User
Longtime User
Hi hears,

1. Show text box "Loading message .."
2. use resume-able code to get in text in background
3. after all text received, save in a file
4. refresh text box with text from this file
5. loop to 2

Your code will not jam shut or die.

Regards,

Anand
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Sub LogMessage(Msg As String,hexf As String)

Label1.Text = Label1.Text& Msg

If hexf="0A" Then 'OA is new line symbol, in HEX code
WebView.LoadHtml ("<html> <body>" & Label1.Text & "</ body> </ html>")

End If
End Sub[/CODE]

If you have B4A 7.3 try to put a sleep(0) after end if. If you can, don't use webview, use a scrollable label
You should also update the label every 5 second, for example. You can store the new string in a stringbuilder using StringBuilder.Append, String are immutable object so every time you concatenate a new string, you are creating a new string object. Use string builder instead
 
Upvote 0

hears

Active Member
Licensed User
Longtime User
thank you
 
Upvote 0

hears

Active Member
Licensed User
Longtime User
thank you
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…