/// <summary> /// Reads data from the specified address. /// </summary> /// <param name="address">The address.</param> /// <param name="count">The count. Recommended 32 as maximum.</param> /// <returns>The byte array that was read.</returns> public byte[] Read(byte address, int count) { var data = new byte[7]; data[0] = 0x04; // Set Address data[1] = address; // Address Literal data[2] = 0x02; // Start Condition data[3] = 0x06; // Write Command data[4] = Convert.ToByte(count); // data length; data[5] = 0x03; // Stop condition data[6] = 0x00; // End command; var output = new byte[count]; var outCount = BoardException.ValidateResult( I2c.BbI2CZip(Handle, data, Convert.ToUInt32(data.Length), output, Convert.ToUInt32(output.Length))); if (output.Length == outCount) { return(output); } var result = new byte[outCount]; Buffer.BlockCopy(output, 0, result, 0, outCount); return(result); }
/// <summary> /// Writes data to the specified address. /// </summary> /// <param name="address">The address.</param> /// <param name="buffer">The buffer. Recommended 32 bytes max.</param> public void Write(byte address, byte[] buffer) { var data = new byte[7 + buffer.Length]; data[0] = 0x04; // Set Address data[1] = address; // Address Literal data[2] = 0x02; // Start Condition data[3] = 0x07; // Write Command data[4] = Convert.ToByte(data.Length); // data length; data[data.Length - 2] = 0x03; // Stop condition data[data.Length - 1] = 0x00; // End command; // copy buffer data to command Buffer.BlockCopy(buffer, 0, data, 5, data.Length); var output = new byte[32]; BoardException.ValidateResult( I2c.BbI2CZip(Handle, data, Convert.ToUInt32(data.Length), output, Convert.ToUInt32(output.Length))); }