FB_AmsLogger

FB_AmsLogger 1:

The "TwinCAT AMS Logger" is a component of the "TwinCAT ADS Monitor" (..\TwinCAT\AdsMonitor\Logger\TcAmsLog.exe). The logger records the AMS/ADS commands on the data carrier. The recording can be displayed and analyzed later, e.g. during troubleshooting with the "TwinCAT AMS ADS Viewer".
The FB_AmsLogger function block can be used to start or stop the recording from a PLC program. The FB_AmsLogger function block can only communicate with an existing/running instance of TcAmsLog.exe. In other words, TcAmsLog.exe must already have been started, e.g. manually via the Start menu or via the NT_StartProcess function block.

FB_AmsLogger 2: Inputs

VAR_INPUT
    sNetId       : T_AmsNetId := '';
    eMode        : E_AmsLoggerMode := AMSLOGGER_RUN;
    sCfgFilePath : T_MaxString := '';
    bExecute     : BOOL;
    tTimeout     : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

Name

Type

Description

sNetId

T_AmsNetID

The network address of the TwinCAT computer on which the status of the "TwinCAT AMS Logger" should be modified can be specified here. An empty string can be specified for the logger on the local computer.

eMode

E_AmsLoggerMode

The new status to which the "TwinCAT AMS Logger" is to be set (start/stop recording).

sCfgFilePath

T_MaxString

(Optional) path for a "TwinCAT AMS Logger" configuration file. Currently not yet implemented and reserved for future applications (enter an empty string).

bExecute

BOOL

The function block is enabled by a positive edge at this input.

tTimeout

TIME 

States the length of the timeout that may not be exceeded by execution of the ADS command.

FB_AmsLogger 3: Outputs

VAR_OUTPUT
    bBusy  : BOOL;
    bError : BOOL;
    nErrId : UDINT;
END_VAR

Name

Type

Description

bBusy

BOOL

When the function block is enabled, this output is set and remains set until a feedback is received.

bError

BOOL

If an error occurs during the transmission of the command, this output is set after the bBusy output is reset.

nErrId

UDINT

Returns the ADS error number when the bError output is set.

Example:

When the PLC program starts an instance of TcAmsLog.exe is started on a local system. When the bRecord variable is set to TRUE, the recording of the AMS/ADS command is started. It is stopped when the variable is reset to FALSE.

Declaration part:

PROGRAM MAIN
VAR
    bRecord        : BOOL := TRUE;(* TRUE => start recording, FALSE => stop recording *)
    fbStartProcess : NT_StartProcess := ( NETID := '', PATHSTR: = 'c:\TwinCAT\AdsMonitor\Logger\TcAmsLog.exe',
                                      DIRNAME:= 'c:\TwinCAT\AdsMonitor\Logger', COMNDLINE := '', TMOUT := DEFAULT_ADS_TIMEOUT );
    fbAmsLogger    : FB_AmsLogger := ( sNetID := '', eMode := AMSLOGGER_STOP, sCfgFilePath := '', tTimeout := DEFAULT_ADS_TIMEOUT );
    state          : BYTE;
    bBusy          : BOOL;
    bError         : BOOL;
    nErrID         : UDINT;
    eCurrMode      : E_AmsLoggerMode := AMSLOGGER_STOP;(* Current mode/state *)
    eNewMode       : E_AmsLoggerMode := AMSLOGGER_STOP;(* New mode/state *)
    timer          : TON := ( PT := T#5s );
END_VAR

Implementation:

CASE state OF
0:(* Start instance of TcAmsLogger.exe *)
    fbStartProcess( START := FALSE );
    fbStartProcess( START:= TRUE );
    state := 1;

1:(* Wait until command execution started *)
    fbStartProcess( START := FALSE, BUSY=>bBusy, ERR=>bError, ERRID=>nErrID );
    IF NOT bBusy THEN
        IF NOT bError THEN(* Success *)
            state := 2;
        ELSE(* Error *)
            state := 100;
        END_IF
    END_IF

2:(*Wait until instance started or new AMS logger mode/state set *)
    timer( IN := TRUE );
    IF timer.Q THEN
        timer( IN := FALSE );
        state := 3;
    END_IF

3:(* Change TcAmsLog.exe mode/state *)
    eNewMode := SEL( bRecord, AMSLOGGER_STOP, AMSLOGGER_RUN);
    IF ( eNewMode <> eCurrMode ) THEN
        fbAmsLogger( bExecute := FALSE );
        fbAmsLogger( eMode:= eNewMode, bExecute := TRUE );
        state := 4;
    END_IF

4:(* Wait until command execution started *)
    fbAmsLogger( bExecute := FALSE, bBusy=>bBusy, bError=>bError, nErrID=>nErrID );
    IF NOT bBusy THEN
        IF NOT bError THEN(* Success *)
            eCurrMode := eNewMode;
            state := 2;
        ELSE(* Error *)
            state := 100;
        END_IF
    END_IF

100:(* Error state *)
    ;
END_CASE

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)