FB_CSVMemBufferWriter
This function block can be used to generate data sets in an external buffer in CSV format from individual data fields. The content of the buffer can then be written into a file, e.g. with the aid of the function blocks for file access. The new data field can be transferred to the function block either via the putValue variable(string) or via the optional pValue and cbValue variables. This depends on whether you want to write data fields without control characters (string) or data fields with control characters or binary data to the data set. The function block can generate several data sets in the buffer until the maximum available buffer size is reached. The end of the data set (last data field in the current data set) is automatically appended to the data field if the bCRLF variable was set to TRUE during writing of the data field. The function block automatically adds the data field separators. The default data field separator is a semicolon. The separator can be configured from semicolon to comma via the global PLC variable DEFAULT_CSV_FIELD_SEP.
Inputs
VAR_INPUT
eCmd : E_EnumCmdType := eEnumCmd_First;
putValue : T_MaxString := '';
pValue : POINTER TO BYTE := 0;
cbValue : UDINT := 0;
bCRLF : BOOL := FALSE;
pBuffer : POINTER TO BYTE;
cbBuffer : UDINT;
END_VAR
Name | Type | Description |
---|---|---|
eCmd | eEnumCmd_First adds the first data field to the buffer, eEnumCmd_Next adds the next data field. No other parameter values are used. | |
putValue | T_MaxString | A new data field as string. This input must be an empty string if the optional parameters pValue and cbValue are used instead of this input. |
pValue | BYTE | Optional: Address of an external byte buffer containing the new data field. Together with the cbValue parameter this input can then be used to write a data field with control characters or binary data into the data set, for example. Control characters or binary data in the data field could truncate the putValue string at an undesired position and are therefore transferred as a byte buffer. This input must be null if it is not used. |
cbValue | UDINT | Optional: Length of the data field data in the external byte buffer. This input must be null if it is not used. The maximum size can be specified with the global parameter cMaxCSVFieldValueSize. |
bCRLF | BOOL | If this input is set the new data field is terminated with a CRLF data set separator. Subsequent data fields belong to the new data set. |
pBuffer | BYTE | Address (pointer) for the destination buffer variable. The address can be determined with the ADR operator. In this buffer the function block generates the data sets in CSV format. |
cbBuffer | UDINT | Maximum available size (in bytes) of the destination buffer variables. The size can be determined with the SIZEOF operator |
Outputs
VAR_OUTPUT
bOk : BOOL;
cbSize : UDINT;
cbFree : UDINT;
nFields : UDINT;
nRecords : UDINT;
cbWrite : UDINT;
END_VAR
Name | Type | Description |
---|---|---|
bOk | BOOL | TRUE = success, FALSE = buffer overflow or faulty input parameters. |
cbSize | UDINT | Current buffer fill status (number of data bytes created in the buffer). |
cbFree | UDINT | Number of free data bytes in the buffer. |
nFields | UDINT | Number of written data fields. |
nRecords | UDINT | Number of written data sets. |
cbWrite | UDINT | Number of last written data bytes (length of the last data field + any data set or data field separators). |
Requirements
Development environment |
Target platform |
PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.0 |
PC or CX (x86, x64, ARM) |
Tc2_Utilities (System) |