I try to read a gaz sensor in java with jdk.dio but I always read 0 on my SPI bus with this code:
import java.nio.ByteBuffer;
import org.slf4j.Logger;
import jdk.dio.Device;
import jdk.dio.DeviceConfig;
import jdk.dio.DeviceManager;
import jdk.dio.spibus.SPIDevice;
import jdk.dio.spibus.SPIDeviceConfig;
public class SPIDACDemo {
public static void startApp(Logger sLogger, int spiDeviceId) {
try {
SPIDeviceConfig config = new SPIDeviceConfig(0, 1, 300000, 0, DeviceConfig.DEFAULT, Device.BIG_ENDIAN);
SPIDevice spi = (SPIDevice) DeviceManager.open(config);
while (true) {
ByteBuffer rcvMsg = ByteBuffer.wrap(new byte[2]);
int resp = spi.read(rcvMsg);
System.out.println(resp);
for (byte b : rcvMsg.array()) {
System.out.println(b);
}
String message = "Response: " + resp + ", Received: " + new String(rcvMsg.array(),"ASCII");
System.out.println(message);
Thread.sleep(1000);
}
spi.close();
System.out.println("Done");
} catch (Exception ex) {
System.out.println(ex.getMessage());
sLogger.error(SPIDACDemo.class.getName() + ", error:" + ex);
}
}
}
my connection is OK and I can read value in python but in Java I only read 0...