Search code examples
javamodbus

Connect with modbus device every 10 seconds


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?

Device's Display


Solution

  • 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);