plc扫描周期读取源码
FUNCTION_BLOCK PlcCycle
VAR_OUTPUT
plc_Cycle : REAL;//PLC扫描周期
END_VAR
VAR
init: BOOL;
tx: DWORD;
last: DWORD;
END_VAR
程序
(* read system timer *)
tx := T_PLC_US();
IF NOT init THEN
init := TRUE;
plc_Cycle := 0.0;
ELSE
plc_Cycle := (DWORD_TO_REAL(tx - last)*1.0E-6)*1000;
END_IF;
last := tx;
程序里用到的函数
FUNCTION T_PLC_US : DWORD
VAR CONSTANT
debug : BOOL := 0;
N : INT := 0;
offset : DWORD := 0;
END_VAR
VAR
tx : TIME;
END_VAR
tx := TIME();
T_PLC_US := TIME_TO_DWORD(Tx)*1000;
IF debug THEN
T_PLC_US := (SHL(T_PLC_US,N) OR SHL(DWORD#1,N)-1) + OFFSET;
END_IF;
页:
[1]