技術(shù)文章
SCL編寫模擬量監(jiān)視功能塊,用于S7-300
閱讀:4155 發(fā)布時間:2016-9-19SCL編寫模擬量監(jiān)視功能塊,用于S7-300
//編譯選項
//Compile options
{
Scl_OverwriteBlocks:= 'y' ;
Scl_CreateObjectCode:= 'y' ;
Scl_OptimizeObjectCode:= 'y' ;
Scl_MonitorArrayLimits:= 'y' ;
Scl_CreateDebugInfo := 'y'
}
FUNCTION_BLOCK MonAn
TITLE='Analog Monitoring'
NAME:MonAn
FAMILY:MyLib
AUTHOR:NC
VERSION:'1.0'
// KNOW_HOW_PROTECT
VAR_INPUT
PV : REAL := 0.0; //Process Value
PV_Unit {S7_m_c:='true'} : INT:=1001 ; // Unit 單位
SimOn: BOOL := FALSE; //Simalation On 仿真打開
SimPV{S7_m_c:='true'} : REAL := 0.0; // Simulation Value 仿真值
PVHR {S7_m_c:='true'} : REAL := 100.0; // high range 過程值量程上限
PVLR {S7_m_c:='true'} : REAL := 0.0; // low range過程值量程下限
HHA {S7_m_c:='true'} : REAL := 95.0; // H limit Alarm 高高報警
HW {S7_m_c:='true'} : REAL := 90.0; // H limit Warning 高警告
LW {S7_m_c:='true'} : REAL := 10.0; // L limit Warning 低警告
LLA {S7_m_c:='true'} : REAL := 5.0; // L Limit Alarm 低低報警
HHA_EN : BOOL := TRUE; // H Alarm Message Enable 高高報警消息使能
HW_EN : BOOL := TRUE; // H Warning Message Enable 高警告消息使能
LW_EN : BOOL := TRUE; // L Warning Message Enable 低警告消息使能
LLA_EN : BOOL := TRUE; // L Alarm Message Enable 低低報警消息使能
Hys {S7_m_c:='true'} : REAL:=0.0; // Hysterese value 滯后
Deadband {S7_m_c:='true'} : REAL:=0.0 ; // Width of Dead band 零點死區(qū)
ADCT : REAL:=0.0; // Alarm delay coming time 報警延遲到達(dá)時間
WDCT : REAL:=0.0; // Warning delay coming time警告延遲到達(dá)時間
ADGT : REAL:=0.0; // Alarm delay going time警告延遲離開時間
WDGT : REAL:=0.0; // Warning delay going time報警延遲離開時間
SAMPLE_T : REAL := 0.2; // Sampletime采樣時間
PULSE : BOOL;//脈沖輸入
//消息事件ID號
MsgEvID1 {S7_a_type:='alarm_s';S7_server:='alarm_archiv'} :DWORD:=DW#16#0;
MsgEvID2 {S7_a_type:='alarm_s';S7_server:='alarm_archiv'} :DWORD:=DW#16#0;
MsgEvID3 {S7_a_type:='alarm_s';S7_server:='alarm_archiv'} :DWORD:=DW#16#0;
MsgEvID4 {S7_a_type:='alarm_s';S7_server:='alarm_archiv'} :DWORD:=DW#16#0;
SD1 :ANY;
SD2 :ANY;
SD3 :ANY;
SD4 :ANY;
END_VAR
VAR_IN_OUT
OP_dwCmd {S7_m_c:='true'} : DWORD :=16#0; // control word wincc操作命令
END_VAR
VAR_OUTPUT
QdwState{S7_m_c:='true'} : DWORD:=0; // Status WinCC狀態(tài)字
QabyState AT QdwState : ARRAY [0..3] OF BYTE; // look at state byte-wise
QdwPerm {S7_m_c:='true'}: DWORD :=16#FFFFFFFF; // Permssion word wincc權(quán)限字
QabyPerm AT QdwPerm: ARRAY [0..3] OF BYTE;
PV_OUT {S7_m_c:='true';S7_archive:='shortterm'} : REAL := 0.0; // Process Value out
QHHA : BOOL := FALSE; // H Alarm is Active //高高報警到達(dá)
QHW : BOOL := FALSE; // H Warning is Active//高警告到達(dá)
QLW : BOOL := FALSE; // L Warning is Active//低警告到達(dá)
QLLA : BOOL := FALSE; // L Alarm is Active//低低警告到達(dá)
QHys : REAL := 0.0; //滯后值
END_VAR
VAR
//操作命令高低字節(jié)交換需要,以及AT指令拆分DWORD為32個BOOL變量
OPdwCmdHMI : DWORD := 16#0; // Operator Commands in HMI format
OPabyCmdHMI AT OPdwCmdHMI : ARRAY [0..3] OF BYTE; // look at HMI command byte-wise
OPdwCmdPLC : DWORD := 16#0; // Operator Commands in PLC format
OPabyCmdPLC AT OPdwCmdPLC : ARRAY [0..3] OF BYTE; // look at plc command byte-wise
OPabCmdPLC AT OPdwCmdPLC : ARRAY [0..31] OF BOOL;
//狀態(tài)字AT指令拆分DWORD為32個BOOL變量
QdwStatePLC : DWORD := 16#0; // State word in PLC format
QabyStatePLC AT QdwStatePLC : ARRAY [0..3] OF BYTE; // look at state byte-wise
QabStatePLC AT QdwStatePLC : ARRAY [0..31] OF BOOL; // look at state bit-wise
//權(quán)限字AT指令拆分DWORD為32個BOOL變量
QdwPermPLC : DWORD := 16#FFFFFFFF;
QabyPermPLC AT QdwPermPLC : ARRAY [0..3] OF BYTE; // look at state byte-wise
QabPermPLC AT QdwPermPLC : ARRAY [0..31] OF BOOL; // look at state bit-wise
//警告及報警延時到達(dá)或離開計時器
ADCT1 : REAL:= 0.0; // Alarm delay coming time
WDCT1 : REAL:= 0.0; // Warning delay coming time
ADGT1 : REAL:= 0.0; // Alarm delay going time
WDGT1 : REAL:= 0.0; // Warning delay going time
FP_Pulse:BOOL; //脈沖上升沿
FP_1,FP_2,FP_3,FP_4:BOOL;
HHLLA_C,HHLLA_G,HLW_G,HLW_C:BOOL;
// First scan
FstScan : BOOL := TRUE; //掃描
RunUpCyc: INT := 5; //運行周期預(yù)設(shè)值
//Message
MsgEffOld:BYTE:=B#16#0; //消息字節(jié)狀態(tài)存儲
MsgEff:BYTE:=B#16#0; //當(dāng)前消息字節(jié)
MsgEff1 AT MsgEff :ARRAY[0..7]OF BOOL;
END_VAR
VAR_TEMP
iRet1,iRet2,iRet3,iRet4:INT;
END_VAR