本人小白想求一个VBS脚本,假设有三个灯D1D2D3我想在按钮A按下时,根据画面上设定的延时时间(一个时间就行单位是秒)。比如启动D1亮,延时设定时间。D1灭然后D2亮延时设定时间D2灭然后D3亮延时D3灭。如果按钮A=0的时候就不会执行脚本并且亮的灯也灭掉。
最佳答案
全局脚本vbs,周期1s
dimtime_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内部变量
ifstart=1then
iFCount=0then
hmiruntime.tags("D1").write1”D1打开
elseifcount=1then
hmiruntime.tags("D2").write1”D2打开
else
hmiruntime.tags("D3").write1”D3打开
endif”根据count值打开对应的灯
runtime=runtime+1
ifruntime>=time_spthen
count=count+1
runtime=0
endif”运行时间大于sp则count加1,runtime清零
ifcount>2then
count=0
endif”count大于0说明需要从头循环,count复位
hmiruntime.tags("mycount").writecount”保存count值
hmiruntime.tags("myrumtime").writeruntime”保存runtime值
else
hmiruntime.tags("mycount").write0
hmiruntime.tags("myrumtime").write0
hmiruntime.tags("D1").write0”D1关闭
hmiruntime.tags("D2").write0”D2关闭
hmiruntime.tags("D3").write0”D3关闭
endif”没有启动则计数和运行时间清零,关闭灯。
按钮中的脚本:
SetTagBit("bstart",!GetTagBit("bstart"));//按钮中给bstart取反
提问者对于答案的评价:
太感谢了。。还有个问题是倒数的Else提示缺少end我看了下确实是前面也没有if语句直接else和endif了应该把这句错误的地方在哪里改一下呢?