TDMS_AdvancedAsyncRead
- Updated2023-02-21
- 5 minute(s) read
int TDMS_AdvancedAsyncRead (TDMSFileHandle file, void *samples, size_t numberOfSamples, TDMSDataType dataType, TDMSAsyncReadCallbackPtr callback, void *callbackData, int *readProcessFinished);
Purpose
Reads data from the specified .tdms file asynchronously.
This function can issue additional asynchronous reads while executing previously issued asynchronous reads in the background. When the number of asynchronous reads in the background reaches the maximum value, this function waits until a previously issued asynchronous read completes before issuing an additional asynchronous read. If the previously issued asynchronous read does not complete within the timeout value, this function returns error code TDMS_OperationTimedOut. Call TDMS_ConfigureAsyncReads to configure the maximum number of asynchronous reads and the timeout value.
Call TDMS_GetAsyncReadStatus to query the number of pending asynchronous reads.
(Linux) This function is not supported.
(Real-Time Module) This function is not supported.
Parameters
| Input | ||||
| Name | Type | Description | ||
| file | TDMSFileHandle | The file handle. You obtain this handle from TDMS_AdvancedOpenFile or TDMS_AdvancedCreateFile. You must specify the enable asynchronous operations option when you open or create the file. | ||
| numberOfSamples | size_t | The number of samples to read.
|
||
| dataType | TDMSDataType | The data type of the samples to read. This function does not support reading samples of type string. | ||
| callback | TDMSAsyncReadCallbackPtr | The function that the library calls when the asynchronous read operation is complete or fails due to an error. The library calls this function asynchronously in a worker thread. The TDM Streaming Library always calls your callbacks in the same order in which you issue the corresponding calls to this function. The function you pass for this parameter must have the following prototype: void CVICALLBACK Callback (TDMSFileHandle file, int error, void *samples, size_t numSamplesRead, void *callbackData); Upon entry to the callback, the file parameter contains the same file handle passed to this function. The error parameter contains an error code value indicating the reason the read operation failed or zero if the read operation succeeded. The samples parameter contains the same array pointer passed to this function. The numSamplesRead parameter contains the number of samples actually read from the file. This value can be less than the numberOfSamples value passed to this function. This happens when the number of samples remaining from the total passed to the totalSamplesToRead parameter of TDMS_ConfigureAsyncReads is less the value of numberOfSamples passed to this function. The callbackData parameter of the callback contains the value you provide in the callbackData parameter of this function. You can use this parameter to pass any additional information you choose.
|
||
| callbackData | void * | Specifies a pointer to user-defined data that the TDM Streaming Library will pass to your callback as the callbackData parameter. Do not pass the address of a local variable or any other variable or memory that might not be valid when the callback is executed. If you do not need callback data you can pass NULL for this parameter. | ||
| Output | ||||
| Name | Type | Description | ||
| samples | void * | An array that receives the samples from the specified file. Because the read operation is asynchronous the array will not contain the samples read from the file immediately after this function call returns. Instead you must wait until the asynchronous operation completes before referencing the array contents. You can be notified when the asynchronous operation completes using the callback parameter. This array must be large enough to hold at least the number of samples specified by the numberOfSamples parameter. The type of this array should match the type of the samples you are reading. This function does not support reading samples of type string. If the type of the samples you are reading is TDMS_Timestamp, you must pass an array of type CVIAbsoluteTime. Refer to the Absolute Time functions in the Utility Library for more information about this type.
|
||
| readProcessFinished | int | Indicates whether this call completes the read operations configured by a corresponding call to TDMS_ConfigureAsyncReads. This value will be zero if additional calls to this function are needed and non-zero if no additional calls are needed. You can use this value to determine when to exit a loop that calls this function on each iteration. The read operations configured by a corresponding call to TDMS_ConfigureAsyncReads are complete if this function reaches the end of the file or finishes reading the number of samples specified by the totalSamplesToRead parameter of TDMS_ConfigureAsyncReads. |
||
Return Value
| Name | Type | Description |
| status | int | Return value indicating whether the function was successful. Unless otherwise stated, zero represents successful execution and a negative number represents the error code. Error codes are defined in cvi\include\cvitdms.h. |
Additional Information
Library: TDM Streaming Library
Include file: cvitdms.h
LabWindows/CVI compatibility: LabWindows/CVI 2013 and later
© 2016 National Instruments. All rights reserved.
Examples
Refer to the following examples that use the TDMS_AdvancedAsyncRead function:

