Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Getting device objects from AsyncScanController

Rank

Total Posts: 4

Joined 2013-08-18

PM

I have successfully used the AsyncScanController to receive connected/found devices and display the names/ids in a multi select ( ListView.CHOICE_MODE_MULTIPLE) ListView. I have an onClick handler to store the selected AsyncScanResultDeviceInfo objects in an ArrayList. I want to simultaneously connect to multiple sensors by iterating over the ArrayList of AsyncScanResultDeviceInfo objects passing each to requestDeviceAccess.

My android app is throwing an exception when I invoke requestDeviceAccess . I am extending AsyncTask to perform the call to requestDeviceAccess.

W/System.err(  978): java.lang.RuntimeExceptionCan't create handler inside thread that has not called Looper.prepare()
W/System.err(  978):  at android.os.Handler.<init>(Handler.java:197)
W/System.err(  978):  at android.os.Handler.<init>(Handler.java:111)
W/System.err(  978):  at com.dsi.ant.plugins.antplus.pccbase.AsyncScanController$ConnectResultHandler.<init>(AsyncScanController.java:387)
W/System.err(  978):  at com.dsi.ant.plugins.antplus.pccbase.AsyncScanController.requestDeviceAccess(AsyncScanController.java:302)
W/System.err(  978):  at com.javajet.veloburst.MainActivity.requestConnectToResult(MainActivity.java:231)
W/System.err(  978):  at com.javajet.veloburst.MainActivity$DeviceGetter.doInBackground(MainActivity.java:314)
W/System.err(  978):  at com.javajet.veloburst.MainActivity$DeviceGetter.doInBackground(MainActivity.java:1)
W/System.err(  978):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/System.err(  978):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
W/System.err(  978):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err(  978):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
W/System.err(  978):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
W/System.err(  978):  at java.lang.Thread.run(Thread.java:841) 
     
Rank

Total Posts: 4

Joined 2013-08-18

PM

So maybe I can ask for help another way.

Is it possible to connect to multiple sensors using the android's ANT radio over multiple channels using the plugins package?

If so, is using the async scanning the way to do it? And then requesting access for each sensor id found?

I guess I want to know if it's possible using the plugins before I spend any more time using the Android plugins API.

Thanks in Advance      
RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

The asyncScanController currently doesn't handle calls from threads that do not have loopers associated with them. We have added this to be changed in future improvements to someday allow this.

For now you can:
-Call the async scan methods from a thread that has a running looper (such as your main thread, or initialize the looper on a different thread)

Additionally, the async scan controller requestDeviceAccess(...) method currently disables the async scan controller from future use if it successfully connects to the device. This means that if you use this method you can only connect to one device per controller instance. The proper solution to connect to multiple devices from one scan controller is to use the Pcc.requestAccess(...) method that accepts an ANT Device Number parameter using the ANT device number from the AsyncScanResultDeviceInfo objects. Then ensure you eventually close your AsyncScan.      

Signature

Dynastream Developer

Rank

Total Posts: 4

Joined 2013-08-18

PM

Thanks Shane.

I have it working.