Infosys在阅读器中打开 / AI 翻译

TF3xxx - Measurement · 0 次阅读

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
  • bExecute: The function block is called by a positive edge on the bExecute input if the function block is not already active.
  • bAbortif this input is set, execution is canceled. The function block must be called until the output bBusy=FALSE is reached so that an ADS communication that has already started internally can be terminated.
  • sNetId: To execute the operation on the local device, it is not necessary to specify this input variable. Alternatively, an empty string can be specified. To direct the query to another computer, its AMS Net Id (type T_AmsNetId) can be specified here.
  • tAdsTimeout: Specifies a maximum time to execute the internal ADS communication.
  • sFileName: Specifies the file path of the CSV file being read.
  • sSeparator: Specifies the CSV field separator used in the CSV file. Individual values are thus separated from each other.
  • nHeaderLines: Specifies the number of lines containing only header information. These are skipped during readout. A CSV file saved with the TwinCAT 3 Scope View can contain different amounts of header information.
  • bColumn: Indicates whether the data is located one after the other in a row (bColumn=FALSE) or one below the other as a column in the CSV (bColumn=TRUE). The latter is the case for CSV files that were saved with the TwinCAT 3 Scope View.
  • aBuffer: Specifies the output data buffer to which the read values are written. This must be a type LREAL PLC array of any length. If the FB_CMA_ReadCsvFile is used as an alternative to the hardware sensor signal, the length typically corresponds to the oversampling factor. The specified buffer must be maintained for the duration of the operation. During the operation, the aBuffer buffer is filled several times with new data records and this is signaled via the bBufferFull output variable.

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
  • bBufferFull: The output is TRUE if the aBuffer buffer has been completely filled. This will often be the case for the duration of the operation until the CSV file has been completely read out. If a new data record is available in the aBuffer buffer, it should be processed immediately before the function block is called again. Typically, new data is available in the buffer each time the function block is called. Nevertheless, the bBufferFull output should be checked to ensure a correct data stream.
  • nReadRecords: The output indicates how many values are contained in the entire read dataset.
  • bBusy: The output is TRUE as long as the function block is active. The output is FALSE when the CSV file has been read completely or an error has occurred.
  • bError: The output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
  • ipErrorMessage: Contains more detailed information on the current return value. Refer to the Error description and information section here. This special interface pointer is internally secured so that it is always valid/assigned.

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