电工学习网

 找回密码
 立即注册
查看: 5164|回复: 1
打印 上一主题 下一主题

SCL实现数组全复制的三种方法

[复制链接]
跳转到指定楼层
楼主
发表于 2017-11-10 11:09:30 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
//copy a array totally to another array
//first way: use SFC20
#Error := BLKMOV(SRCBLK := #SourceArray, DSTBLK =>#DestinationArray_1);
//second way: copy the elements one by one
FOR #index := 0 TO 9 DO  
  #DestinationArray_2[#index] := #SourceArray[#index];
END_FOR;
#index := #index + 1;
//third way: use the name of array
#DestinationArray_3 := #SourceArray;
//Error check
FOR #index := 0 TO 9 DO   
IF (#DestinationArray_1[#index] <> #SourceArray[#index]) THEN  
      #Error_1 := TRUE;        
      IF (#DestinationArray_2[#index] <> #SourceArray[#index]) THEN         
            #Error_2 := TRUE;         
            IF (#DestinationArray_3[#index] <> #SourceArray[#index]) THEN               
                  #Error_3 := TRUE;      
            END_IF;      
       END_IF;   
END_IF;
END_FOR;
SCL实现数组全复制的三种方法

若要倒序复制,则变更索引下标即可:
//second way: copy the elements one by one
FOR #index := 0 TO 9 DO
    #DestinationArray_2[9-#index] := #SourceArray[#index];
END_FOR;
#index := #index + 1;
或者
//second way: copy the elements one by one
FOR #index := 0 TO 9 DO
    #DestinationArray_2[#index] := #SourceArray[9-#index];
END_FOR;
#index := #index + 1;
本文转载自:西门子工业技术论坛

回复

使用道具 举报

沙发
发表于 2017-11-10 12:56:26 | 只看该作者
西门子PLC的知识没有接触过,了解一下

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

电工学习网 ( )

GMT+8, 2024-5-9 08:07

Powered by © 2011-2022 www.diangon.com 版权所有 免责声明 不良信息举报

技术驱动未来! 电工学习网—专业电工基础知识电工技术学习网站。

栏目导航: 工控家园 | 三菱plc | 西门子plc | 欧姆龙plc | plc视频教程

快速回复 返回顶部 返回列表