FB_CTRL_LOG_DATA

FB_CTRL_LOG_DATA 1:

This function block allows a log file to be created in *.csv format (comma separated values), in which a maximum of 10 variables may be recorded. The column headings specified by the user are written in the first row of this file. The input data is written at equal time intervals in the following lines. The individual entries are separated by a comma. The time interval between the entries is specified in the tLogCycleTime parameter. If, for instance, tLogCycleTime := T\#2s is chosen, then an entry is made in the file every 2s. The files that were generated can be analyzed with a spreadsheet program, for example.

The time stamp of the log entry, in s, is stored in the first column of the file. The other columns contain the data of the function block input fLogData.

FB_CTRL_LOG_DATA 2:

When the mode is set to eCTRL_MODE_ACTIVE the log file is opened and entries are written into the file. The file remains open until the function block's mode is set to eCTRL_MODE_PASSIVE.

It is essential that the file is closed by switching into eCTRL_MODE_PASSIVE before attempting to analyze the log file. If this is not done, it is possible that not all the entries will be written into the file.

The function block makes it possible to work with or without an external buffer.

Operating without an external buffer:

The bBusy output is TRUE when the logging of a row has been started. The following data set will not be logged until the bBusy output is FALSE again. The fBufferUsage output indicates how full the internal buffer is.

Operating with an external buffer:

The user must create a buffer larger than 255 bytes and with the type ARRAY OF BYTES.
The individual messages are temporarily stored in the external buffer, and this buffer is written into the file as quickly as possible. The fBufferUsage output indicates how full the buffer is. The function block is stopped and an error is output if the buffer overflows.

FB_CTRL_LOG_DATA 3:

The external buffer is used if a buffer address and a buffer size greater than zero are parameterized. In the absence of an external buffer, an internal buffer with the size of 255 bytes is used.

FB_CTRL_LOG_DATA 4: VAR_INPUT

VAR_INPUT
    fLogData  : T_CTRL_LOGGER_DATA;
    eMode     : E_CTRL_MODE;
END_VAR

VAR_GLOBAL CONSTANT
    nCTRL_LOGGER_DATA_ARRAY_SIZE  : UINT := 10;
END_VAR

TYPE T_CTRL_LOGGER_DATA :
    ARRAY [1..nCTRL_LOGGER_DATA_ARRAY_SIZE] OF FLOAT;
END_TYPE

Name

Type

Description

fLogData

T_CTRL_
LOGGER_DATA

Array containing the values that are to be written into the log file.

eMode

E_CTRL_MODE

Input that specifies the operation mode of the function block.

FB_CTRL_LOG_DATA 5: VAR_OUTPUT

VAR_OUTPUT
    eState        : E_CTRL_STATE;
    bFileOpen     : BOOL
    bFileClosed   : BOOL
    fBufferUsage  : FLOAT
    bBusy         : BOOL
    eErrorId      : E_CTRL_ERRORCODES;
    bError        : BOOL;
END_VAR

Name

Type

Description

eState

E_CTRL_STATE

State of the function block

bFileOpen

BOOL

A TRUE at this output indicates that the file has successfully been opened.

bFileClosed

BOOL

A TRUE at this output indicates that the file has successfully been closed.

fBufferUsage

FLOAT

Current fill level of the external buffer as a percentage

bBusy

BOOL

A TRUE at this output indicates that logging a row is active.

eErrorId

E_CTRL_ERRORCODES

Supplies the error number when the output bError is set.

bError

BOOL

Becomes TRUE, as soon as an error occurs.

VAR_IN_OUT

VAR_IN_OUT
    stParams        : ST_CTRL_LOG_DATA_PARAMS;
END_VAR

Name

Type

Description

stParams

ST_CTRL_LOG_DATA_PARAMS

Parameter structure of the logging function block

stParams consists of the following elements:

TYPE ST_CTRL_LOG_DATA_PARAMS:
STRUCT
    tLogCycleTime             : TIME := T#0ms;
    tTaskCycleTime            : TIME := T#0ms;
    sFileName                 : STRING;
    sNetId                    : T_AmsNetId := '';
    tFileOperationTimeou      : TIME := T#3s;
    nNumberOfColumn           : INT(1..10);
    arColumnHeadings          : ARRAY [1..10] OF STRING;
    bAppendData               : BOOL := FALSE;
    bWriteTimeStamps          : BOOL := TRUE;
    bWriteColumnHeadings      : BOOL := TRUE;
    bWriteAbsoluteTimeStamps  : BOOL := FALSE
    pLogBuffer_ADR            : POINTER TO BYTE;
    nLogBuffer_SIZEOF         : UDINT;
END_STRUCT
END_TYPE

Name

Type

Description

tLogCycleTime

TIME

Cycle time with which entries are written into the log file. This must be greater than or equal to the TaskCycleTime.

tTaskCycleTime

TIME

Cycle time with which the function block is called. If the function block is called in every cycle this corresponds to the task cycle time of the calling task.

sFileName

STRING

Name and path of the log file, for example: d:\Logfile.csv

sNetId

T_AmsNetId

The log file is written to the system with the NetId specified here.

tFileOperation
Timeou

TIME

Timeout for all file operations

nNumberOf
Column

INT

Number of columns written into the file (maximum 10)

arColumn
Headings

ARRAY

Array of strings that contain the column headings.

bAppendData

BOOL

If this parameter is TRUE, then new data sets are appended when a file is opened again. Otherwise the file is overwritten without query, and this will delete any content that already exists.

bWriteTime
Stamps

BOOL

If this parameter is set to TRUE, the time stamp of the measurement is written into the first column of the file.

bWriteColumn
Headings

BOOL

If this parameter is set to TRUE, the column headers are written into the first row of the file.

bWriteAbsolute
TimeStamps

BOOL

If this parameter is set to TRUE, the local NT time is used as timestamp. In this case the minimum LogCycleTime is 5s!

pLogBuffer_ADR

POINTER TO BYTE

Address of the external LogBuffer. To detect a buffer, the address must not be 0.

nLogBuffer_
SIZEOF

UDINT

Size of the LogBuffer. The buffer must be an ARRAY OF BYTE with at least 256 elements. The size of the buffer can be optimized with the aid of the fBufferUsage output.

Notice

Error during file handling

The parameter set can only be changed when the file is closed (bFileClosed = TRUE). Otherwise errors can occur during file handling.