You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here how I am using it but don't know whether its correct and how to check response for the same. Please let me know if I am missing something in below code.
WriteMultipleRegistersRequest multipleRegistersRequest = null;
WriteMultipleRegistersResponse multipleRegistersResponse = null;
SerialUtils.setSerialPortFactory(new SerialPortFactoryJSerialComm());
SerialParameters serialParameters = new SerialParameters();
serialParameters.setBaudRate(SerialPort.BaudRate.BAUD_RATE_9600);
serialParameters.setParity(SerialPort.Parity.NONE);
serialParameters.setDataBits(8);
serialParameters.setStopBits(1);
serialParameters.setDevice("COM5");
try {
ModbusMaster m = ModbusMasterFactory.createModbusMasterRTU(serialParameters);
m.connect();
System.out.println("Connected");
multipleRegistersRequest = new WriteMultipleRegistersRequest();
multipleRegistersRequest.setServerAddress(1);//ModbusAddress of Slave device to be read
multipleRegistersRequest.setStartAddress(458); // Start Address
multipleRegistersRequest.setRegisters(new int[]{14,28,65,200}); //Values to write at different registers
m.setResponseTimeout(500);
m.processRequest(multipleRegistersRequest);
multipleRegistersResponse = (WriteMultipleRegistersResponse) multipleRegistersRequest.getResponse();
System.out.println("<> "+multipleRegistersResponse.getValue());
System.out.println("<> "+multipleRegistersResponse.toString());
} catch (SerialPortException ex) {
Logger.getLogger(JLibModbusTestClass.class.getName()).log(Level.SEVERE, null, ex);
} catch (ModbusIOException ex) {
Logger.getLogger(JLibModbusTestClass.class.getName()).log(Level.SEVERE, null, ex);
} catch (ModbusNumberException ex) {
Logger.getLogger(JLibModbusTestClass.class.getName()).log(Level.SEVERE, null, ex);
}
I have updated my code.But Still I am getting error as following
com.intelligt.modbus.jlibmodbus.exception.ModbusIOException: java.io.IOException: com.fazecast.jSerialComm.SerialPortTimeoutException: The read operation timed out before any data was returned.
at com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransportSerial.read(ModbusTransportSerial.java:49)
at com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport.readMessage(ModbusTransport.java:69)
at com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport.readResponse(ModbusTransport.java:64)
at com.intelligt.modbus.jlibmodbus.master.ModbusMaster.readResponse(ModbusMaster.java:111)
at com.intelligt.modbus.jlibmodbus.master.ModbusMaster.processRequest(ModbusMaster.java:134)
at com.importexportutility.jlibmodbustest.JLibModbusTestClass.main(JLibModbusTestClass.java:52)
Caused by: java.io.IOException: com.fazecast.jSerialComm.SerialPortTimeoutException: The read operation timed out before any data was returned.
at com.intelligt.modbus.jlibmodbus.serial.SerialPortJSerialComm.read(SerialPortJSerialComm.java:100)
at com.intelligt.modbus.jlibmodbus.serial.SerialPort$2.read(SerialPort.java:77)
at com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingInputStream.read(LoggingInputStream.java:52)
at com.intelligt.modbus.jlibmodbus.net.stream.InputStreamRTU.read(InputStreamRTU.java:55)
at com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport.createMessage(ModbusTransport.java:51)
at com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransportSerial.read(ModbusTransportSerial.java:45)
... 5 more
Caused by: com.fazecast.jSerialComm.SerialPortTimeoutException: The read operation timed out before any data was returned.
at com.fazecast.jSerialComm.SerialPort$SerialPortInputStream.read(SerialPort.java:1328)
at com.intelligt.modbus.jlibmodbus.serial.SerialPortJSerialComm.read(SerialPortJSerialComm.java:98)
... 10 more
The text was updated successfully, but these errors were encountered:
Here how I am using it but don't know whether its correct and how to check response for the same. Please let me know if I am missing something in below code.
I have updated my code.But Still I am getting error as following
The text was updated successfully, but these errors were encountered: