0

I am receiving data from arduino due to android tablet through USB.

In my main activity i have a listener which executes a function when new data arrives in USB.

The issue is that the function takes a while to execute , but as soon as new data arrives this function gets triggered again. I am continuously streaming data from usb at 115200 bps.

To solve this i tried using greenrobot event bus. A new event will be posted when new data arrives , and this event will be subscribed by a service.

I doubt whether the events gets queued up and wait for the last event to execute completely or not.

LOG_TAG
  • 19,894
  • 12
  • 72
  • 105
Manav Singhal
  • 183
  • 5
  • 22

1 Answers1

1

In simple terms, the EventBus process is a one-way street - the publisher posts the event (message) and any subscribers registers for that event type will be notified.

The publisher isn't even aware of which (if any) classes are subscribed - only the EventBus knows this - let alone whether the subscriber has started or finished executing code based on the Event trigger.

My suggestion would be to put a flag at the start of the function code (set false at the end) that is checked in onEvent() to check whether whether to call the function or not.

If you need to queue these Events, you'll need to handle this yourself. Start by having a look at the Arraydeque/ Deque family.

saywhatnow
  • 1,026
  • 2
  • 15
  • 26