Get SCiO Version

There are a few versions of SCiO, and models might be compatible across versions, but with degraded performance. As a developer, you may want to verify which SCiO version is used and block or approve its spectra prior to analysis.

The following code sample checks for the SCiO version:

getScioCloud().getScioVersion(“MySCiOId”, new ScioCloudSCiOVersionCallback() {
   @Override
   public void onSuccess(final String scioVersion) {
   }

   @Override
   public void onError(int code, String message) {
   }
});

 

Get ConsumerPhysics models info (name, ID, supported SCiO versions, etc.) and use them to analyze your scans.

Each model has a “supportedSCiOVersions” array property that contains all the supported SCiO versions for the specific model.

__weak typeof(&*self)weakSelf = self;
[[CPScioCloud sharedInstance] getCPModelsWithCompletion:^(BOOL success, NSArray *models, NSError *error) {
    if (success) {
        [weakSelf modelsScreenWithModels:models];
        return;
    }
    
    // Error
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakSelf alertWithTitle:error.userInfo[NSLocalizedDescriptionKey]  mes-sage:error.userInfo[NSLocalizedFailureReasonErrorKey]];
    });
}];}

To retrieve the model IDs of ConsumerPhysics models, use the ScioCloud.getCPModels() methods, and create the ScioCloudModelsCallback methods:

  • onSuccess(): Returns a list of all CP Models. Use this model ID to send to the cloud to compare with the scanned sample.

  • onError(): Returns the error message.

 

The following code sample shows how to retrieve the model ID:

getScioCloud().getCPModels(new ScioCloudCPModelsCallback() {
   @Override
   public void onSuccess(List<ScioCPModel> models) {
   }

   @Override
   public void onError(int code, String error) {
   }
});

Get your model info (name, ID, etc.) and use it to analyze your scans.

    
__weak typeof(&*self)weakSelf = self;
 [[CPScioCloud sharedInstance] getModelsWithCompletion:^(BOOL success, NSArray *models, NSError *error) {
        if (success) {
            [weakSelf modelsScreenWithModels:models];
            return;
        }
        
        // Error
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf alertWithTitle:error.userInfo[NSLocalizedDescriptionKey]  mes-sage:error.userInfo[NSLocalizedFailureReasonErrorKey]];
        });
    }];

You can check if your SCiO device needs calibration before scanning using the following SCiO Device API:

scioDevice.isCalibrationNeeded();

You can read your SCiO device battery status using the following SCiO Device API:

scioDevice.readBattery(new ScioDeviceBatteryHandler() {
  @Override
  public void onSuccess(final ScioBattery battery) {
  }


  @Override
  public void onError() {
  }


  @Override
  public void onTimeout() {
  }
});

Once calibration data is taken, the user can scan. The following code sample takes a scan:

__weak typeof(&*self)weakSelf = self;
    [[CPScioDevice sharedInstance] isCalibrationValid:^(BOOL success) {
        if (!success) {
            [weakSelf alertWithTitle:@"Calibration is invalid" message:@"Calibrate before scan"];
            return;
        }
        [weakSelf toastWithTitle:@"scanAPI" message:@"Scanning"];
        [[CPScioDevice sharedInstance] scanWithCompletion:^(BOOL success, CPScioReading *reading, NSError *error) {
            NSLog(@"Scan: %i",success);
            if (!success) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self alertWithTitle:error.userInfo[NSLocalizedDescriptionKey] message:error.userInfo[NSLocalizedFailureReasonErrorKey]];
                });
                return;
            }
            weakSelf.scanReading = reading;
            if (![SASampleFileUtils storeToDisk:reading fileName:SALastScanFileName]) {
                [self alertWithTitle:@"Failure" message:@"Failed to save last scan"];
            }
            
            [self toastWithTitle:@"Scan Completed" message:@"You can analyze a model now."];
        }];
    }];

The battery status API retrieves the battery percentage and charging status.

The following code sample reads the battery status from the SCiO device.

__weak typeof(&*self)weakSelf = self;
[[CPScioDevice sharedInstance] getBatteryStatusWithCompletion:^(double percentage, BOOL isCharging, NSError *error) {
    if (error) {
        [weakSelf alertWithTitle:error.userInfo[NSLocalizedDescriptionKey]  message:error.userInfo[NSLocalizedFailureReasonErrorKey]];
        return;
    }
    
    [weakSelf alertWithTitle:@"Battery status" message:[NSString stringWithFormat:@"Status: %@\nPercentage: %.0f", isCharging ? @"Charging" : @"Not charging", percentage]];
}];

A SCiO device can be renamed using the renameDeviceWithName API call.

The following code sample sets a new name for the SCiO device.

__weak typeof(&*self)weakSelf = self;
 [[CPScioDevice sharedInstance] renameDeviceWithName:name completion:^(BOOL success, NSError *error) {
     if (success) {
         dispatch_async(dispatch_get_main_queue(), ^{
             weakSelf.scioNameLabel.text = name;
         });
         return;
     }
     
     [weakSelf alertWithTitle:error.userInfo[NSLocalizedDescriptionKey]  message:error.userInfo[NSLocalizedFailureReasonErrorKey]];
 }];

There are a few versions of SCiO, and models might be compatible across versions, but with degraded performance. As a developer, you may want to verify which SCiO version is used and block or approve its spectra prior to analysis.
The following code sample sets a new name for the SCiO device:

__weak typeof(&*self)weakSelf = self;
[[CPScioCloud sharedInstance] getSCiOVersionByDeviceID:[[CPScioDevice sharedInstance] getDeviceID] completion:^(NSString *SCiOVersion, NSError *error) {
    NSLog(@"SCiO version:%@", SCiOVersion);
    [weakSelf alertWithTitle:@"SCiO Version" message:SCiOVersion];
}];