每个块在程序代码(SCL/ST)或块注释(LAD, FBD) 中包含一个块标题栏, 开发过程中最重要信息必须记录在案。开发相关信息将被存放于程序内部, 隐藏在专有技术保护块中。 必须在块属性中提供用户相关信息。即使在专有技术保护的块中, 用户也可以获得此信息。 下面这个块标题栏的模板包含块属性中的元素以及与开发相关的信息, 它们不需要复制到属性中。 模板描述包含以下项目: • (可选)公司名称/(C)版权(年份) 版权所有 • 标题/块描述 • 功能说明 • (可选)库的名称 • 部门/作者/联系人 • 目标系统 - 带固件版本的 PLC(例如, 1516-3 PN/DP v2.6) • 工程环境 - TIA 博途, 包含创建/修改时的博途版本 • 使用限制(例如特定的 OB 类型) • 要求(如附加硬件) • (可选)其他信息 • (可选)包含版本、 日期、 作者和修改说明的修改日志(对于安全块则包含安全签名)
代码语言:javascript复制SCL 中块标题栏的模板:
REGION Description header
//==================================================================================
// (company) / (C) Copyright (year)
//----------------------------------------------------------------------------------
// Title: (Title of this block)
// Comment/Function: (that is implemented in the block)
// Library/Family: (that the source is dedicated to)
// Author: (department / person in charge / contact)
// Target System: (test system with FW version)
// Engineering: TIA Portal (SW version)
// Restrictions: (OB types, etc.)
// Requirements: (hardware, technological package, etc.)
//----------------------------------------------------------------------------------
// Change log table:
// Version | Date | Expert in charge | Changes applied
//-------------|------------|------------------|------------------------------------
// 001.000.000 | yyyy-mm-dd | (name of expert) | First released version
//==================================================================================
END_REGION
实例1
代码语言:javascript复制FUNCTION_BLOCK "EnableTemplate"
TITLE = Enable Template
{ S7_Optimized_Access := 'TRUE' }
AUTHOR : '(author)'
FAMILY : '(family)'
VERSION : 1.0
//Template for an FB with Enable / Valid Handling according to PLC Open "Function Blocks for Motion Control" V2.0
VAR_INPUT
enable { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // TRUE: Enable functionality of FB; 0: Disable
END_VAR
VAR_OUTPUT
busy { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // TRUE: FB is working and new output values can be expected
valid { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // TRUE: Valid set of outputs available at the FB
error { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Rising edge informs that an error occurred during the execution of
status { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Word := #STATUS_NO_CALL; // Current status of FB
END_VAR
VAR
statErrorUserCleared { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Error occured that can only be solved by user; rising edge at enable input necessary
statErrorAutoCleared { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Error occured that can be acknowledged by FB
statEnableOld { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Old value of enable for edge detection
END_VAR
VAR CONSTANT
STATUS_NO_CALL : Word := 16#7000; // No call of FB
STATUS_FIRST_CALL : Word := 16#7001; // First call of FB after enabling
STATUS_SUBSEQUENT_CALL : Word := 16#7002; // Subsequent call of FB
END_VAR
BEGIN
//=============================================================================
//(company)
//(c)Copyright (year) All Rights Reserved
//-----------------------------------------------------------------------------
//Library: (that the source is dedicated to)
//Tested with: (target system with FW Version)
//Engineering: TIA Portal (SW Version)
//Restrictions: (OB types, etc.)
//Requirements: (hardware, technological package, memory needed, etc.)
//Functionality: (that is implemented in the block)
//-----------------------------------------------------------------------------
//Change log table:
//Version Date Expert in charge Changes applied
//01.00.00 dd.mm.yyyy (name of expert) First released version
//=============================================================================
//Check if FB is disabled
IF NOT #enable
AND #statEnableOld
THEN
//TODO : Add functionality after disabling functionality, e.g. closing connections
//--------------------------------------------------------------------------------
//Error outputs are reset with falling edge of enable input
#statErrorUserCleared := FALSE;
#statErrorAutoCleared := FALSE;
#error := FALSE;
#status := #STATUS_NO_CALL;
//Enable and busy are reset with falling edge of enable input
#valid := FALSE;
#busy := FALSE;
//Set old value of enable for edge detection and end execution
#statEnableOld := #enable;
RETURN;
//Check if FB is enabled
ELSIF #enable
AND NOT #statEnableOld
THEN
//TODO: Initialize values after enabling FB, e.g. set state machine to initial state
//-----------------------------------------------------------------------------------
//Busy is set at rising edge of enable input
#busy := TRUE;
//Set status for first call
#status := #STATUS_FIRST_CALL;
//Set old value of enable for edge detection and end execution
#statEnableOld := #enable;
RETURN;
//Check if user cleared error in FB occurred
ELSIF #statErrorUserCleared
THEN
#busy := FALSE;
//Set old value of enable for edge detection and end execution
#statEnableOld := #enable;
//No set of status necessary, because status already set when error occured
RETURN;
//Check if function block is disabled
ELSIF NOT #enable
THEN
#busy := FALSE;
#status := #STATUS_NO_CALL;
//Set old value of enable for edge detection and end execution
#statEnableOld := #enable;
RETURN;
ELSE
//Detect edge for disabling
#statEnableOld := #enable;
END_IF;
//----------------------------------------------------------------------------------------------
//TODO: Add user program
//-----------------------
//Following values have to be set in user program:
// - statErrorUserCleared:
// Error can only be cleared by user; rising edge at enable input is needed to continue
// - statErrorAutoCleared:
// Error is automatically reset by system
// - status:
// Identifier for current appeared error
//
//Following outputs are not allowed to use in user program:
// - busy
// - valid
// - error
//
//Attention:
// - Input parameteres can be updated continously
// - If inputs exceed application limits, system has either to throw an error or to correct it
// automatically
//----------------------------------------------------------------------------------------------
//Error handling
//----------------------------------------------------------------------------------------------
IF #statErrorUserCleared THEN
#valid := FALSE;
#busy := FALSE;
#error := TRUE;
//TODO: Set correct status that identifies error clearly
//#status := ...;
RETURN;
ELSIF #statErrorAutoCleared THEN
#valid := FALSE;
#busy := TRUE;
#error := TRUE;
//TODO: Set correct status that identifies error clearly
//#status := ...;
RETURN;
ELSE
//Process normal output values
#valid := TRUE;
#error := FALSE;
#status := #STATUS_SUBSEQUENT_CALL; //Set status for subsequent call
END_IF;
//----------------------------------------------------------------------------------------------
END_FUNCTION_BLOCK
实例2
代码语言:javascript复制FUNCTION_BLOCK "ExecuteTemplate"
TITLE = Execute Template
{ S7_Optimized_Access := 'TRUE' }
AUTHOR : '(author)'
FAMILY : '(family)'
VERSION : 1.0
//Template for an FB with Execute / Busy / Done Handling according to PLC Open "Function Blocks for Motion Control" V2.0
VAR_INPUT
execute { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Rising edge starts action once
END_VAR
VAR_OUTPUT
busy { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // TRUE: FB is not finished and new output values can be expected
done { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // TRUE: Commanded action has been completed successfully
error { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Rising edge informs that an error occurred during the execution of
status { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Word := #STATUS_NO_CALL; // Current status of FB
END_VAR
VAR
statBusy { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Static value for output busy
statDone { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Static value for output done
statError { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Static value for output error
statExecuteOld { S7_HMI_Accessible := 'False'; S7_HMI_Visible := 'False'} : Bool; // Old value of execute for edge detection
END_VAR
VAR CONSTANT
STATUS_EXECUTION_FINISHED : Word := 16#0000; // Execution finished without errors
STATUS_NO_CALL : Word := 16#7000; // No call of FB
STATUS_FIRST_CALL : Word := 16#7001; // First call of FB after enabling
STATUS_SUBSEQUENT_CALL : Word := 16#7002; // Subsequent call of FB
END_VAR
BEGIN
//=============================================================================
//(company)
//(c)Copyright (year) All Rights Reserved
//-----------------------------------------------------------------------------
//Library: (that the source is dedicated to)
//Tested with: (target system with FW Version)
//Engineering: TIA Portal (SW Version)
//Restrictions: (OB types, etc.)
//Requirements: (hardware, technological package, memory needed, etc.)
//Functionality: (that is implemented in the block)
//-----------------------------------------------------------------------------
//Change log table:
//Version Date Expert in charge Changes applied
//01.00.00 dd.mm.yyyy (name of expert) First released version
//=============================================================================
//Check if FB is triggered
IF #execute
AND NOT #statExecuteOld
// AND NOT #statBusy // Remove the first comment characters if FB should finish current
// job before new job can be started with rising edge of execute
THEN
//TODO: Initialize functionality after triggering FB, e.g. reset of values
//-----------------------------------------------------------------------------------
//Functionality is busy
#statBusy := TRUE;
//Reset other outputs
#statError := FALSE;
#status := #STATUS_FIRST_CALL;
#busy := #statBusy;
#error := #statError;
#statExecuteOld := #execute;
RETURN;
//FB is currently inactive
ELSIF NOT #execute
AND NOT #statBusy
THEN
//Error outputs are reset with falling edge of enable input
#statError := FALSE;
//Done and busy are reset with falling edge of enable input
#statDone := FALSE;
#statBusy := FALSE;
//Write outputs
#done := #statDone;
#busy := #statBusy;
#error := #statError;
#status := #STATUS_NO_CALL;
#statExecuteOld := #execute;
RETURN;
//FB is currently executed and not finished
ELSIF #statBusy
THEN
#statExecuteOld := #execute;
//FB finished job
ELSE
#statExecuteOld := #execute;
RETURN; //Wait for start of functionality
END_IF;
//----------------------------------------------------------------------------------------------
//TODO: Add user program
//-----------------------
//Following values have to be set in user program:
// - statDone:
// FB is finished with execution
// - statError:
// Error happened in program
// - status:
// Identifier for current error
//
//Following values are not allowed to use in user program:
// - statBusy
// - busy, done and error
//
//Attention:
// - Input parameters can be updated continously
// - If inputs exceed application limits, system has either to throw an error or to correct it
// automatically
//----------------------------------------------------------------------------------------------
//Write ouputs and error handling
//----------------------------------------------------------------------------------------------
//Error occured in request
IF #statError
THEN
#statDone := FALSE;
#statBusy := FALSE;
//TODO: Set correct status that identifies error clearly
//#status := ...;
//Request finished
ELSIF #statDone
THEN
#statBusy := FALSE;
#statError := FALSE;
#status := #STATUS_EXECUTION_FINISHED;
//Request in execution
ELSE
#status := #STATUS_SUBSEQUENT_CALL;
END_IF;
//Write static values to outputs
#done := #statDone;
#busy := #statBusy;
#error := #statError;
//----------------------------------------------------------------------------------------------
END_FUNCTION_BLOCK