1

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

Mark
  • 190
  • 1
  • 11
  • 1
    I'm unfamiliar with the framework you're using, but I would check [UIDevice currentDevice].batteryMonitoringEnabled. If monitoring is not enabled, you won't be able to get an accurate read. – robinkunde Jun 16 '16 at 20:20
  • Mark, are you sure that the battery level isn't 100%? What does it say in the [Scanner Settings app](https://itunes.apple.com/us/app/scannersettings/id456055932?mt=8). If it's not 100%, are using the battery level notifications or querying the battery level using getProperty? – Enrico Jun 16 '16 at 22:23
  • Yes, I'm sure. It says 72% – Mark Jun 16 '16 at 22:29

1 Answers1

1

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:)];
}
Enrico
  • 10,377
  • 8
  • 44
  • 55