LabWindows/CVI

Content Type
Programming Language
Current manual
Table of Contents

TDMS_AdvancedAsyncWrite

TDMS_AdvancedAsyncWrite

int TDMS_AdvancedAsyncWrite (TDMSFileHandle file, void *samples, size_t numberOfSamples, TDMSDataType dataType, TDMSAsyncWriteCallbackPtr callback, void *callbackData);

Purpose

Writes data to the specified .tdms file asynchronously.

This function can issue additional asynchronous writes while executing previously issued asynchronous writes in the background. When the number of asynchronous writes in the background reaches the maximum value, this function waits until a previously issued asynchronous write completes before issuing an additional asynchronous write. If the previously issued asynchronous write does not complete within the timeout value, this function returns error code TDMS_OperationTimedOut. Call TDMS_ConfigureAsyncWrites to configure the maximum number of asynchronous writes and the timeout value.

Call TDMS_GetAsyncWriteStatus to query the number of pending asynchronous writes.

(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.
samples void * An array containing samples that will be written to the specified file.

Because the write operation is asynchronous you cannot modify the array contents or dispose of the array memory immediately after this function call returns. Instead you must wait until the asynchronous operation completes. You can be notified when the asynchronous operation completes using the callback parameter. The type of this array should match the type of the samples you are writing. This function does not support writing samples of type string.

If the type of the samples you are writing 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.

Note Note  The alignment of the pointer value passed for this parameter can significantly impact the performance of this write operation. The performance impact varies depending on the hardware being used. National Instruments recommends a minimal alignment of 512 bytes and a preferred alignment of 4096 bytes. Call TDMS_AllocateAlignedMemory to allocate aligned memory for this parameter.
numberOfSamples size_t The number of samples to write.
Note Note   If you specified the disable buffering option when you opened the file using TDMS_AdvancedOpenFile or TDMS_AdvancedCreateFile, then the number of samples should correspond to a number of bytes that is an even multiple of the sector size of the hard disk. This is necessary so that subsequent calls to this function will read from a position in the file that is aligned on a hard disk sector boundary. This requirement does not apply to the last call to this function that corresponds to a single call to TDMS_ConfigureAsyncWrites. The sector size of the hard disk is available as an output parameter from TDMS_AdvancedOpenFile or TDMS_AdvancedCreateFile.
dataType TDMSDataType The data type of the samples to write. This function does not support writing samples of type string.
callback TDMSAsyncWriteCallbackPtr The function that the library calls when the asynchronous write operation is complete or fails due to an error. The library calls this function asynchronously in a worker thread. The TDM Streaming library will always call 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 numSamplesWritten, 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 write operation failed or zero if the write operation succeeded. The samples parameter contains the same array pointer passed to this function. The numSamplesWritten parameter contains the number of samples written to the file. This will be the same number of samples passed to this function or will be zero if an error occurred. 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.

Note  Return from this function as soon as possible to avoid blocking other asynchronous operations on the same file. If needed, you can use PostDeferredCallToThread or the Thread Pool functions to process this event in a different thread. From within this callback function, you must also avoid calling any functions in the TDM Streaming Library to perform an operation using the same file or any channel groups or channels within that file. The TDM Streaming Library will return an error in that case in order to prevent a deadlock.
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.

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_AdvancedAsyncWrite function:

  • TDM Streaming\Advanced Read and Write\TDMS Advanced Async Write\TDMS Advanced Async Write.cws

    Open example
  • TDM Streaming\Advanced Read and Write\TDMS Advanced Async Write Throughput Test\TDMS Advanced Async Write Throughput Test.cws

    Open example
Was this information helpful?