我的一只烂板凳:不使用SFC20实现不同长度数组间元素块的复制

已锁定

'Razor

西门子1847工业学习平台

  • 帖子

    3208
  • 精华

    41
  • 被关注

    222

论坛等级:至圣

注册时间:2008-03-31

钻石 钻石 如何晋级?

我的一只烂板凳:不使用SFC20实现不同长度数组间元素块的复制

1508

6

2017-11-11 00:11:59







数组间连续单元块的复制操作,完全可以通过调用系统功能块SFC20实现,简洁高效,使用时仅须注意格式正确二者长度一致即可。

此帖没有使用上述方法,而是采用了一种比较”糟糕“的方法,纯属个人无聊的产物,对细节有兴趣的朋友可以看看,参考一下;没兴趣的朋友,笑笑就好。

//initialize the #ErrorMessage and #ErrorWord

#ErrorMessage := '';

#ErrorWord := 0;


//deal with input ANY by using the function "AT" in temp

#tempInputANY := #SourceArray;


//get #srcTotalElements

#srcTotalElements := #TempSource.Repetition_factor;


//get the srcMaxIndex and srcMinIndex

#srcMaxIndex := #srcTotalElements - 1;

#srcMinIndex := 0;


//deal with output ANY by using the function "AT" in temp

#tempOutputANY := #DestinationArray;


//get #dstTotalElements

#dstTotalElements := #TempDestination.Repetition_factor;


//get the desMaxIndex and desMinIndex

#dstMaxIndex := #dstTotalElements - 1;

#dstMinIndex := 0;


//conditions judge: the set value of the "stopIndex" in the range of allowed.

#stopIndexInRange := (#srcStopIndex < #srcTotalElements) AND (#dstStopIndex < #dstTotalElements);


//judge source's index

 IF (#srcStopIndex >= #srcTotalElements) = TRUE THEN

    #ErrorWord := w#16#1; 

    #ErrorMessage := #srcStopIndexOutRange;

END_IF;


//judge destination's index

IF (#dstStopIndex >= #dstTotalElements) = TRUE THEN

    #ErrorWord := w#16#2; 

    #ErrorMessage := #dstStopIndexOutRange;

END_IF;


//judge length of copied data zone

#srcCopyDatasLength := #srcStopIndex - #srcStartIndex;

#dstCopyDatasLength := #dstStopIndex - #dstStartIndex;

#lengthEqual := (#srcCopyDatasLength = #dstCopyDatasLength);

IF (#srcCopyDatasLength > #dstCopyDatasLength) = TRUE THEN

    #ErrorWord := w#16#3;

    #ErrorMessage := #"SrcZone_>_dstZone";

END_IF;

IF (#srcCopyDatasLength < #dstCopyDatasLength) = TRUE THEN

    #ErrorWord := w#16#4;

    #ErrorMessage := #"SrcZone_<_dstZone";

END_IF;


//judge data type matched or not

#dataTypeMatch := (#TempSource.DataType = #TempDestination.DataType);


//allow copy operation

 #copyAllow := #stopIndexInRange AND #lengthEqual AND #dataTypeMatch;


//copy operation

IF #copyAllow = TRUE THEN

    #dstIndex := #dstStartIndex;

    FOR #srcIndex := #srcStartIndex TO #srcStopIndex DO

        #DestinationArray[#dstIndex] := #SourceArray[#srcIndex];

        #dstIndex := #dstIndex + 1;

    END_FOR;

END_IF;

我的一只烂板凳:不使用SFC20实现不同长度数组间元素块的复制 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC S7-300/400

共有54618条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

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

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

  • 分享

  • 只看
    楼主

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