FB_CTRL_LOG_DATA (only on a PC system)

FB_CTRL_LOG_DATA (only on a PC system) 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 titles 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 rows. 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 2 s. The files that were generated can be analyzed with a spreadsheet program, for example.

The timestamp 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 (only on a PC system) 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. The external buffer is used if a buffer address and a buffer size different from zero are parameterized. In the absence of an external buffer, an internal buffer with the size of 255 bytes is used.

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 of the type ARRAY OF BYTES larger than 255 bytes.
The individual messages are temporarily stored in the external buffer and this buffer is written to the file as soon 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.

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

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

eMode : Input that specifies the block's operating mode.

VAR_OUTPUT

VAR_OUTPUT
    eState      : E_CTRL_STATE;
    bFileOpen       : BOOL
    bFileClosed     : BOOL
    fBufferUsage    : FLOAT     (* Buffer fill level in percent [0 ... 100] *)
    bBusy       : BOOL
    eErrorId        : E_CTRL_ERRORCODES;
    bError      : BOOL;
END_VAR

eState : State of the function block.

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

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

fBufferUsage : Current fill level of the used buffer in percent.

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

eErrorId : Supplies the error number when the bError output is set.

bError : Becomes TRUE, as soon as an error occurs.

VAR_IN_OUT

VAR_IN_OUT
    stParams        : ST_CTRL_LOG_DATA_PARAMS;
END_VAR

stParams : Parameter structure of the logging block. This consists of the following elements:

TYPE ST_CTRL_LOG_DATA_PARAMS
:
STRUCT
       
tLogCycleTime        : TIME := T#0ms; (* controller cycle time
[TIME] *)
       
tTaskCycleTime       : TIME := T#0ms; (* task cycle time [TIME]
*)

       
sFileName        : STRING;

       
sNetId           : T_AmsNetId := ''; (* ams net id
*)
       
tFileOperationTimeout    : TIME := T#3s; (* file operation timeout
*)

       
nNumberOfColumns     : INT(1..10);

       
arColumnHeadings     : ARRAY [1..10] OF STRING;

       
bAppendData          : BOOL := FALSE;

       
bWriteTimeStamps     : BOOL := TRUE;
       
bWriteColumnHeadings     : BOOL := TRUE;
       
bWriteAbsoluteTimeStamps : BOOL := FALSE; (* Set to true if the
NT-time form the local machine should logged in the first column.
*)
                        
(* The log cycle time must than be greater or equal T#5s!!!
*)

       
pLogBuffer_ADR       : POINTER TO BYTE;
       
nLogBuffer_SIZEOF    : UDINT;
END_STRUCT
END_TYPE

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

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

sFileName : Name and path of the log file, e.g.: d:\Logfile.csv.

sNetId : The file is written on the system with this net id.

tFileOperationTimeout : Timeout for all file operations.

nNumberOfColums: Number of columns written into the file (maximum 10).

arColumnHeadings: Array of strings that contain the column headings.

bAppendData : 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.

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

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

bWriteAsoulteTimeStamps : If true, the NT-time from the local system is used as timestamp. In this case, the minimum log cycle time is 5s!

pLogBuffer_ADR : Address of the external LogBuffer. To be recognised, the buffer's address must be unequal to 0.

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

Note

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

Requirements

Development Environment

Target System

PLC libraries to include

TwinCAT v2.8

PC (i386)

TcControllerToolbox.lib