Hi,
I have developed a Java application under Windows using jmod.jar and comm.jar (for windows) to communicate with a board trough a serial port RS-485.
Between the PC and the board there is a USB RS-485 Adapter. This applications runs fine and PC and board communicate without problems.
Now, i try to write the same app under Linux. Start to change the comm.jar (for Linux) and adjust the consequent code
// import com.sun.comm.Win32Driver;
import com.sun.comm.LinuxDriver;
...
LinuxDriver linuxDriver = new LinuxDriver(); //Init Native Driver
linuxDriver.initialize();
...
When application is initialized, the port /dev/ttyUSB0 is opened correctly and when the communications start problems begins:
Most of the request from the application are transmitted to the converter and even to the board, (because i observe the behavior) but never i receive the response from this board into the PC, this causes the ModbusIOException: I/O exception - failed to read as show in next lines:
Sent: 18 03 00 ff 00 01 b6 33
Last request: 18 03 00 ff 00 01 b6 33
Error reading response
execute try 1 error: I/O exception - failed to read
Sent: 18 03 00 ff 00 01 b6 33
Last request: 18 03 00 ff 00 01 b6 33
Error reading response
execute try 2 error: I/O exception - failed to read
Sent: 18 03 00 ff 00 01 b6 33
Catch trans.execute excep: ...net.wimpi.modbus.ModbusIOException: I/O exception - failed to read
Last request: 18 03 00 ff 00 01 b6 33
Error reading response
net.wimpi.modbus.ModbusIOException: I/O exception - failed to read
at net.wimpi.modbus.io.ModbusRTUTransport.readResponse(ModbusRTUTransport.java:180)
at net.wimpi.modbus.io.ModbusSerialTransaction.execute(ModbusSerialTransaction.java:183)
at btl.modbus.comm.ModbusBTL.transExecute(ModbusBTL.java:215)
Ok, most incredible is that for the same kind of command, in some exceptional occasions, I receive the answer !!!! ( randomly 1/10 aprox.)
I have checked all around the port, the cables, the drivers (uhci_hcd, ftdi_sio), the different options to configure the parameter ..
params.setPortName(portname);
params.setBaudRate(9600);
params.setDatabits(8)
params.setStopbits(1);
params.setParity("Even");
params.setEncoding("RTU");
params.setEcho(false);
even trying to change some parameters for the transaction
// trans.setTransDelayMS(5);
// trans.setCheckingValidity(false);
but always without success.
please any information that can help is welcome.
Uve
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
I'm experienceing this exact problem!!
I've developed in Windows using javax.comm and I'm successfully talking to modbus devices over rs485.
I've tried to use linux now (ubuntu server) and after installing the linux comms api my application has the same problem it writes to the device successfully, but cannot read a response. I can see my rs232-rs486 converter blinking to show communications.
But my windows and linux installs use a natice COM1 or /dev/ttyS0 from a dsub connector on the motherboard, so no USB com port.
This is the error I see...
Last request: 05 04 02 01 00 01 60 36
Error reading response
execute try 1 error: I/O exception - failed to read
Last request: 05 04 02 01 00 01 60 36
Error reading response
execute try 2 error: I/O exception - failed to read
Last request: 05 04 02 01 00 01 60 36
Error reading response
execute try 3 error: I/O exception - failed to read
Last request: 05 04 02 01 00 01 60 36
Error reading response
execute try 4 error: I/O exception - failed to read
Last request: 05 04 02 01 00 01 60 36
This port has not been opened yet
2010/02/11 18:16:05.459| |main|ModbusRTU|--> Failed! Error reading meter.
2010/02/11 18:16:05.460|***|main|ModbusRTU|net.wimpi.modbus.ModbusIOException: I/O exception - failed to read
net.wimpi.modbus.ModbusIOException: I/O exception - failed to read
at net.wimpi.modbus.io.ModbusRTUTransport.readResponse(ModbusRTUTransport.java:180)
at net.wimpi.modbus.io.ModbusSerialTransaction.execute(ModbusSerialTransaction.java:183)
at IAS_BRMS_DAQ.ModbusRTU.response(ModbusRTU.java:311)
at IAS_BRMS_DAQ.ModbusRTU.readMeters(ModbusRTU.java:181)
at IAS_BRMS_DAQ.ModbusRTU.execute(ModbusRTU.java:74)
at IAS_BRMS_DAQ.Main.main(Main.java:145)
Has anyone found a solution to this I really need to get this working for work ASAP!!
Many thanks~
I believe I have the answer as to why this is happening, though I don't yet know how to solve it.
It seems that the Linux device driver has a default timeout or threshold. This timeout or threshold limits the size of the responses.
I am using the RXTX Java library, and in it I see that the CommPort/SerialPort classes have the functions:
CommPort.enableReceiveThreshold(int)
CommPort.disableReceiveThreshold()
CommPort.enableReceiveTimeout(int)
CommPort.disableReceiveTimeout()
Unfortunately, I am not yet certain how to play with these from within Jamod without modifying the source.
Any comments would be most appreciated.
-Edgar
I have never used Windows on my project, but happily have working an EasySync USB-RS485 device in 2 wire duplex with RXTX.
This is how I brought up the serial interface.
SerialParameters params = new SerialParameters();
params.setPortName(serialport);
params.setBaudRate(baud);
params.setDatabits(databits);
params.setParity(parity);
params.setStopbits(stopbits);
params.setEncoding("rtu");
params.setEcho(false);
params.setReceiveTimeout(500); //msec
SerialConnection ModSerialConnection = new SerialConnection(params);