检查时间是否更新的Javascript代码

发布于 2024-10-31 01:47:49 字数 206 浏览 7 评论 0原文

我想知道是否有人可以帮助我编写一段 JavaScript 代码来检查我的 HMI 上的时间是否每秒更新一次,如果时间停止,它应该提醒用户。 我有一个名为“device.string.TIME”的字符串变量,我的 HMI 正在通过 modbus 从 PLC 读取该变量,HMI 读取的格式为字符串“12:00:00”。该字符串从 PLC 连续更新(1 秒),现在当该时间过时 2 秒时,我想提醒用户。

I was wondering if anybody can help me to write a javascript code that will check whether the time on my HMI is updating every seconds, if the time stops it should alert the user.
I have a string variable called "device.string.TIME" that my HMI is reading from the PLC over modbus, the format the HMI is reading is in strings "12:00:00". This string is updating continuously (1 second) from the PLC, now when this time gets stale for 2 seconds i want to alert the user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生百味 2024-11-07 01:47:49
var oldTime = 0;
function checkTime() {
   var newTime = device.string.TIME;
   if(oldTime!=0&&newTime==oldTime) {
      alert("something!");
      return;
   }
   oldTime = newTime;
   window.setTimeout(function() {
            checkTime();
   },1000)
}
    checkTime()

1000 毫秒 = 一秒

var oldTime = 0;
function checkTime() {
   var newTime = device.string.TIME;
   if(oldTime!=0&&newTime==oldTime) {
      alert("something!");
      return;
   }
   oldTime = newTime;
   window.setTimeout(function() {
            checkTime();
   },1000)
}
    checkTime()

1000ms = one second

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文