首页 西门子(Si. 正文

回复

自动控制步序为什么用编码原理的疑问

西门子(Siemens)PLC 浏览:407 回复:1 收藏

eagleking68  2019-09-02 16:33

以前的到过别人的一个程序,S7-1200螺丝机,程序做的确实调理和有序,做的很规范,但是不明白的是为什么在各个自动步序中也是喜欢先复制后编码译码,这样做有什么好处呢?实在是想不明白,为什么不能直接控制流程控制字或位进行自动流程控制呢?只是好监控吗?不应该吧,无论是三菱还是西门子,大点的程序,看到好多都是这么做的。顺便把编码译码的scl程序贴出来。

Input

StepIn Int 0 非保持 True True True False Step No.

Output

StepNoW1 DWord 16#0 非保持 True True True False Step word1

StepNoW2 DWord 16#0 非保持 True True True False Step word2

StepNoW3 DWord 16#0 非保持 True True True False Step word3

StepNoW4 DWord 16#0 非保持 True True True False Step word4

InOut

Static

StepMaskPos Array[0..31] of DInt 在 IDB 中设置 True True True False

Temp

MaskResult DInt

DecodingOut DInt

StepInBuff DInt

Constant

(*

STEP DECODER

STEP NUMBER:0~127

*)

#StepInBuff := INT_TO_DINT(#StepIn);

#MaskResult := #StepInBuff AND 16#001F;

#DecodingOut := #StepMaskPos[#MaskResult];

#StepNoW1 := 0;

#StepNoW2 := 0;

#StepNoW3 := 0;

#StepNoW4 := 0;

IF NOT #StepIn.%X6 AND NOT #StepIn.%X5 THEN

  // Statement section IF

  #StepNoW1 := DINT_TO_DWORD(#DecodingOut);

  #StepNoW1 := SWAP(#StepNoW1);

END_IF;

IF NOT #StepIn.%X6 AND #StepIn.%X5 THEN

  // Statement section IF

  #StepNoW2 := DINT_TO_DWORD(#DecodingOut);

  #StepNoW2 := SWAP(#StepNoW2);

END_IF;


IF #StepIn.%X6 AND NOT #StepIn.%X5 THEN

  // Statement section IF

  #StepNoW3 := DINT_TO_DWORD(#DecodingOut);

  #StepNoW3 := SWAP(#StepNoW3);

END_IF;

IF #StepIn.%X6 AND #StepIn.%X5 THEN

  // Statement section IF

  #StepNoW4 := DINT_TO_DWORD(#DecodingOut);

  #StepNoW4 := SWAP(#StepNoW4);

END_IF;

输入一个整形变量值,对应的MD中的M位就有了输出。程序调用时这么转换。

我知道了