1

I wanted to ask how to query every second Modbus, using the JAMOD library. Decided to make a preliminary connection to Modbus and then, within a loop while(true) query the Modbus. After interrogating the device, use a Thread.sleep (1000); is the right way? Thank you.

JoeJoe
  • 83
  • 1
  • 12

2 Answers2

1

You should create a Thread (something that implements Runnable).

See this answer : https://stackoverflow.com/a/426795/362332

Community
  • 1
  • 1
klonq
  • 3,535
  • 4
  • 36
  • 58
0
//I usually use asynchronous threads to process
//example
@Async
public Future<Integer> loop() {
    while (true) {
        int value = modbusServer.read(1001);
        if (value == 1) {
            //Business processing ...

            break;
        }
        thread.sleep(50);
    }
    return new AsyncResult(1);
}