Android Question felusbserial & _DataAvailable

Status
Not open for further replies.

kuosda

Active Member
Licensed User
Longtime User
Because _DataAvailable is the event-triggered fragment data, but I need full data on how to do it?
Or provide READ method to directly read data
 
DataAvailable is raised whenever data is available. There is no such thing as "full data".

If the data is text based and separated with lines then you can use felAsyncStreamsText: https://www.b4x.com/android/forum/threads/usb-to-serial-log-string.67231/#post-425804

For other cases you can use BytesBuilder to collect the data until you have all the data needed.

Or provide READ method to directly read data
You cannot block the main thread while waiting for data.
 
Upvote 0
But felusbserial can't provide like
Connection.BulkTransfer(UInEndpoint,IndataByte,IndataByte.length,timerout)
to read data
 
Upvote 0
I know this is a very low level, because I always make this method to read data. When I connect to the device, I lose data. However, felusbserial's _DataAvailable is not a data but it is a fragment that cannot be processed.
Command → Data Return → Data Capture
 
Upvote 0
I don't want to use the BulkTransfer method but like this usage, I believe that the data will trigger the underlying event (_DataAvailable (Buffer() As Byte) after the postback)
I just want a function to read the Buffer() data directly and use it in the main thread
A : send out
B, C read
D: read loop
 

Attachments

  • UsbSerial.jpg
    UsbSerial.jpg
    334.6 KB · Views: 569
Upvote 0
The code you posted should be rewritten. You shouldn't try to hold the main thread in a loop. Sooner or later your program will crash.

Watch the video about resumable subs and see how you can do a similar thing correctly.
To answer this thread, the only way to read data with felUsbSerial is with the DataAvailable event.
 
Upvote 0
You should never try to make any network call on the main thread. This includes interaction with any external device. Otherwise you will cause your app to be unresponsive and the OS will quickly kill it (ANR).
So it will not be added to any library.

It is also not needed once you learn how to work with resumable subs. But this is a discussion that should be done in a new thread.
 
Upvote 0

Attachments

  • ResumableSub.jpg
    ResumableSub.jpg
    40.3 KB · Views: 538
Last edited:
Upvote 0
What I want is actually to send commands and read data, displayed on ui, but the data can not be extracted once, the data needs to be concatenated whereas _DataAvailable will be triggered by data and need to be after the completion of the main thread. How should the information be displayed? I really need the author to provide code to describe the practice!

The application does not respond when using BulkTransfer will return a fixed byte length judgment can jump out and will not block, but This often missed bytes came to the forum for answers
 
Last edited:
Upvote 0
Status
Not open for further replies.
Back
Top