The function I2CTransfer:
This function performs one or more I2C read or write operations. pI2CTransferBlock contains a pointer to
the first of an array of I2C packets to be processed by the I2C. All the required information for the I2C
operations should be contained in the array elements of pI2CPackets.
BOOL I2CTransfer(
HANDLE hDev,
PI2C_TRANSFER_BLOCK pI2CTransferBlock);
Parameters:
hDev I2C device handle retrieved from CreateFile()
pI2CTransferBlock
pI2CPackets [in] Pointer to an array of packets to be transferred sequentially
iNumPackets [in] Number of packets pointed to by pI2CPackets (the number of packets to be
transferred)
Return Values Returns TRUE or FALSE, if the result is TRUE, the operation is successful.
I have defined it as so:
[DllImport("i2csdk.DLL")]
public static extern bool I2CTransfer(IntPtr manejador, I2C_TRANSFER_BLOCK miBloque);
And the trnsfer function definitions are as follow:
I2C_PACKET
This structure contains the information needed to write or read data using an I2C port.
typedef struct {
BYTE byAddr;
BYTE byRW;
PBYTE pbyBuf;
WORD wLen;
LPINT lpiResult;
} I2C_PACKET, *PI2C_PACKET;
Members
byAddr 7-bit slave address that specifies the target I2C device to or from which data is read
or written
byRW Determines whether the packet is a read or a write packet. Set to I2C_RW_READ
for reading and I2C_RW_WRITE for writing. Set to I2C_POLLING_MODE to
force polling mode for transfer.
pbyBuf Pointer to a buffer of bytes. For a read operation, this is the buffer into which data
is read. For a write operation, this buffer contains the data to write to the target
device.
wLen If the operation is a read, wLen specifies the number of bytes to read into pbyBuf.
If the operation is a write, wLen specifies the number of bytes to write from
pbyBuf.
lpiResult Pointer to an int that contains the return code from the transfer operation
I2C_TRANSFER_BLOCK
This structure contains an array of packets to be transferred using an I2C port.
typedef struct {
I2C_PACKET *pI2CPackets;
INT32 iNumPackets;
} I2C_TRANSFER_BLOCK, *PI2C_TRANSFER_BLOCK;
Members
pI2CPackets Pointer to an array of I2C_PACKET objects
iNumPackets Number of I2C_PACKET objects pointed to by pI2CPackets