N
We are using EM6436 energy meter connected to a PC via RS232 to RS485 converter.
With my own code using modbus4j open source library,we are able to discover the Energy meter and obtain its ID using Modbus4j.
But when I try to read data address (3901 say) of the device(EM6436) using the following code:<pre>
SerialParameters params = new SerialParameters();
params.setCommPortId("COM1");
params.setBaudRate(9600);
params.setDataBits(SerialPort.DATABITS_8);
params.setParity(SerialPort.PARITY_EVEN);
params.setStopBits(SerialPort.STOPBITS_1);
ModbusMaster master = null;
ModbusFactory factory = null;
try
{
factory = new ModbusFactory();
master=factory.createRtuMaster(params, 0);
if (master == null){
return;
}
master.setTimeout(5000);
master.init();
Object obj = null;
NumericLocator locator = null;
try{
locator = new NumericLocator(1,
RegisterRange.HOLDING_REGISTER, 3901, DataType.FOUR_BYTE_FLOAT);
obj = master.getValue(locator);
}catch (Exception e) {
System.out.println("Exception occured : "+e.getMessage());
}
System.out.println("Value read"+"for------"+i+"----------->"+obj);
}
}
finally {
master.destroy();
}
} </pre>
We are getting error as Error Response Exception :Invalid data address or sometimes its giving TimeOut exception.
The same code is working fine with the simulators (Modbus PAL , Modbus PLC).
Even reading the same data address with ModScan32 (with the same connection) is also working but not with the above code. Please suggest.
With my own code using modbus4j open source library,we are able to discover the Energy meter and obtain its ID using Modbus4j.
But when I try to read data address (3901 say) of the device(EM6436) using the following code:<pre>
SerialParameters params = new SerialParameters();
params.setCommPortId("COM1");
params.setBaudRate(9600);
params.setDataBits(SerialPort.DATABITS_8);
params.setParity(SerialPort.PARITY_EVEN);
params.setStopBits(SerialPort.STOPBITS_1);
ModbusMaster master = null;
ModbusFactory factory = null;
try
{
factory = new ModbusFactory();
master=factory.createRtuMaster(params, 0);
if (master == null){
return;
}
master.setTimeout(5000);
master.init();
Object obj = null;
NumericLocator locator = null;
try{
locator = new NumericLocator(1,
RegisterRange.HOLDING_REGISTER, 3901, DataType.FOUR_BYTE_FLOAT);
obj = master.getValue(locator);
}catch (Exception e) {
System.out.println("Exception occured : "+e.getMessage());
}
System.out.println("Value read"+"for------"+i+"----------->"+obj);
}
}
finally {
master.destroy();
}
} </pre>
We are getting error as Error Response Exception :Invalid data address or sometimes its giving TimeOut exception.
The same code is working fine with the simulators (Modbus PAL , Modbus PLC).
Even reading the same data address with ModScan32 (with the same connection) is also working but not with the above code. Please suggest.
