WINCC的VBS的按钮代码分析

一个新手编的2个按钮代码: 第一个按钮按下去后出现小画面,再按第二个按钮,给B赋1;松开0;
 第一个按钮:
 Dim  motor_command_req
 Set  motor_command_req=HMIRuntime.Tags("motor_command_req_1")
 motor_command_req.Write  "B"
 
 第二个按钮按下去:
 Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)           
 
 Dim   motor_command_req_1
 Set    motor_command_req_1=HMIRuntime.Tags("motor_command_req_1")
 
 Dim motor_1            
 Set motor_1=HMIRuntime.Tags(motor_command_req_1.read) 
 motor_1.Write 1
 End Sub
 
 第二个按钮松开:
 Sub OnLButtonUp(Byval Item, Byval Flags, Byval x, Byval y)           
 
 Dim    motor_command_req_1
 Set     motor_command_req_1=HMIRuntime.Tags("motor_command_req_1")
 
 Dim motor            
 Set motor=HMIRuntime.Tags(motor_command_req_1.read) 
 motor.Write 0
 End Sub
 其中motor_command_req_1 为WINCC内部变量;B是写给PLC的变量;
 按下第一个按钮后,再按第二个按钮实现给PLC变量B赋值1;松开B赋值0;
 请大侠分析下:
 1.第一个按钮的代码起什么作用??最终的目的是给PLC 的B变量写值,为什么把B写给motor_command_req_1???? 在我看来应该是
 SET    motor_command_req_1=HMIRuntime.Tags("B")
 motor_command_req_1.Write  " motor_command_req_1"
 2. Dim    motor_command_req_1
 Set     motor_command_req_1=HMIRuntime.Tags("motor_command_req_1")
 这2行起啥作用??
 Dim motor            
 Set motor=HMIRuntime.Tags(motor_command_req_1.read) 
 motor.Write 0
 这3行起啥作用???

最佳答案

1、实际按钮1的代码等同于:
HMIRuntime.Tags("motor_command_req_1").write "B"
2、这是定义一个脚本内的变量连接到motor_command_req_1
3、这个脚本是有问题的,应该是直接用
Dim motor            
 Set motor=HMIRuntime.Tags("motor_command_req_1")
 motor.Write 0
这个是给变量motor_command_req_1赋值0
如果你怀疑我的分析你可以原来的这些代码赋值到项目中运行一下看看。

提问者对于答案的评价:
谢谢

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

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2019年6月10日
下一篇 2019年6月10日

相关推荐