连接到Modbus设备,每10秒一次。

huangapple go评论72阅读模式
英文:

Connect with modbus device every 10 seconds

问题

我正在处理通过串口与系统连接的Modbus设备。我可以读/写设备寄存器上的数据。我正在使用Java进行数据读/写。

设备每隔10秒钟会自动关闭,为了保持其激活状态,我需要每隔10秒钟建立一次连接。我如何实现这个要求?

连接到Modbus设备,每10秒一次。

英文:

I am working on modbus device which is connected with system through serial port. I can read/write data on device's register. I am using java for data read/write.

The device automatically turns off on every 10 seconds, to keep it activated I need to establish the connection on every 10 seconds. How can I achieve this requirement?

连接到Modbus设备,每10秒一次。

答案1

得分: 2

可以使用Timer类来每隔10秒钟建立连接,代码如下:

class EstablishConnection extends TimerTask {
   public void run() {
      // 建立连接的代码
   }
}
Timer timer = new Timer();
timer.schedule(new EstablishConnection(), 0, 10000);
英文:

You can use timer class to establish connection every 10 seconds as such:

class EstablishConnection extends TimerTask {
   public void run() {
      // Code to establish connection 
   }
}
Timer timer = new Timer();
timer.schedule(new EstablishConnection(), 0, 10000);

huangapple
  • 本文由 发表于 2020年9月18日 16:41:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/63952248.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定