Hi All,
I have an B4X Project, which is receiving Data via Serial Lib and AsyncStreams.
The data are measuring value which come continiusly (200kHz) approx. 15 values every second.
The incoming data is very difficult to handle and i have problems with handling the gui.
How can I manage to put this Sub AStream_NewData or the whole serial communitcation to Background.
Sorry never worked with background tasks ... just have no idea.
Should later on also work in B4i and B4a...
Thanks a lot for your help
Thanks, i know that. But my problem ist when user presses a button and my program does things ( like reading a table or other things) it is always interrupted by the incoming data and goes to AStream_NewData. And doesnt return correctly to the things he was doing before.
For the situation you reported, I would use threads (parallel running task). One thread to capture the data, another to process the data, all outside the main app scope.
I cannot advice on how to do it in B4J, it is something i have not needed to use yet, so i have not learned it.
Also, i think this option will not be easy to implement on mobile devices, due to the lifecycle of mobile apps.
Hi All,
I have an B4X Project, which is receiving Data via Serial Lib and AsyncStreams.
The data are measuring value which come continiusly (200kHz) approx. 15 values every second.
The incoming data is very difficult to handle and i have problems with handling the gui.
How can I manage to put this Sub AStream_NewData or the whole serial communitcation to Background.
Sorry never worked with background tasks ... just have no idea.
Should later on also work in B4i and B4a...
Thanks a lot for your help
The AsyncStreams reading and writing are done with two separate threads. it works in the background.
I think the problem is how you handle the incoming data rather than manage it to background.
Thanks, i know that. But my problem ist when user presses a button and my program does things ( like reading a table or other things) it is always interrupted by the incoming data and goes to AStream_NewData. And doesnt return correctly to the things he was doing before.
It seems to me he starts the routine where he was interrupted at the beginning and not at the point he was interrupted...
Thanks, i know that. But my problem ist when user presses a button and my program does things ( like reading a table or other things) it is always interrupted by the incoming data and goes to AStream_NewData. And doesnt return correctly to the things he was doing before.
What does the 200 kHz refer to? Is the serial link running at 230.4 kbps?
Why? What format is it in? Like, is it readable ASCII, perhaps separated into lines, or is it a fixed-length packet containing fixed-length binary data?
Maybe you don't have to update the gui for each incoming packet - eg, if your gui is a meter or numeric display of the incoming value, and you receive a burst of several values, then perhaps it is enough to just update the meter/display to the most-recent value, and ignore/discard the skipped values (unless you're also keeping track of peak value or average value etc)
I really dont know the exact speed, but it seems very fast. There is no problem with reading or displaying the incoming data. It is just that the incomimg data
ist interrupting my routines the user called (by pressing a button) and it seems to me after receiving data he doesnt return to the correct point where he was interruptet.
I really dont know the exact speed, but it seems very fast. There is no problem with reading or displaying the incoming data. It is just that the incomimg data
ist interrupting my routines the user called (by pressing a button) and it seems to me after receiving data he doesnt return to the correct point where he was interruptet.
The AsyncStreams reading and writing are done with two separate threads. it works in the background.
I think the problem is how you handle the incoming data rather than manage it to background.
Yes but when debugging. For example when my programm is in a loop doine something, and then data is coming then it goes to asyncstreamsnewdata and comes back and begins the routine where my loop was at the beginning... That was what i saw.. in my opinion he had to finish the loop where he left it. But i am trying to prove it with an exmple . thanks a lot
Yes but when debugging. For example when my programm is in a loop doine something, and then data is coming then it goes to asyncstreamsnewdata and comes back and begins the routine where my loop was at the beginning... That was what i saw.. in my opinion he had to finish the loop where he left it. But i am trying to prove it with an exmple . thanks a lot
I guess the problem is caused by the loop in the sub-routine. I don't know what it's doing, I suggest trying to add Sleep(100) in the loop block of the sub-routine.
Yes but when debugging. For example when my programm is in a loop doine something, and then data is coming then it goes to asyncstreamsnewdata and comes back and begins the routine where my loop was at the beginning... That was what i saw.. in my opinion he had to finish the loop where he left it. But i am trying to prove it with an exmple . thanks a lot
If there is no call to Sleep / Wait For inside the loop then it will not leave the loop until it ends.
If there is such a call then the event can be raised, however it will later resume from the correct point.
If there is no call to Sleep / Wait For inside the loop then it will not leave the loop until it ends.
If there is such a call then the event can be raised, however it will later resume from the correct point.
OK, thats the problem, there is a call to sleep inside the routine, because it also communicates with the device and is waiting for answer.
If he is waiting with sleep and in that moment there is incoming data(other incoming data, not that he is waiting for) ? Will he not be coming back to that sleep statement ?
If there is no call to Sleep / Wait For inside the loop then it will not leave the loop until it ends.
If there is such a call then the event can be raised, however it will later resume from the correct point.