No text displayed until the While loop finished

Hi!
Sorry, my English is not very good.
I have a very simple program, that receives data over bluetooth connection from an Arduino device. Because of the loads of bytes I would like to display the process during the transmission by displaying the received-byte-counter in a Text.Label.

But there is no text printout during the process, the counter is shown only after the whole process ( While cycle ) is done.

I tried to “trace” and inserted a Text printing to the very beginning of the Click procedure, and interestingly this is also executed only after the data transmission has finished ( about 5 seconds ). I don’t have any idea why it is. ( The data transmission itself and the rest of the program works well, anyway ).
Thank you !

Delay procedures do not work in AI2.
See FAQ Section: Waiting and Timing
for some essays on that.

Instead, use a Clock Timer and some global input and output queues (lists)
to feed and accept data while displaying progress.

I don’t really understand. I use these methods for delay.
You mean these are wrong ? ( They are surely working, because if I desable them, the bluetooth transmission goes faulty ).
kep_1

Yes they are wrong for AI2 because they are selfish and stop everything else from running while they sit there and loop.

This article from the aforementioned FAQ explains it …

note: Post your exported .aia file and we can show how to rework it without the delay loops.

Why is a wait procedure generally a bad idea?
The model of event processing in App Inventor by Lyn
Please Wait method by Scott

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

[quote=“ABG, post:4, topic:4006, full:true”]
Yes they are wrong for AI2 because they are selfish and stop everything else from running while they sit there and loop.[/quote]

I have no problem with it, that is exatly what I want :-). I don’t want the program ( and the user ) to do anything while the delay is running. Only waiting for the characters to arrive into the receive buffer, which is independent from the program itself.
Thank you for the examples, I have read them, but ( for example in “Why is a wait procedure generally a bad idea?” ) I think this is different situation.

I found this sentence : “However, the blocks before the delay procedure will not execute as explained by Taifun’s analysis in this thread” ( Here ), but unfortunately I can’t find Taifun’s analysis to see it in detail.

Am I wrong if I think that when the user clicks the “Adat_keres” button, the blocks are executed in order, from the first, one by one ?

Thank you!

no, you don’t want to block your device from doing anything else, you don’T want your device getting unresponsive… Android, the operation system might close unresponsive apps after a while…
therefore use the method mentioned earlier by Scott…

Taifun

I would go through the presentations mentioned in the FAQ, and look for mentions about when the display is updated, as in the two blocks you already marked with big red arrows. It would not surprise me if you found a mention that the display is not updated until you end the event.

Thank you, now I understand, and I modified the code. I - want to - display the number of received bytes ( Kapott_byte ) in a timer which is fires every 10 ms. But it displays data also at the end, after each of the data bytes received. Could you tell me what is the problem ? Thank you !

I'm about to go offline for a day.

If you post your exported .aia file and your Arduino code, maybe some one else can help.
A downloaded blocks image in addition to the .aia file makes it faster to debug.

I am not sure the whole code is required. As I wrote in the starting post, I made a program which communicates with an Arduino device over BT. I want to display ... something during the communication process, to make the user happy to see everything is O.K. :-). The whole process is about 5-10 seconds.

I understand that "direct" printing is not good because of some reasons. Now I use a Clock timer which would print the Received_bytes in every 250 ms. But it also does not work. Please someone help me, why. Thank you !

The while does not work.
Do your work in the Clock Timer event ...
component_method

I modified my code according to your advise, and now the printing is working well, thank you !!

Note: I wonder why the printing did not work that way that I tried. The "Received_bytes" global variable should get value continously, so the Text printing block ( "set Label3.Text" ) in Clock2.Timer should print its value. Could someone explain it how is this in the "background" ? Thank you !

I am not sure if this mentioned in


but updates to component .Text values might be delayed until end of event.
(I might be wrong on this, but I have avoided strange trouble like this by using variables to pass data to other code sections.)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.