FB_CMA_ReadCsvFile

Reading a CSV file and sequential output of the data to a PLC buffer (array).

Data can be recorded, displayed and saved with the TwinCAT 3 Scope. One potential storage format is CSV. This allows signal data to be stored in a CSV file and read in again later using the FB_CMA_ReadCsvFile. The signal data read in with this can be transferred to an instance of FB_CMA_Source and thus to the condition monitoring analysis chain as an alternative source of input data.

You can find an example of how to use the function block here: Fatigue Analysis.

You will find another example at the bottom of this page.

Inputs and outputs

Input parameters

VAR_INPUT
    bExecute        : BOOL := TRUE;       // starts execution (on rising edge)
    bAbort          : BOOL;               // aborts execution (after finishing current ADS communication) 
    sNetId          : T_AmsNetId := '';   // TwinCAT system network address (could be kept empty for local host)
    tAdsTimeout     : TIME := T#1S;       // ADS timeout (only 1 second as condition for a fast data transmission)
    sFileName       : T_MaxString := '';  // CSV source file path and name (located on the system with the specified Net Id)
    sSeparator      : STRING(2) := '$T';  // CSV field separator [e.g. tab '$T' or comma ',' or semicolon ';' or colon ':' or blank ' ']
    nHeaderLines    : UDINT := 0;         // Number of lines in the CSV file which belongs to the header. Data start after header lines.
    bColumn         : BOOL := TRUE;       // select whether the data is placed as column (e.g. TcScope CSV file) or as line
END_VAR
VAR_IN_OUT
    aBuffer         : ARRAY[*] OF LREAL;  // buffer with individual length (do not switch the buffer during one execution)
END_VAR

Output parameters

VAR_OUTPUT
    bBufferFull     : BOOL;     // signals that aBuffer is fully filled
    nReadRecords    : UDINT;    // shows the number of records saved to aBuffer
    bBusy           : BOOL;     // TRUE if execution is active
    bError          : BOOL;     // TRUE if an error occurred
    hrErrorCode     : HRESULT;  // '< 0' = error; '> 0' = info; '0' = no error/info
    ipErrorMessage  : I_TcMessage := fbErrorMessage;    // shows detailed information about occurred errors,warnings and more
END_VAR

Example

This example shows how the FB_CMA_ReadCsvFile is used. A large buffer length is assumed for the buffer specified for aBuffer, which favors outsourcing to a separate task. The buffer is transferred to the actual PLC task via the process image and is available there as a process image input, analogous to an oversampling terminal.

Download the sample: ReadCsvFile_Sample