To retrieve data from a sensor in the synchronous mode, use the SensorConnection.getData
method, for
example:
int bufferSize = 10; Data[] data = sensorConnection.getData(bufferSize); int bufferingPeriod = 1000; boolean includeTimestamps = true; boolean includeUncertainities = true; boolean includeValidities = true; Data[] data = sensorConnection.getData(bufferSize, bufferingPeriod, includeTimestamps, includeUncertainities, includeValidities);
SensorConnection.getData
returns the collected
data of all the channels of the sensor, so the returned array contains
as many Data
objects as there are channels. The
data values can be accessed by using the Data.getIntValues
, Data.getDoubleValues
, and Data.getObjectValues
methods. The Data
object returns only the value type defined by the
channel, otherwise it throws an IllegalStateException
. For example:
double[] doubleValues; int[] intValues; Data[] data = sensorConnection.getData(bufferSize); if(data[0].getChannelInfo().getDataType() == ChannelInfo.TYPE_DOUBLE) { // Get double values doubleValues = data[0].getDoubleValues(); } else if(data[0].getChannelInfo().getDataType() == ChannelInfo.TYPE_INT) { // Get int values intValues = data[0].getIntValues(); }