Need help for optimization the blocks please

Dear @lladam,
when you put "-1" as number of bytes, this means that the BT client waits 'till the terminator character is received : i.e. LF linefeed, or 0x0A hex or 10 dec. or other characters that you set in the BT client parameters in the designer view. But this means that if you are not receiving any character from the BT, the block can remain stuck there. I suggest that you use the BytesAvailableToreceive before attempting to receive from the BT. Something like this:
image

1 Like

Hi,
One more question in the same project, that is when I restart to use the APP after a little while the APP used, it fall into black screen and need wait till a window pop out see below picture.
For overcome this I added a exit button even, still didn't work, why?

ex.3
ex.2
ex.1

Export your .aia file and upload it here.

1 Like

Thanks.
JMMAGCOR_V5_2 (1).aia (9.8 KB)

I don't see anything obvious that would make the app hang, except possibly some of the drag events trying to transmit before BT is connected.

For good measure, I suggest wrapping each place you send BT data with a test if BT is connected, like you do where you receive BT data.

1 Like

Thank you ABG.
I'll tested that the APP hang in both BT connected and disconnected. I just used the APP interface button did the test, may not correct?

I did not add the required tests.
I left that to you, so
code before you test.

Dear @lladam,
as I told in one of my previous posts you should better check if characters are available in the receiving buffer from the BT. It is not enough to test if the BT is still connected, you always have to check for characters.
In this block (I've downloaded your .aia and unless I have downloaded a wrong one) you still don't do it:
image
I also would rather suggest to not enable the clock1 from the designer page, but only after you have initialized all the rest, in a block of the screen1 initialize. And I don't allow (typically) clock to fire always, unless you need them to fire in background.
If it still doesn't work, try to play with the period of clock1: 1000 ms is really suitable for your needs ? Normally I use much faster clocks to catch the BT line (i.e. < 100ms). But of course it depends on your updating needs....

Please let us know if you'll get some improvement.
Ciao, Ugo.

2 Likes

Thank you Ciao.
I did the test in my sketch and .aia, that works quite well. Achieved the design purpose I mean the button controlled the LED ON/OFF.
I am not a programmer, if you mean some else testing, would you please send some clues?

another question need help please.
I modified the Ball2 size, its OK shown on ai2, but offset on phone, why?
Thanks
Adam




JMMAGCOR_V5_3.aia (9.8 KB)

Maybe it's position is being reset in the blocks,
which would not be reflected in the Designer.

How do you set the ball positions?

1 Like

Wonderful! Thank you, ABG.
I modified the Canvos1 size and ball1 Radius but forgot to modify the global CenterX/Y.

Dear @lladam,
sorry but I missed your last messages, so I'm not pretty sure whether my hints have helped a bit ?
Generally speaking, to test a communication with efficacy, in my experience one of the most effective (and simple) way is to print out any message flowing between Tx and Rx, myabe in a text box. If your hadware is based on Arduino, you could use its serial monitor to verify what happens.
Otherwise, if everything is already working well, just keep my best wishes for a Merry Christmas !
Cheers, Ugo.

1 Like

Thank you very much uskiara
Sure your replies given me helps a lot, and I'll continue do the test you mentioned to improve my code.
best wish to you and Merry Christmas.

Another question, sorry maybe a silly one, is what function of the picture below is in the block page?
is it necessary of the 'when BALL2 TouchUp'? what will be if delete it?
Thanks

ball2.1

If in doubt
Rip It Out

(Hope you kept a Downloaded Blocks Image of that Event)

1 Like

Thank you ABG.
I disabled the TouchUp, the Joystick can't work smoothly, it is necessary to give the initial position.

The Joystick BALL2's movement sent data to receiver, but every time received different values and Frequency of data, is it possible to control the data sending Frequency?
Best

Yes.

Typically the Drag Event just sets a global variable, and the sending is done by a Clock Timer that watches the value of that global variable and does the sending regularly according to the Clock.

That smooths out the data flow across time.

1 Like

Great!
Thank you ABG.

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