恭喜,你发布的帖子
发布于 2022-11-25 21:17:22
20楼
容器是泛型, 没有指明类型, 可以操作任何数据类型, 先入先出, 而且避免了For循环 , 大量节约了扫描周期, 测试过80万长度的数组 也可以不增加扫描周期的情况下 完成,
优化的和非优化的 都可以。
REGION BLOCK INFO HEADER
//===============================================================================
// Dang
//-------------------------------------------------------------------------------
// Title: FC_FIFO V1.0
// Comment/Function: Sort the Array
// Library/Family:
// Author:
// Tested with: S7-PLCSIM V2.0 SP1
// Engineering: TIA Portal V15.1
// Restrictions: ENO disabled - error handling done with error and status
// Requirements: PLC (S7-1200 / S7-1500)
//-------------------------------------------------------------------------------
// Change log table:
// Version | Date | Expert in charge | Changes applied
//----------|------------|------------------------|------------------------------
// 09.00.00 25.7.2021 dangguodong
// Set version to V1.0.0
// array must be start with zreo
//==============================================================================
END_REGION
REGION init the result
#"FC_FIFO_V2.0" := FALSE;
#State := #Program_No_Excute;
END_REGION
REGION Check the DataContainer , if not array will be return
IF NOT IS_ARRAY(#DataContainer)
THEN
#State := #Data_Type_Wrong;
RETURN;
END_IF;
END_REGION
REGION Check the DataContainer , If DataContainer is not correct point or length is 1 , no need sort
IF IS_NULL(#DataContainer)
OR CountOfElements(#DataContainer) <= 1
THEN
#State := #Data_Type_Wrong;
RETURN;
END_IF;
END_REGION
REGION move the data container shift
#State :=INT_TO_WORD( MOVE_BLK_VARIANT(SRC := #DataContainer, COUNT := CountOfElements(#DataContainer) - 1, SRC_INDEX := 0, DEST_INDEX := 1, DEST => #DataContainer));
IF #State <> 16#0
THEN
RETURN;
END_IF;
END_REGION
REGION result ok
#"FC_FIFO_V2.0" := TRUE;
#State := #NO_Error;
END_REGION
楼主厉害了,每次用语句表for循环做先进先出,看到大神的方法简直让人耳目一新
请填写推广理由:
分享
只看
楼主