I have written the following program to understand how to use JAMOD to access coils. Unfortunately it is throwing the error -
_java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.DataInputStream.read(Unknown Source)
at net.wimpi.modbus.io.ModbusTCPTransport.readResponse(ModbusTCPTransport.java:177)
at net.wimpi.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:193)
at TempReader.main(TempReader.java:27)
. x2 more times
.
java.io.EOFException
at java.io.DataInputStream.readUnsignedByte(Unknown Source)
at net.wimpi.modbus.io.BytesInputStream.readUnsignedByte(BytesInputStream.java:153)
at net.wimpi.modbus.io.ModbusTCPTransport.readResponse(ModbusTCPTransport.java:182)
at net.wimpi.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:193)
at TempReader.main(TempReader.java:30)
net.wimpi.modbus.ModbusIOException: Executing transaction failed (tried 3 times)
at net.wimpi.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:197)
at TempReader.main(TempReader.java:30)
_
In the program line 27 is "trans.execute()". The coil address I am trying to read is 0x7D1 (2001) or channel 0 Data type is 2 word. -
public static void main(String Args){
TCPMasterConnection con = null;
ModbusTCPTransaction trans = null;
ReadCoilsRequest rcreq=null;
ReadCoilsResponse rcres=null;
InetAddress addr = null;
int port = Modbus.DEFAULT_PORT;
byte byteArray={(byte)192, (byte)168, (byte)0, (byte)182};
try {
addr=InetAddress.getByAddress(byteArray);
con=new TCPMasterConnection(addr);
con.setPort(502);
con.connect();
rcreq=new ReadCoilsRequest(2001, 1);
trans=new ModbusTCPTransaction(con);
trans.setRequest(rcreq);
trans.execute();
rcres=(ReadCoilsResponse)trans.getResponse();
System.out.println("Response : "+rcres.getCoils().toString());
con.close();
}
catch(Exception e){
con.close();
e.printStackTrace();
}
}
}
**
The error of course repeats 3 times as set in ModbusTCPTransport class (I checked the class source) i.e 3 attempts before exit and program exits.
Where am I going wrong?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have written the following program to understand how to use JAMOD to access coils. Unfortunately it is throwing the error -
_java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.DataInputStream.read(Unknown Source)
at net.wimpi.modbus.io.ModbusTCPTransport.readResponse(ModbusTCPTransport.java:177)
at net.wimpi.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:193)
at TempReader.main(TempReader.java:27)
. x2 more times
.
java.io.EOFException
at java.io.DataInputStream.readUnsignedByte(Unknown Source)
at net.wimpi.modbus.io.BytesInputStream.readUnsignedByte(BytesInputStream.java:153)
at net.wimpi.modbus.io.ModbusTCPTransport.readResponse(ModbusTCPTransport.java:182)
at net.wimpi.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:193)
at TempReader.main(TempReader.java:30)
net.wimpi.modbus.ModbusIOException: Executing transaction failed (tried 3 times)
at net.wimpi.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:197)
at TempReader.main(TempReader.java:30)
_
In the program line 27 is "trans.execute()". The coil address I am trying to read is 0x7D1 (2001) or channel 0 Data type is 2 word. -
**import java.net.*;
import java.io.*;
import net.wimpi.modbus.*;
import net.wimpi.modbus.msg.*;
import net.wimpi.modbus.io.*;
import net.wimpi.modbus.net.*;
import net.wimpi.modbus.util.*;
public class TempReader {
public static void main(String Args){
TCPMasterConnection con = null;
ModbusTCPTransaction trans = null;
ReadCoilsRequest rcreq=null;
ReadCoilsResponse rcres=null;
InetAddress addr = null;
int port = Modbus.DEFAULT_PORT;
byte byteArray={(byte)192, (byte)168, (byte)0, (byte)182};
try {
addr=InetAddress.getByAddress(byteArray);
con=new TCPMasterConnection(addr);
con.setPort(502);
con.connect();
rcreq=new ReadCoilsRequest(2001, 1);
trans=new ModbusTCPTransaction(con);
trans.setRequest(rcreq);
trans.execute();
rcres=(ReadCoilsResponse)trans.getResponse();
System.out.println("Response : "+rcres.getCoils().toString());
con.close();
}
catch(Exception e){
con.close();
e.printStackTrace();
}
}
}
**
The error of course repeats 3 times as set in ModbusTCPTransport class (I checked the class source) i.e 3 attempts before exit and program exits.
Where am I going wrong?
The error come from the ReadCoilsRequest(2001, 1); 2001 is out of bound