FB_CMA_ReadCsvFile
Reading of a CSV file and sequential output of the data into a PLC buffer (array).
Data can be recorded, displayed and saved with the TwinCAT 3 Scope. One possible storage format is CSV. Thus, signal data can be stored in a CSV file and read in again later with the FB_CMA_ReadCsvFile. The signal data read in can be transferred as an alternative source of input data to an instance of FB_CMA_Source and thus to the Condition Monitoring analysis chain.
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 inputbExecute
, if the function block is not already active.bAbort
: The execution is aborted if this input is set. The function block must still be called until the outputbBusy=FALSE
, so that an ADS communication that has already started internally can be terminated.sNetId
: No specification of these input variables is required in order to perform the operation on the local device. Alternatively, an empty string can be specified. To direct the query to another computer, its AMS Net Id (of 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 to be read.sSeparator
: Specifies the CSV field separator used in the CSV file. Individual values are hereby separated from each other.nHeaderLines
: Specifies the number of rows in which there is only header information. These are skipped when reading out. A CSV file saved with the TwinCAT 3 Scope View can contain different amounts of header information.bColumn
: Indicates whether the data are located in a row one after the other (bColumn=FALSE
) or underneath one another as a column in the CSV (bColumn=TRUE
). The latter is the case with CSV files that have been saved with the TwinCAT 3 Scope View.aBuffer
: Specifies the output data buffer into which the read values are written. This must be a PLC array of the type LREAL of any length. If theFB_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 over the duration of the operation. During the operation, the bufferaBuffer
is filled several times with new data sets and this is signaled via the output variablebBufferFull
.
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 isTRUE
if the bufferaBuffer
has been completely filled. This will often be the case over the duration of the operation until the CSV file has been read out completely. If a new data set is present in the bufferaBuffer
, it should be processed immediately before the function block is called again. Typically, after each call to the function block, new data is available in the buffer. Nevertheless, the outputbBufferFull
should be checked to ensure a correct data stream.nReadRecords
: The output indicates how many values the entire read data set contained.bBusy
: The output isTRUE
as long as the function block is active. The output becomesFALSE
if the CSV file has been read in full or an error occurred.bError
: The output isTRUE
if an error occurs.hrErrorCode
: If an error occurs, a corresponding error code of the typeHRESULT
is output. Possible values are described in the List of error codes.ipErrorMessage
: Contains more detailed information on the current return value. Refer here to the section Error description and information. This special interface pointer is internally secured so that it is always valid/assigned.