public NativeI2CDeviceSysFs(int controller, int deviceAddress, boolean force) { this.controller = controller; this.deviceAddress = deviceAddress; String device_file = "/dev/i2c-" + controller; try { deviceFile = new RandomAccessFile(device_file, "rwd"); int fd = FileUtil.getNativeFileDescriptor(deviceFile.getFD()); int rc = NativeI2C.selectSlave(fd, deviceAddress, force); if (rc < 0) { close(); if (rc == EBUSY) { throw new DeviceBusyException("Error, I2C device " + controller + "-0x" + Integer.toHexString(deviceAddress) + " is busy"); } throw new RuntimeIOException("Error selecting I2C address " + controller + "-0x" + Integer.toHexString(deviceAddress) + ": " + rc); } } catch (IOException e) { close(); throw new RuntimeIOException( "Error opening I2C device " + controller + "-0x" + Integer.toHexString(deviceAddress), e); } }
public NativeI2CDeviceSMBus(int controller, int deviceAddress, boolean force) throws RuntimeIOException { this.controller = controller; this.deviceAddress = deviceAddress; String device_file = "/dev/i2c-" + controller; int rc = NativeI2C.smbusOpen(device_file, deviceAddress, force); if (rc < 0) { if (rc == -16) { throw new DeviceBusyException("Error, I2C device " + controller + "-0x" + Integer.toHexString(deviceAddress) + " is busy"); } throw new RuntimeIOException(rc); } fd = rc; rc = NativeI2C.getFuncs(fd); if (rc < 0) { close(); throw new RuntimeIOException("Error reading I2C_FUNCS for device i2c-" + controller + "-0x" + Integer.toHexString(deviceAddress) + ": " + rc); } funcs = rc; Logger.debug("I2C_FUNCS for controller {}: 0x{}", Integer.toString(controller), Integer.toHexString(funcs)); }