FB_AmsLogger
The "TwinCAT AMS Logger" belongs to the components of the "TwinCAT ADS Monitor" (..\TwinCAT\AdsMonitor\Logger\TcAmsLog.exe). The logger charts the AMS/ADS commands to a data medium. The chart can for e.g. be displayed by "TwinCAT AMS ADS Viewer" and analysed for debugging. The record of the "TwinCAT AMS Logger" can be started or stopped from the PLC program using the instance of function block "FB_AmsLogger". The instance of TcAmsLog.exe have allready be existing and running. Please use start menue command or e.g. NT_StartProcess function block to start an instance of TcAmsLog.exe.
VAR_INPUT
VAR_INPUT
sNetId : T_AmsNetId:= '';
eMode : E_AmsLoggerMode := AMSLOGGER_RUN;
sCfgFilePath: T_MaxString := '';
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
sNetId: It is possible here to provide the network address of the TwinCAT computer on which the "TwinCAT AMS Logger" state is to be changed. If the logger state is to be changed on the local computer, an empty string can be entered.
eMode: New "TwinCAT AMS Logger" state to set.
sCfgFilePath: (Optionally) Path of the "TwinCAT AMS Logger" configuration file. Currently not used and reserved for future use (enter empty string).
bExecute: The function block is activated by a positive edge at this input.
tTimeout: States the length of the timeout that may not be exceeded by execution of the ADS command.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
END_VAR
bBuse: When the function block is activated this output is set. It remains set until and acknowledgement is received.
bError: If an ADS error should occur during the transfer of the command, then this output is set once the BUSY output is reset.
nErrId: Supplies the ADS error number when the ERR output is set.
Example:
The sample program starts new instance of TcAmsLog.exe and the record chart. Setting bRecord to FALSE stopps the recording.
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 system type | PLC libraries to include |
---|---|---|
TwinCAT v2.8.0 Build > 747 TwinCAT v2.9.0 Build >= 959 | PC or CX (x86) | TcUtilities.Lib (Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically) |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) |