MultiLabQuestJNATest: What's wrong?

6 views
Skip to first unread message

Charles Xie

unread,
Mar 18, 2013, 4:21:12 PM3/18/13
to org-conco...@googlegroups.com
The following is my code of trying to get multiple LabQuest Mini to work at the lower level. It does find the right types of sensors of each of the two devices and even read seemingly correct values. However, the units seem to be wrong and all the temperature sensors seem to read the same value, which is unlikely. See the output below the code.


package org.concord.sensor.labquest.jna;

import java.io.IOException;

import com.sun.jna.Native;

public class MultiLabQuestJNATest {

private static LabQuestLibrary labQuestLib;
private static LabQuest[] labQuest;

public static void main(String[] args) throws IOException {

try {

labQuestLib = LabQuestLibrary.getInstance();
labQuestLib.init("main");

short[] version = labQuestLib.getDLLVersion();
System.out.println("major: " + version[0] + " minor: " + version[1]);

labQuestLib.searchForDevices();
labQuestLib.printListOfDevices();

String[] devices = new String[2];
labQuest = new LabQuest[devices.length];
for (int i = 0; i < 2; i++) {
devices[i] = labQuestLib.getDeviceName(i);
if (devices[i] != null) {
labQuest[i] = labQuestLib.openDevice(devices[i]);
System.out.println("Device " + i + ": " + devices[i] + "," + labQuest[i]);
if (labQuest[i] != null) {
test(labQuest[i]);
try {
labQuest[i].close();
} catch (LabQuestException e) {
e.printStackTrace();
}
}
}
}

} catch (Throwable t) {
t.printStackTrace();
}

labQuestLib.uninit("main");

}

public static void test(LabQuest lq) throws LabQuestException {
boolean remoteCollectionActive = false;
remoteCollectionActive = lq.isRemoteCollectionActive();
System.out.println("remote collection active: " + remoteCollectionActive);

// isremotecollection active appears to always return false. so even if it isn't active try to acquire ownership
lq.acquireExclusiveOwnership();

lq.printAttachedSensors();

int channel1Id = lq.getSensorId(NGIOSourceCmds.CHANNEL_ID_ANALOG1);
int channel2Id = lq.getSensorId(NGIOSourceCmds.CHANNEL_ID_ANALOG2);
int channel3Id = lq.getSensorId(NGIOSourceCmds.CHANNEL_ID_ANALOG3);
System.out.println("Channel IDs: " + channel1Id + "," + channel2Id + "," + channel3Id);

GSensorDDSMem sensorDDSMem = lq.ddsMemGetRecord(NGIOSourceCmds.CHANNEL_ID_ANALOG1);
byte[] unitBuf = sensorDDSMem.CalibrationPage[sensorDDSMem.ActiveCalPage].Units;
String unit1 = Native.toString(unitBuf);
sensorDDSMem = lq.ddsMemGetRecord(NGIOSourceCmds.CHANNEL_ID_ANALOG2);
unitBuf = sensorDDSMem.CalibrationPage[sensorDDSMem.ActiveCalPage].Units;
String unit2 = Native.toString(unitBuf);
sensorDDSMem = lq.ddsMemGetRecord(NGIOSourceCmds.CHANNEL_ID_ANALOG3);
unitBuf = sensorDDSMem.CalibrationPage[sensorDDSMem.ActiveCalPage].Units;
String unit3 = Native.toString(unitBuf);
System.out.println("Units: " + unit1 + "," + unit2 + "," + unit3);

// period in seconds
lq.setMeasurementPeriod((byte) -1, 0.1);

// send a NGIO_CMD_ID_SET_SENSOR_CHANNEL_ENABLE_MASK
lq.setSensorChannelEnableMask(0x02);

// Send a NGIO_CMD_ID_START_MEASUREMENTS
lq.startMeasurements();

// NGIO_Device_ReadRawMeasurements();
int[] pMeasurementsBuf = new int[1000];
for (int count = 0; count < 2; count++) {

try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}

float data1 = 0, data2 = 0, data3 = 0;

int n = lq.readRawMeasurementsAnalog(NGIOSourceCmds.CHANNEL_ID_ANALOG1, pMeasurementsBuf, pMeasurementsBuf.length);
data1 = lq.calibrateData2(NGIOSourceCmds.CHANNEL_ID_ANALOG1, pMeasurementsBuf[0]);

n = lq.readRawMeasurementsAnalog(NGIOSourceCmds.CHANNEL_ID_ANALOG2, pMeasurementsBuf, pMeasurementsBuf.length);
data2 = lq.calibrateData2(NGIOSourceCmds.CHANNEL_ID_ANALOG2, pMeasurementsBuf[0]);

n = lq.readRawMeasurementsAnalog(NGIOSourceCmds.CHANNEL_ID_ANALOG3, pMeasurementsBuf, pMeasurementsBuf.length);
data3 = lq.calibrateData2(NGIOSourceCmds.CHANNEL_ID_ANALOG3, pMeasurementsBuf[0]);

System.out.println(lq + ": value: " + data1 + " " + unit1 + " " + data2 + " " + unit2 + " " + data3 + " " + unit3);

}

// NGIO_CMD_ID_STOP_MEASUREMENTS
lq.stopMeasurements();

}

}


Output:


major: 1 minor: 97
labquest num devices: 0 list sig: 0
labquest_mini num devices: 2 list sig: 1
  dev name: ;0c;000000;89456944 (USB)
  dev name: ;0c;000000;89456912 (USB)
labquest_mini num devices: 0 list sig: 0
Device 0: ;0c;000000;89456944 (USB),org.concord.sensor.labquest.jna.LabQuestImpl@1d4d493
remote collection active: false
found sensor: 10
found sensor: 10
found sensor: 10
found sensor: 0
found sensor: 0
found sensor: 0
Channel IDs: 10,10,10
Units: Volts,Volts,Volts
org.concord.sensor.labquest.jna.LabQuestImpl@1d4d493: value: 2.971878 Volts 2.971878 Volts 2.971878 Volts
org.concord.sensor.labquest.jna.LabQuestImpl@1d4d493: value: 2.968216 Volts 2.968216 Volts 2.968216 Volts
LabQuest: closing
LabQuest: called close
LabQuest: claimed to close
Device 1: ;0c;000000;89456912 (USB),org.concord.sensor.labquest.jna.LabQuestImpl@a22671
remote collection active: false
found sensor: 10
found sensor: 24
  name: 
  operationType: 14
found sensor: 25
  name: 
  operationType: 14
found sensor: 0
found sensor: 0
found sensor: 0
Channel IDs: 10,24,25
Units: Volts,Volts,Volts
org.concord.sensor.labquest.jna.LabQuestImpl@a22671: value: 2.960205 Volts 128.40811 Volts -2.3171446 Volts
org.concord.sensor.labquest.jna.LabQuestImpl@a22671: value: 2.960205 Volts 128.40811 Volts -2.3171446 Volts
LabQuest: closing
LabQuest: called close
LabQuest: claimed to close


Scott Cytacki

unread,
Mar 19, 2013, 10:57:21 AM3/19/13
to org-concord-sensor
I think the values returned are correct, but the units are wrong.

Looking up the ids in sensor-vernier/.../SensorID.java, you've got 4 temp sensors and a gas pressure and a force sensor.
It would make sense for gas presure to be 128 and force -2.31 sounds reasonable too.

You need to manually calibrate the temperature sensor since it isn't a smart sensor, smart sensors are those with ids >= 20.
Look at sensor-vernier/.../VernierSensor#setupSensor to see how the higher level API handles part of this.
The other half of this handling is in sensor-verner/.../LabQuestSensorDevice:306-313

You might be able to use the VernierSensor class without the rest of the higher level API so you don't have to re-implement some of this handling.

I think the units are incorrect because you are not calling 
ddsMemReadRecord 
before
ddsMemGetRecord

For more details take a look at:
NGIO_Device_DDSMem_ReadRecord
and
NGIO_Device_DDSMem_GetRecord
in 
/labquest-jna/NGIO_SDK/redist/include/NGIO_lib_interface.h



--
--
You received this message because you are subscribed to the Google
Groups "org-concord-sensor" group.
To post to this group, send email to org-conco...@googlegroups.com
To unsubscribe from this group, send email to
org-concord-sen...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/org-concord-sensor?hl=en?hl=en
Google Code project for org-concord-sensor: http://code.google.com/p/org-concord-sensor/
---
You received this message because you are subscribed to the Google Groups "org-concord-sensor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to org-concord-sen...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Scott Cytacki
The Concord Consortium

Reply all
Reply to author
Forward
0 new messages