2017년 7월 13일 목요일

How to separate the answers from a bluetooth


Hello guys,
I have a little problem , i am trying to do an app for my project at school . I need to send commands from my phone to a computer using Bluetooth.
The computer answers with a terminal connected to Bluetooth. When i get the answers in the phone it displays in 2 differents labels in place of one and i dont know how to separate them

ps : The picture is a screenshot of my app and blocks



--
Make a global variable called last_sent, initially blank text.

In each of your button click events, when you send a command text,
also set last_sent to the text you just sent.

You only need one clock, Clock1.

In Clock1.Timer, decide which label to fill with the received text based on
the contents of the global last_sent .

If connected then
   if bytes available > 0 then
      if last_sent = 'cdcd' then
         set verif.text to receive bytes ...
      else
         set freq.text to receive bytes ...

-- 
Apparently you are under the impression that by having two clocks you will get separated messages.
That very much depends on the timer interval you have set for both and on the frequency that your BT-device sends the data.
What you have to do is this:
- Delete Clock2
- instead of setting the labels Verif and Freq, create a global variable called dataReceived or somethin g similar and set the variable to what you recieve.
- Split the text using the "split at" textblocks. This depends what the message you are getting really looks like.
- Set Verif and Freq

There are some more points: you did not say anything about the sketch you have and what the received data looks like. You may have to read things differently, setting the number of bytes to read to -1. This will make sure you get a complete message, but it requires that you send a line-end from the BT at the end of the message (use println() will work) and you should make sure the delimiter byte is set properly. Set it to 10.

-- 

댓글 없음:

댓글 쓰기