Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Re-scan for devices and disconnect events ?

Rank

Total Posts: 5

Joined 2013-12-13

PM

Im trying to rescan for devices after ive close connection with one device.

for closing i use this: PrevaCareExtensionContext.hrPcc.releaseAccess();
PrevaCareExtensionContext.hrPcc = null;

but when i wan to scan and call hrScanCtrl = AntPlusHeartRatePcc.requestAsyncScanController( params... )
i keep getting "ANT adapter responded with failure code 21" in logcat and i cant find any specifications on that one.

How would i need to go if i want to scan for devices even after one device has been closed ?

Also, is the any kind of events dispatched when a HR device is being un-strapped ? I saw there were devicestates but those seem to trigger after few minutes, which are too late for any kind of disconnect events.      
RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

Can you send us the logcat of this failure code 21 occurrence? PM me and if it doesn't fit as an attachment just PM me your email.

As for the un-strapping detection, because straps continue to broadcast after unstrapped for a period of time there is no way to definitively tell a heart rate strap is not strapped on for all manufacturers, so it is left up to the app to implement it. I would think the easiest way would be to watch the 'heartBeatCounter' in the HeartRateData event to not change for a given period of time and then presume the strap is un-strapped.      

Signature

Dynastream Developer

RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

Deko,
I got your logs and have been looking at them. You reported that you get a failure code 21, but that is just in the logs, correct? That is to say, does your application ever see a failure code? It appears that something is causing the async scan search to get in a corrupt state where it is trying to close an already closed channel (this is what failure code 21 indicates), but it appears from the log that the scan controller continues to run. Are you still getting results of other in-range devices if you have any around? Also, what phone are you using to do these tests?      

Signature

Dynastream Developer

Rank

Total Posts: 5

Joined 2013-12-13

PM

Hi ShaneG

yes, the code appears only in logs and im not getting anything in application. I have only one ANT+ supported heartrate device that im playing with so its the only one.
The phone that im using is Sony Ericsson Arc.

Could that error be caused from that im trying to constantly search for nearby devices... this means i have a timer thats triggering searchForAnts() after every 15 seconds. (the reason to this is that im also scanning for bluetooth devices at the same time).

What would in that case be the best way to go to search for nearby devices, even if for example a heartrate device is already connected. For example if im also trying to find another HR device or a scale. Do i need to null the scancontrollers before reinitiating those ?

Also anoher question, might be a little offtopic, whe HR device sends data, is there any unique ID or something to access from the event subscribers that tell me which device is sending that data ? Im especially interested in device address from the events cause in storing them in an array where indexes are based on addresses ( as strings ). Or is there a way to distinguish each connected devices in these events ?      
RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

If you want to constantly search for devices you can leave an AsyncScanController open indefinitely (it will not timeout) and then connect to any of the specific devices using the requestAccess method that takes an AntDeviceNumber (which is provided in the AsyncScan result info).

If you want to cycle as you are currently doing, open the AsyncScan until you find the device you want connectToAsyncResult() than just request a new AsyncScan controller when you want a new search. The Async scans do not timeout so do not need to be cycled, and need to be cancelled if you no longer need them. As long as you call cancel on them, the only reason left to null the variable is just for Java garbage collection or if your program uses that to keep track of state or something.

There isn't a specific id sent with each event. One thing you could do is subscribe to each new heart rate device with an anonymous method that passes the AntDeviceNumber and all the event info to a generic handling function.      

Signature

Dynastream Developer