UsbDevice probe = findProbe();
if (probe == null) {
System.err.println("No Go!Temp probe attached.");
return;
}
UsbConfiguration config = probe.getActiveUsbConfiguration();
UsbInterface theInterface = config.getUsbInterface((byte) 0);
theInterface.claim(new UsbInterfacePolicy() {
public boolean forceClaim(UsbInterface usbInterface) {
return true;
}
});
UsbEndpoint endpoint = (UsbEndpoint) theInterface.getUsbEndpoints().get(0);
UsbPipe pipe = endpoint.getUsbPipe();
// set up the IRP
UsbIrp irp = pipe.createUsbIrp();
byte[] data = new byte[8];
irp.setData(data);
pipe.open();
outer: while (true) {
pipe.syncSubmit(irp);
int numberOfMeasurements = data[0];
for (int i = 0; i < numberOfMeasurements; i++) {
int result = UsbUtil.toShort(data[2*i+3], data[2*i+2]);
int sequenceNumber = UsbUtil.unsignedInt(data[1]);
double temperature = result / 128.0;
if (temperature > 110.0) {
System.err.println("Maximum accurate temperature exceeded.");
break outer;
}
else if (temperature < -10) {
System.err.println("Minimum accurate temperature exceeded.");
break outer;
}
System.out.println("Measurement " + sequenceNumber + ": "
+ temperature + "°C");
}
// get ready to reuse IRP
irp.setComplete(false);
}
pipe.abortAllSubmissions();
pipe.close();
theInterface.release();