kochedykov / jlibmodbus

JLibModbus - is an implementation of the Modbus protocol v1.1b in java language. Java modbus library. It works. Welcome.
http://kochedykov.github.io/jlibmodbus/
Apache License 2.0
307 stars 128 forks source link

Truncated modbus messages #55

Open andreaghezzi-servitly opened 4 years ago

andreaghezzi-servitly commented 4 years ago

I have the following configuration:

Modbus poll application running on a Windows machine connected to a Linux embedded device through an usb-serial adapter:

slaveId=10,
serialBaudRate=38400,
serialDataBits=8,
serialParity=EVEN,
serialStopBits=1,
serialPortFactory=JSerialComm,
serialPortId=/dev/ttymxc1,

With Modbus poll (emulating the modbus master) I'm trying to write with the 'write multiple registers' function 123 registers every 10 ms. In the Linux device I'm running a java class that uses jLibModbus v1.2.9.7 library (it will be the modbus slave) and jSerialComm v2.6.2 which reads correctly first 10-20 messages, then I see continuously in log:

INFO: Frame recv: 0000
WARNING: null

I've edited the 'open' method of SerialPortJSerialComm class as following:

public void open() throws SerialPortException {
    SerialParameters sp = getSerialParameters();
    port = com.fazecast.jSerialComm.SerialPort.getCommPort(sp.getDevice());
    port.openPort();

    port.setComPortParameters(sp.getBaudRate(), sp.getDataBits(), sp.getStopBits(), sp.getParity().getValue(), true);
    port.setFlowControl(com.fazecast.jSerialComm.SerialPort.FLOW_CONTROL_DISABLED);
    port.setComPortTimeouts(com.fazecast.jSerialComm.SerialPort.TIMEOUT_READ_SEMI_BLOCKING
        | com.fazecast.jSerialComm.SerialPort.TIMEOUT_WRITE_BLOCKING, 0, 0);

    in = port.getInputStream();
    out = port.getOutputStream();
}

I've also tried playing around with different timeouts configuration without any luck. What could be possible wrong? Thank you, regards. Andrea