Closed SanduDS closed 6 years ago
please tell me what I got wrong. and power meter (SMD 220 eastron )gives me integer register values but I couldn't convert it to real values. I m new to Modbus
Hi! JLibmodbus supports several uart connectors like jssc, rxtx, jserialcomm etc. Before you create a master you should set SerialPortFactory, for instance jssc:
SerialUtils.setSerialPortFactory(new SerialPortFactoryJSSC());
If you need to read float values you can use the code below:
ReadHoldingRegistersRequest request = new ReadHoldingRegistersRequest();
//Or ReadInputRegistersRequest request = new ReadInputRegistersRequest();
request.setServerAddress(slaveId);
request.setStartAddress(offset);
request.setQuantity(2);
ReadHoldingRegistersResponse response = (ReadHoldingRegistersResponse)
request.getResponse();
master.processRequest(request);
ModbusHoldingRegisters registers = response.getHoldingRegisters();
registers.getFloat32At(0);
/Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at com.intelligt.modbus.jlibmodbus.serial.SerialUtils.createSerial(SerialUtils.java:63) at com.intelligt.modbus.jlibmodbus.master.ModbusMasterRTU.(ModbusMasterRTU.java:34)
at com.intelligt.modbus.jlibmodbus.master.ModbusMasterFactory.createModbusMasterRTU(ModbusMasterFactory.java:48)
at powerMeterConnector.PMconnection.(PMconnection.java:43)
/
public class PMconnection {
private static PMconnection plc;
private ModbusMaster master;
}