FB_ScopeServerControl

FB_ScopeServerControl 1:

The function block FB_ScopeServerControl enables the PLC to collect data for subsequent display with TwinCAT Scope 2.

FB_ScopeServerControl 2: Inputs

VAR_INPUT
    sNetId      : T_AmsNetId;
    eReqState   : E_ScopeServerState := SCOPE_SERVER_IDLE;
    sConfigFile : STRING;
    sSaveFile   : STRING;
    tTimeout    : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

Name

Type

Description

sNetID

T_AmsNetID

A string containing the network address of the TwinCAT target system can be specified here. For the local computer an empty string may be specified.

eReqState

E_ScopeServerState

Requested scope server status

sConfigFile

STRING

Full path with the name of the configuration file (e.g.: C:\TwinCAT\TwinCATScope2\First.sv2').

sSaveFile

STRING

Full path with the name of the data file (e.g.: C:\TwinCAT\TwinCATScope2\First.svd).

tTimeout

TIME 

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

FB_ScopeServerControl 3: Outputs

VAR_OUTPUT
    bBusy    : BOOL;
    bDone    : BOOL;
    bError   : BOOL;
    nErrorId : 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.

bDone

BOOL

Is set if the requested status was activated.

bError

BOOL

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

nErrorId

UDINT

Shows the error number if the error output bError is set. As a rule this can be an ADS error number or a specific error code of this library.

FB_ScopeServerControl 4:

Only one target system is permitted for the configuration file (*.sv2).

State diagram:

FB_ScopeServerControl 5:

*) to reset State Change is always possible

This state diagram shows the possible transitions for eReqState. If there is an other state change requested bError will be set.

TYPE E_ScopeServerState

TYPE E_ScopeServerState
(
   SCOPE_SERVER_IDLE,
   SCOPE_SERVER_CONNECT,
   SCOPE_SERVER_START,
   SCOPE_SERVER_STOP,
   SCOPE_SERVER_SAVE,
   SCOPE_SERVER_DISCONNECT,
   SCOPE_SERVER_RESET
);

Example:

Declaration part:

FUNCTION_BLOCK FB_ScopeServerSample
VAR_INPUT
    bExternalTriggerEvent: BOOL := FALSE;
END_VAR
VAR_OUTPUT
END_VAR
VAR
    fbScopeServerControl: FB_ScopeServerControl;
    eReqState: E_ScopeServerState := SCOPE_SERVER_IDLE;
    bBusy: BOOL := FALSE;
    bDone: BOOL := FALSE;
    bError: BOOL := FALSE;
    nErrorId: UDINT := 0;
    fbTimer: TON;
    bTriggerTimer: BOOL := FALSE;
    nState: UDINT := 0;
END_VAR

Implementation of the FB_ScopeServerSample

CASE nState OF
0:
    eReqState := SCOPE_SERVER_START;
    nState := 10;
10:
    IF fbScopeServerControl.bDone AND bExternalTriggerEvent
    THEN
        bTriggerTimer := TRUE;
        nState := 20;
    END_IF
20:
    IF fbTimer.Q THEN
        eReqState := SCOPE_SERVER_SAVE;
        bTriggerTimer := FALSE;
        nState := 30;
    END_IF
30:
    IF fbScopeServerControl.bDone THEN
        eReqState := SCOPE_SERVER_DISCONNECT;
    END_IF
END_CASE
fbTimer(IN:=bTriggerTimer, PT:=t#10s);
fbScopeServerControl( sNetId:= '',
                      eReqState:= eReqState,
                      sConfigFile:= 'C:\twinCat\scope\test.sv2',
                      sSaveFile:= 'C:\twinCat\scope\test.svd',
                      tTimeout:= t#5s,
                      bBusy=>bBusy,
                      bDone=>bDone,
                      bError=>bError,
                      nErrorId=>nErrorId);

This example demonstrates how a long-term recording with the Scope Server can be executed.

The existing configuration (Test.sv2) is loaded for this purpose. In this example Test.sv2 was stored in order to run in the ring buffer. Data logging will not finish until it is triggered by FB_ScopeServerControl. If an internal trigger event (this could be an error event) occurs, a timer is started, and 10 seconds later the data are saved in Test.svd. In this way the data file contains information from before and after the trigger event.

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)