wincc6.2顺序启动问题

本人小白 想求一个VBS脚本  , 假设有三个灯 D1 D2 D3 我想在按钮A按下时,根据画面上设定的延时时间(一个时间就行单位是秒)。比如启动 D1亮,延时 设定时间  。D1灭  然后D2亮   延时设定时间  D2灭 然后D3亮延时D3灭   。如果按钮A=0的时候 就不会执行脚本并且亮的灯也灭掉。

最佳答案

全局脚本vbs,周期1s
dim time_sp,start,count,runtime
time_sp=hmiruntime.tags("timesp").read''读取设定时间
start=hmiruntime.tags("bstart").read''按钮按下bstart置位。
count=hmiruntime.tags("mycount").read‘需要启动的灯,wincc内部变量
runtime=hmiruntime.tags("myruntime").read''读取运行时间,wincc内部变量
if start=1 then
     if count=0 then
        hmiruntime.tags("D1").write 1''D1打开
      else if count=1 then
                hmiruntime.tags("D2").write 1''D2打开
      else
               hmiruntime.tags("D3").write 1''D3打开
      end if''根据count值打开对应的灯
    runtime=runtime+1
     if runtime>=time_sp then
        count=count+1
        runtime=0
     end if''运行时间大于sp则count加1,runtime清零
     if count>2 then
        count=0
     end if''count大于0说明需要从头循环,count复位
    hmiruntime.tags("mycount").write count''保存count值
    hmiruntime.tags("myrumtime").write runtime''保存runtime值
 else
    hmiruntime.tags("mycount").write0
    hmiruntime.tags("myrumtime").write 0
      hmiruntime.tags("D1").write 0''D1关闭
      hmiruntime.tags("D2").write 0''D2关闭
      hmiruntime.tags("D3").write 0''D3关闭
end if''没有启动则计数和运行时间清零,关闭灯。
按钮中的脚本:
SetTagBit("bstart",!GetTagBit("bstart"));//按钮中给bstart取反

提问者对于答案的评价:
太感谢了 。。还有个问题是 倒数的  Else  提示缺少end 我看了下 确实是前面也没有if语句 直接 else 和end if 了    应该把这句错误的地方在哪里改一下呢?

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc179167.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2017年6月24日 下午5:10
下一篇 2017年6月24日 下午5:10

相关推荐