SCL编写模拟量监视功能块,用于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 零点死区 ADCT : REAL:=0.0; // Alarm delay coming time 报警延迟到达时间 WDCT : REAL:=0.0; // Warning delay coming time警告延迟到达时间 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'} WORD:=DW#16#0; MsgEvID2 {S7_a_type:='alarm_s';S7_server:='alarm_archiv'} WORD:=DW#16#0; MsgEvID3 {S7_a_type:='alarm_s';S7_server:='alarm_archiv'} WORD:=DW#16#0; MsgEvID4 {S7_a_type:='alarm_s';S7_server:='alarm_archiv'} WORD:=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状态字 QabyState AT QdwState : ARRAY [0..3] OF BYTE; // look at state byte-wise QdwPerm {S7_m_c:='true'}: DWORD :=16#FFFFFFFF; // Permssion word wincc权限字 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 //高高报警到达 QHW : BOOL := FALSE; // H Warning is Active//高警告到达 QLW : BOOL := FALSE; // L Warning is Active//低警告到达 QLLA : BOOL := FALSE; // L Alarm is Active//低低警告到达 QHys : REAL := 0.0; //滞后值
END_VAR
VAR //操作命令高低字节交换需要,以及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;
//状态字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
//权限字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 //警告及报警延时到达或离开计时器 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; //运行周期预设值 //Message MsgEffOld:BYTE:=B#16#0; //消息字节状态存储 MsgEff:BYTE:=B#16#0; //当前消息字节 MsgEff1 AT MsgEff :ARRAY[0..7]OF BOOL; END_VAR
VAR_TEMP iRet1,iRet2,iRet3,iRet4:INT; END_VAR
-
|