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