FB_ScopeServerControl
[This documentation is preliminary and subject to modifications]
- As of library version 2.0.52
- Requires the installation of the TwinCAT Scope Server, which is delivered with the TwinCAT Scope View 2.
The function block "FB_ScopeServerControl" enables the PLC to collect data for subsequent display with TwinCAT Scope View 2.
VAR_INPUT
VAR_INPUT
sNetId: T_AmsNetId;
eReqState: E_ScopeServerState := SCOPE_SERVER_IDLE;
sConfigFile: STRING;
sSaveFile: STRING;
tTimeout: TIME := DEFAULT_ADS_TIMEOUT;
ND_VAR
sNetId:Here a string containing the network address of the target TwinCAT Computer can be given. The string can also be empty for the local computer.
eReqState:: Requested Scope Server state.
sConfigFile:: The full path with the name of the configuration file (e.g.: 'C:\TwinCAT\TwinCATScopeView2\First.sv2' ).
sSaveFile: The full path with the name of the data file (e.g.: 'C:\TwinCAT\TwinCATScopeView2\First.svd').
tTimeout:: Maximum time allowed for the internal ADS commands
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bDone : BOOL
bError : BOOL;
nErrorId : UDINT;
END_VAR
bBusy: if the function block is activated, this output is set. It remains set until a feedback is received.
bDone: is set if the requested status was activated.
bError: if an ADS error should occur during the transmission of the command, this output is set after the bBusy output has been reset.
nErrorId: shows the error number if the error output is set. As a rule this can be an ADS error number or a specific error code of this library.
![]() | Only one target system is permitted for the configuration file (*.sv2). |
Status diagram:

*) resetting a state change is possible at any time
This status diagram shows the possible transitions for eReqState. If another state transition is requested, bError is set.
TYPE E_ScopeServerState
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 in ST:
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 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 sample should show, how a long-term data logging with the Scope Server could be handled.
Therefore an existing configuration (Test.sv2) is loaded. In this sample Test.sv2 was saved to run in Ring Buffer. So, data logging will not stopped until it is triggered by FB_ScopeServerControl. If there is an external trigger event (that could be an error event), a timer is started and 10 seconds later the data is saved in Test.svd. On that way the data file holds an information about what happens before and after the trigger event.
Requirements
Development environment | Target system type | PLC libraries to include |
---|---|---|
TwinCAT v2.10.0 Build >= 1329 | PC or CX (x86,ARM) | TcUtilities.Lib (Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically) |