I2CDevice.TryWriteRead | tryWriteRead method

Performs an atomic operation to write data to and then read data from the inter-integrated circuit (I²C) bus on which the device is connected, and returns information about the success of the operation that you can use for error handling.

Syntax

var result = i2cDevice.tryWriteRead(writeBuffer);
var readBuffer = result.readBuffer;
var bytesTransferred = result.bytesTransferred;
var i2cTransferStatus = result.i2cTransferStatus;
public I2CTransferStatus TryWriteRead(
  byte[] writeBuffer, 
  out byte[] readBuffer, 
  out uint bytesTransferred
)
Public Function TryWriteRead(
  writeBuffer As Byte(),  
  <OutAttribute> readBuffer As Byte(),  
  <OutAttribute> ByRef bytesTransferred As UInteger 
) As I2CTransferStatus
public:
I2CTransferStatus TryWriteRead(
  Array<unsigned char>^ writeBuffer, 
  Array<unsigned char>^ readBuffer, 
  [OutAttribute] unsigned int bytesTransferred
)

Parameters

  • writeBuffer
    Type: array of Number [JavaScript] | System.Byte[] [.NET] | Platform::Array<uint8> [C++]

    A buffer that contains the data that you want to write to the I²C device. This data should not include the bus address.

  • readBuffer (out parameter)
    Type: array of Number [JavaScript] | System.Byte[] [.NET] | Platform::Array<uint8> [C++]

    The buffer to which you want to read the data from the I²C bus. The length of the buffer determines how much data to request from the device.

  • bytesTransferred (out parameter)
    Type: Number [JavaScript] | System.UInt32 [.NET] | uint32 [C++]

    The actual number of bytes that the read operation transferred, which is the sum of the number of bytes that the operation wrote and the number of bytes that the operation read. If the return value is I2CTransferStatus.PartialTransfer, this value may be less than the sum of lengths of the buffers that you specified in the writeBuffer and readBuffer parameters.

Return value

Type: I2CTransferStatus

A value that indicates if both the write operation transferred the full buffer specified by writeBuffer to the I²C device and the read operation read the full number of bytes that the method requested to the buffer specified by readBuffer, or the reason that the full transfers did not succeed.

Requirements (device family)

Device family

Universal

API contract

Windows.Devices.DevicesLowLevelContract, introduced version 1.0

Namespace

Windows.Devices.I2C Windows::Devices::I2C [C++]

Metadata

Windows.Devices.DevicesLowLevelContract.winmd

See also

I2CDevice

WriteRead

TryWrite

TryRead

I2CTransferStatus