public bool Read(byte first_address, byte[] buffer) { int len = buffer.Length; int buffer_offset = 0; while (len > 0) { int read_len = (len > MAX_WPILIB_I2C_READ_BYTES) ? MAX_WPILIB_I2C_READ_BYTES : len; byte[] read_buffer = new byte[read_len]; bool write_ok; bool read_ok = false; lock (lockObject) { write_ok = port.Write(first_address + buffer_offset, read_len); if (write_ok) { read_ok = port.ReadOnly(read_buffer, read_len); } } if (write_ok && read_ok) { Array.Copy(read_buffer, 0, buffer, buffer_offset, read_len); buffer_offset += read_len; len -= read_len; } else { break; } } return(len == 0); }