标签:25 V7.3 Tags read MySecond MyMinute VBS Write HMIRuntime
西门子技术论坛上,有人发帖子询问如何在Wincc上面做一个秒表功能,按下开始按钮秒表计时,按下停止功能停止计时,按下复位功能,计数回零。自己测试了一下,这个还是比较容易实现的,现在把实现的过程分享一下。
一 准备工作
1. 建立变量
打开wincc,新建一个工程,建立以下内部变量:
MyHour 32位无符号数;
MyMinute 32位无符号数;
MySecond 32位无符号数;
Start 二进制变量;
Timers 文本变量8位字符集;
2. 画面准备
新建一幅画面main.pdl,上面放置一个输入输出域控件,选择输出类型,绑定变量Timers,显示计时信息;再放置上个按钮,分别是“开始”、“停止”、“复位”。
3. 系统准备
wincc项目管理器-计算机属性,启动选项卡勾选全局脚本。
二 脚本
1. 全局脚本
新建一个stopwatch的VBS动作,循环触发器,频率1秒,脚本如下:
Option Explicit
Function action
Dim fmtHour,fmtMinute,fmtSecond
If HMIRuntime.Tags("Start").Read =1 Then
If HMIRuntime.Tags("MySecond").read<59 Then
HMIRuntime.Tags("MySecond").Write HMIRuntime.Tags("MySecond").read + 1
Else
If HMIRuntime.Tags("MyMinute").read<59 Then
HMIRuntime.Tags("MyMinute").Write HMIRuntime.Tags("MyMinute").read + 1
Else
HMIRuntime.Tags("MyMinute").Write 0
HMIRuntime.Tags("MyHour").Write HMIRuntime.Tags("MyHour").read + 1
End If
HMIRuntime.Tags("MySecond").Write 0
End If
'If HMIRuntime.Tags("MyMinute").read=60 Then
' HMIRuntime.Tags("MyHour").Write HMIRuntime.Tags("MyHour").read + 1
' HMIRuntime.Tags("MyMinute").Write 0
'End If
If HMIRuntime.Tags("MySecond").read<10 Then
fmtSecond="0" & CStr(HMIRuntime.Tags("MySecond").read)
Else
fmtSecond= CStr(HMIRuntime.Tags("MySecond").read)
End If
If HMIRuntime.Tags("MyMinute").read<10 Then
fmtMinute="0" & CStr(HMIRuntime.Tags("MyMinute").read)
Else
fmtMinute= CStr(HMIRuntime.Tags("MyMinute").read)
End If
If HMIRuntime.Tags("MyHour").read<10 Then
fmtHour="0" & CStr(HMIRuntime.Tags("MyHour").read)
Else
fmtHour= CStr(HMIRuntime.Tags("MyHour").read)
End If
HMIRuntime.Tags("Timers").Write fmtHour & ":" & fmtMinute & ":" & fmtSecond
End If
End Function
2. 启动按钮鼠标点击事件将常数1复制给内部变量Start
3. 停止按钮鼠标点击事件脚本
Sub OnClick(ByVal Item)
HMIRuntime.Tags("Start").Write 0
End Sub
4. 复位按钮鼠标点击事件脚本
Sub OnClick(Byval Item)
HMIRuntime.Tags("Start").Write 0
HMIRuntime.Tags("MyHour").Write 0
HMIRuntime.Tags("MyMinute").Write 0
HMIRuntime.Tags("MySecond").Write 0
HMIRuntime.Tags("Timers").Write "00:00:00"
End Sub
做完上述工作保存运行就可以看到效果了,如果想加入毫秒信息,那么需要在项目属性更新周期选项卡中修改一个用户周期为100ms,这是wincc最小的频率,然后修改相应的全集脚本,就可以把毫秒值加入了,这里就不再详细阐述了。
标签:25,V7.3,Tags,read,MySecond,MyMinute,VBS,Write,HMIRuntime 来源: https://www.cnblogs.com/fishingsriver/p/14345880.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。