public void write(byte[] data) throws RuntimeIOException { write(data, order); }
public void writeBytes(int regAddr, int length, byte[] data, int offset) throws RuntimeIOException { /* * if (I2CDEV_SERIAL_DEBUG) { System.out.format( * "I2C (0x%x) writing %d bytes to 0x%x...%n", devAddr, length, regAddr); } */ byte[] dest = new byte[length]; System.arraycopy(data, offset, dest, 0, length); write(regAddr, SUB_ADDRESS_SIZE_1_BYTE, dest); }
public void write(ByteBuffer buffer, int payloadLength) throws RuntimeIOException { write(buffer, payloadLength, order); }
public void write(int registerAddress, ByteBuffer buffer, int payloadLength) throws RuntimeIOException { write(registerAddress, SUB_ADDRESS_SIZE_1_BYTE, buffer, payloadLength, order); }
/** * Set the analog output value. * @param dacPin The analog output channel. * @param value Analogue output value (0..1). * @throws RuntimeIOException if an I/O error occurs */ public void setValue(int dacPin, float value) throws RuntimeIOException { outputEnabled = true; if (dacPin < 0 || dacPin >= 1) { throw new IllegalArgumentException("Invalid output channel number (" + dacPin + ")"); } if (value < 0 || value >= 1) { throw new IllegalArgumentException("Invalid output value (" + value + ", must be 0..1"); } //device.writeByte(ANALOG_OUTPUT_ENABLE_MASK, (byte) (value * (RANGE-1))); byte[] data = new byte[2]; data[0] = ANALOG_OUTPUT_ENABLE_MASK; data[1] = (byte) (value * (RANGE-1)); device.write(data); }
/** * Write a single word to a 16-bit device register * * @param regAddr * Register address to write to * @param data * New word value to write * @throws RuntimeIOException * if an I/O error occurs */ public void writeWord(int regAddr, int data) throws RuntimeIOException { // bool I2Cdev::writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t // data) ByteBuffer buffer = ByteBuffer.allocateDirect(2); buffer.order(order); buffer.putShort((short) data); buffer.flip(); byte[] array = new byte[buffer.remaining()]; buffer.get(array); write(regAddr, SUB_ADDRESS_SIZE_2_BYTES, array); }
public byte readByte(int address) { device.write(getAddressByteArray(address)); return device.readByte(); }
public byte[] readBytes(int address, int length) { device.write(getAddressByteArray(address)); return device.read(length); }
public void writeByte(int address, byte data) { byte[] addr_bytes = getAddressByteArray(address); byte[] buffer = new byte[addr_bytes.length+1]; System.arraycopy(addr_bytes, 0, buffer, 0, addr_bytes.length); buffer[addr_bytes.length] = data; device.write(buffer); SleepUtil.sleepMillis(type.getWriteCycleTimeMillis()); }
public void writeBytes(int address, byte[] data) { if ((address + data.length) > type.getMemorySizeBytes()) { Logger.error("Attempt to write beyond memory size - no data written"); return; } int page = address / type.getPageSizeBytes(); int bytes_remaining = data.length; do { int remaining_page_size = type.getPageSizeBytes() - (address % type.getPageSizeBytes()); int bytes_to_write = remaining_page_size < bytes_remaining ? remaining_page_size : bytes_remaining; byte[] addr_bytes = getAddressByteArray(address); byte[] buffer = new byte[addr_bytes.length+bytes_to_write]; System.arraycopy(addr_bytes, 0, buffer, 0, addr_bytes.length); System.arraycopy(data, data.length - bytes_remaining, buffer, addr_bytes.length, bytes_to_write); device.write(buffer); bytes_remaining -= bytes_to_write; page++; address = page * type.getPageSizeBytes(); SleepUtil.sleepMillis(type.getWriteCycleTimeMillis()); } while (bytes_remaining > 0); }