uint32_t librpipTransactionReadSize(struct librpip_tx* t, uint16_t* len);
Returns the length in bytes that the next read will require to hold the RX data from a transaction. Like librpipTransactionRead(), if a transaction contains multiple RX message segments then librpipTransactionReadSize() can be called multiple times, once for each segment. This function is particularly useful when memory needs to be malloc’d.
If there is nothing to read or if the transaction that has not been sent it will return an error and not alter the value of the len variable.
- struct librpip_tx* t
A pointer to a transaction that is to be read. This will have been created from a previous librpipTransactionCreate() and should have been sent using librpipTransactionSend().
- uint16_t* len
A pointer to a uint16_t that will hold the length.
0 on failure or 1 on success.
Create a transaction to read several registers over I2C and then use malloc to get the result :
struct librpip_tx* readAccel; uint16_t size; uint8_t* result; readValue = librpipTransactionCreate(LIBRPIP_TX_MODE_I2C,8); librpipTransactionMsgAddRegRead(readValue, 0x3b, 2); librpipTransactionSend(readValue, 0, 0x31); //i2c0,client 0x31 librpipTransactionReadSize(readValue, &size); result=malloc(sizeof(uint8_t)*size); librpipTransactionRead(readValue, result, size); librpipTransactionDestroy(readValue); librpipClose();
API version 1.1