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) {
   }
});

 

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) {
   }
});

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() {
  }
});

You can rename your SCiO device using the following SCiO Device API:

scioDevice.renameDevice(newName, new ScioDeviceCallbackHandler() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
}
@Override
public void onTimeout() {
}
});

 

Once you have retrieved the analyzed results from the SCiO cloud, you can get its value according to the attribute type. The value can be either an estimation (including the unit type). or a classification.

The following code demonstrates how to retrieve the attribute type and its value:

final ScioModel model = getItem(position);
final String value;
String unit = null;

switch (model.getAttributes().get(0).getAttributeType()) {
   case STRING:
       value = ((ScioStringAttribute) (model.getAttributes().get(0))).getValue();
       break;
   case NUMERIC:
       value = String.valueOf(((ScioNumericAttribute) (model.getAttributes().get(0))).getValue());
       unit = model.getAttributes().get(0).getUnits();
       break;
   case DATE_TIME:
       value = ((ScioDatetimeAttribute) (model.getAttributes().get(0))).getValue().toString();
       break;
   default:
       value = "Unknown";
}

attributeName.setText(model.getName());

if (model.getType().equals(ScioModel.Type.ESTIMATION)) {
   attributeValue.setText(value + unit);
}
else {
   attributeValue.setText(value + " (" + String.format("%.2f", model.getConfidence()) + ")");

The new scan data is sent to the cloud together with the model ID to be analyzed.

To retrieve the model ID from ScioLab use the ScioCloud.getModels() methods, and create the ScioCloudModelsCallback methods:

  • onSuccess(): Returns a list of all ScioModels associated with the user’s SCiO account. 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:aliqua

public void getModels(final ScioCloudModelsCallback scioCloudModelsCallback) {

  scioCloud.getModels(new ScioCloudModelsCallback () {
      @Override
      public void onSuccess(final List<ScioModel> models) {
          for (ScioModel model : models) {
              Log.d("DemoApp","Model ID="+model.getId()+"  Name="+model.getName());
          }
      }

      @Override
      public void onError(int errorCode, String message) {
          Log.i("DemoApp", "get models on Error");
          Log.i("DemoApp", "----->" + message);
      }
  });
}

The ScioCloud analyse function has the following parameters:

  • ScioReading: The sample data retrieved after a successful scan.
  • ModelId / List<ModelId>: ID of the model or a list of model id’s to compare the sample data to. You retrieve the model ID from the ScioModel object returned by the cloud.
  • ScioCloudAnalyzeCallback/ScioCloudAnalyzeManyCallback function: The callback object for the analyze function. This callback is called when the cloud sends back the analyzed scanned sample data with the results. The sample is analyzed, and in turn the ScioModel or List<ScioModel> objects are constructed and sent back to the mobile device.

The ScioCloudAnalyzeCallback/ScioCloudAnalyzeManyCallback  has two callback methods: onSuccess() and onError().

The onSuccess() method returns the data from the scanned sample including:

  • ScioModel/List<ScioModel>: ScioModel objects contains the model for the scanned sample including its specific attributes.

The onError function returns a String with an error message.

The following code sample sends a ScioReading to the cloud for analysis, retrieves the ScioModel and displays the information on the screen.

(Analyzing multiple models at once is not shown here but is done in the same way).

public void analyze(final ScioReading reading, final String modelId) {

   scioCloud.analyze(reading, modelId, new ScioCloudAnalyzeCallback() {
       @Override
       public void onSuccess(final ScioModel model) {

           List<ScioAttribute> modelAttributes = model.getAttributes();

           // model attribute for example
           ScioAttribute attribute = modelAttributes.get(0);

           String attributeType = attribute.getAttributeType().toString();
           String attributeUnit = attribute.getUnits();
           String attributeValue;

           switch (attribute.getAttributeType()) { 
               case STRING: 
                   attributeValue = ((ScioStringAttribute) attribute).getValue(); 
                    break; 
               case NUMERIC: 
                   attributeValue = String.valueOf(((ScioNumericAttribute) (attribute)).getValue()); 
                   break; 
              case DATE_TIME: 
                  attributeValue = ((ScioDatetimeAttribute) (attribute)).getValue().toString(); 
                  break;
               default: 
                   attributeValue = "N/A";
          } Log.i("DemoApp analyze", "Result model attribute type: " + attributeType); Log.i("DemoApp analyze", "Result model Get Units: " + attributeUnit); Log.i("DemoApp analyze", "Result model Value: " + attributeValue); 
      } 
      @Override 
      public void onError(int errorCode, String message) {
          Log.e("DemoApp analyze","on error: " + message); 
      } 
  }); 
}

 

The SCiO device class enables the application to register the following callback functions:

  • setButtonPressedCallback(): A callback method activated when the user presses the SCiO sensor’s button.

The following code sample implements the setButtonPressedCallback method.

myScio.setButtonPressedCallback(new ScioDeviceCallback() {
   @Override
   public void execute() {
       Log.d("DemoApp","SCiO Button was pressed");
   }
});

  • setScioDisconnectCallback(): A callback method activated when communication between the SCiO sensor and the app fails.

The following code sample implements the setScioDisconnectCallback method.

myScio.setScioDisconnectCallback (new ScioDeviceCallback() {
        @Override
        public void execute() {
                Log.d ("DemoApp", "SCiO disconnect") ;
           }
});

 

SCiO Sensors need to be calibrated or recalibrated in order to provide accurate scans over time. Calibration is done by having the user place their SCiO Sensor in the SCiO Cover and having the SCiO “scan” the cover, which serves as a white reference. You will be notified when calibration is required.

To calibrate,  put the SCiO Sensor into the SCiO cover with the optical head facing down into the cover, the app should call the calibrate method.

In addition, a SCiO scan can return onNeedCalibrate indicating that the SCiO must be calibrated in order to perform another successful scan.

The following code sample calibrates a SCiO sensor:

public void calibrateDevice(final ScioDevice device) {
 myScio.calibrate(new ScioDeviceCalibrateHandler() {
  @Override public void onSuccess() {
   /* In order to write to the UI, run the function on a UI thread.*/
   runOnUiThread(new Runnable() {

    @Override public void run() {
     Toast.makeText(deviceContext, "Your device has been calibrated. You may now use it to scan samples.", Toast.LENGTH_SHORT).show();
    }
   });
   Log.i("DemoApp calibrate", "success");
  }
  @Override public void onError() {
   runOnUiThread(new Runnable() {
    @Override public void run() {
     Toast.makeText(deviceContext, "Your device has NOT been calibrated. Try again or wait for this to be automatically reset", Toast.LENGTH_SHORT).show();
    }
   });
   Log.i("DemoApp calibrate", "error");
  }
  @Override public void onTimeout() {
   runOnUiThread(new Runnable() {
    @Override public void run() {
     Toast.makeText(deviceContext, "Your device has NOT been calibrated. Try again or wait for this to be automatically reset", Toast.LENGTH_SHORT).show();
    }
   });
   Log.i("DemoApp calibrate", "timed out, try again");
  }
 });
}