1

tell me whether it is possible to directly read the values ​​of the registers from the equipment using the Modbus protocol. I want to implement in java language reading registers and outputting them to the jsp page. The program is needed for the diploma project and gaining knowledge in java. Did anyone try to do this? Found the library modbus4j with the use of mango infiniteautomation but somehow everything is very difficult. Thank you in advance for your answers.

I have to add some information. I connected the Schneider electric ATV 71 frequency converter to Modbus TCP to the computer (The connection is established because the software sees this device).

Below is an example of the code used. The host is different because the device is in the university and I do not remember the address that indicated.

public class Test {
   public static void main(String[] args) throws ErrorResponseException,ModbusTransportException {
ModbusFactory factory = new ModbusFactory();
   IpParameters parameters = new IpParameters();
   parameters.setHost("127.0.0.1");
   parameters.setPort(502);
   parameters.setEncapsulated(false);
   ModbusMaster master = factory.createTcpMaster(parameters,true);
   master.setTimeout(1000);
   master.setRetries(0);
   try {
       master.init();
       master.setConnected(true);
       NumericLocator locator = new NumericLocator(1,RegisterRange.HOLDING_REGISTER,0,DataType.FOUR_BYTE_INT_SIGNED);
       System.out.println("value: "+master.getValue(locator));
       System.out.println(master.isInitialized());
       System.out.println(master.isConnected());
   } catch (ModbusInitException e) {
       System.out.println("Something wrong");
       e.printStackTrace();
   }

} }

methods "master.isInitialized()" and "master.isConnected()" return value "true". The address set in the device is "1". It also confirms the connection because an exception is thrown when installing another id.

NumericLocator locator = new NumericLocator(1,RegisterRange.HOLDING_REGISTER,0,DataType.FOUR_BYTE_INT_SIGNED);
       System.out.println("value: "+master.getValue(locator));

The code above always returns "null" whatever shift I set.

I also tried the EasyModbus library and got the value "0" all the time.

So i believe with this information you can help me. Thank you in advance for your answers.

  • Hi, welcome to stack overflow. Please refer the [ask] link for more details on how to ask a question and update your question accordingly. – Jeroen Heier Apr 07 '18 at 07:57

0 Answers0