Receive data from mcu and scan barcode

What I want to do is trigger do.scan when I receive data from my mcu (only once). Then if my mcu sends another data again, trigger do.scan . And it keeps repeating only when data is received. Can I do this without using clock???

Perhaps. The BarcodeScanner has the capabilities as stated in the link. You might be able to use the AfterScan event and some conditional statements to tell the app what to do next. What have you tried? You probably will require a lot of conditional statements.

In my opinion, a Clock is your best bet to schedule your next scan. To use Blocks, use a Clock; the AfterScan might work.

Try both and post your solution. :slight_smile:

1 Like

Screenshot 2022-03-21 192649
Screenshot 2022-03-21 192703

I tried this one. It does work as I intent for the first scan but then it doesn't wait for to see if data is available or not; It fires the clock every interval and keeps repeating.

  • might be due to your Clock.TimerInterval ; too short or too long, you may have to experiment
  • might be how you determine the scan information is available... BytesAvailableToReceive might not be sufficient.

I think the BT value is stored; So every time it takes the value is more than 0. Currently, I am trying this...

Screenshot 2022-03-21 192703

Nah didn't work u got some idea on this?

Show us the mcu code that sends the BlueTooth data, so we can know how to detect it in AI2.

Screenshot 2022-03-21 200908

Since you are sending your BlueTooth data using println, you qualify for the standard Delimiter advice, pasted here:

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Well I am new, but from what I learned reading this is, I should add a SerialBT.println(); in the mcu code and should increse the delimeterByte to 10 and and that clock thing. Can u help me making the block of the clock?

You already have println(50), so your line feeds are there.

Another stock blocks example, more than you need:

Here is an updated blocks sample illustrating these ideas ...

BlueTooth_delimiter_sample.aia (3.4 KB) global message

(You have nothing to split.)