回复:在逻辑运算中纯DI触点投入/切除功能、改变DI触点类型功能的软实现

已锁定

'Razor

西门子1847工业学习平台

  • 帖子

    3558
  • 精华

    46
  • 被关注

    234

论坛等级:至圣

注册时间:2008-03-31

钻石 钻石 如何晋级?

发布于 2025-02-02 22:10:09

18楼

AI助手还是可以干点活的,代码调优。

FUNCTION "FC_NewCalculateAND" : Void

{ S7_Optimized_Access := 'TRUE' }

VERSION : 0.1

   VAR_OUTPUT 

      ob_error : Bool;

      oStr_errorInfo : String;   // error information

   END_VAR


   VAR_IN_OUT 

      ioArr_conditions : Array[*] of Bool;   // contactors connected to PLC or FB/FC

      ioArr_types : Array[*] of Bool;   // the type of contactors which be used

      ioArr_used : Array[*] of Bool;   // contactors which be used

      ob_result { S7_HiddenAssignment := 'Show'} : Bool;   // final calculate result of logic and

   END_VAR


   VAR_TEMP 

      tempIndex : DInt;   // index of array

      tempElementsConditionCount : DInt;   // count of elements

      tempElementsTypeCount : DInt;

      tempElementsUsedCount : DInt;

      tempUpperBound : DInt;

      tempLowerBound : DInt;

      tempArrayLenSame : Bool;

      tempCurrentStatus : Bool;   // current status of contact or which be used 

      tempLastStatus : Bool;   // last status of contactor which be used

   END_VAR


   VAR CONSTANT 

      cOne : DInt := 16#0001;

      cOneDim : UDInt := 16#0001;

      "cError_ArrayLengthIsInconsistent!" : String := 'ArrayLengthIsInconsistent!';

   END_VAR


BEGIN

   REGION init

      #tempUpperBound := UPPER_BOUND(ARR := #ioArr_used, DIM := #cOneDim);

      #tempLowerBound := LOWER_BOUND(ARR := #ioArr_used, DIM := #cOneDim);


      #tempElementsConditionCount := #tempUpperBound - #tempLowerBound + #cOne;

      #tempElementsTypeCount := #tempUpperBound - #tempLowerBound + #cOne;

      #tempElementsUsedCount := #tempUpperBound - #tempLowerBound + #cOne;


      #tempArrayLenSame := #tempElementsConditionCount = #tempElementsTypeCount

      AND #tempElementsConditionCount = #tempElementsUsedCount

      AND #tempElementsTypeCount = #tempElementsUsedCount;


      #tempLastStatus := true;

   END_REGION


   REGION logic

      IF #tempArrayLenSame THEN

         FOR #tempIndex := #tempLowerBound TO #tempUpperBound DO

            IF #ioArr_used[#tempIndex] THEN

               #tempCurrentStatus := #ioArr_types[#tempIndex] XOR #ioArr_conditions[#tempIndex];

               #ob_result := #tempCurrentStatus AND #tempLastStatus;

               #tempLastStatus := #tempCurrentStatus;

            END_IF;

         END_FOR;

      ELSE

         #ob_result := false;

      END_IF;

   END_REGION


   REGION error

      #ob_error := NOT #tempArrayLenSame;

      IF #ob_error THEN

         #oStr_errorInfo := #"cError_ArrayLengthIsInconsistent!";

      ELSE

         #oStr_errorInfo := '';

      END_IF;

   END_REGION


END_FUNCTION


少即是多
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC S7-1200系列

共有15635条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。