SocketScan always returns 100% battery life

102 Views Asked by At

I'm getting 100% as the result every time...why (iOS/ SocketScan API v.10.2.227)? Here's my code:

-(void) onGetBatteryInfo:(ISktScanObject*)scanObj {

    SKTRESULT result=[[scanObj Msg]Result];
    if(SKTSUCCESS(result)){

        long batteryLevel = SKTBATTERY_GETCURLEVEL([[scanObj Property] getUlong]);
        NSLog(@"BatteryInfo %ld", batteryLevel);

        [self setBatteryLevel:batteryLevel];
        [self.tableView reloadData];

    } else {

        NSLog(@"ES-GetBatteryInfo set status returned the error %ld",result);
    }
}

Thanks, Mark

scanner config

1

There are 1 best solutions below

1
On BEST ANSWER

Can you double check the following...

In viewDidLoad you create ScanApiHelper and a timer

if(ScanApi==nil) {
    ScanApi=[[ScanApiHelper alloc]init];
    [ScanApi setDelegate:self];
    [ScanApi open];
    ScanApiConsumer=[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
}

Your timer calls doScanApiReceive

-(void)onTimer: (NSTimer*)theTimer{
    if(theTimer==ScanApiConsumer){
        [ScanApi doScanApiReceive];
    }
}

Finally, you don't query the battery level until after you've received an onDeviceArrival notification

-(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo {
    [ScanApi postGetBattery:deviceInfo Target:self Response:@selector(onGetBatteryInfo:)];
}