Hello.
I have code
//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 mbTest {
public static void main(String[] args) {
try {
/ The important instances of the classes mentioned before /
SerialConnection con = null; //the connection
ModbusSerialTransaction trans = null; //the transaction
ReadInputRegistersRequest req = null; //the request
ReadInputRegistersResponse res = null; //the response
/* Variables for storing the parameters */
// String portname= null; //the name of the serial port to be used
int unitid = 3; //the unit identifier we will be talking to
int ref = 100; //the reference, where to start reading from
int count = 15; //the count of IR's to read
int repeat = 1; //a loop for repeating the transaction
//2. Set master identifier
//3. Setup serial parameters
SerialParameters params = new SerialParameters();
params.setPortName("/dev/ttyUSB0");
params.setBaudRate(19200);
params.setDatabits(8);
params.setParity("Even");
params.setStopbits(1);
params.setEncoding("tru");
params.setEcho(false);
//4. Open the connection
con = new SerialConnection(params);
con.open();
//5. Prepare a request
req = new ReadInputRegistersRequest(ref, count);
req.setUnitID(unitid);
req.setHeadless();
//6. Prepare a transaction
trans = new ModbusSerialTransaction(con);
trans.setRequest(req);
//7. Execute the transaction repeat times
int k = 0;
do {
trans.execute();
res = (ReadInputRegistersResponse) trans.getResponse();
for (int n = 0; n < res.getWordCount(); n++) {
System.out.println("Word " + n + "=" + res.getRegisterValue(n));
}
k++;
} while (k < repeat);
//8. Close the connection
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
But I have exeption 91.
java.lang.Exception
at net.wimpi.modbus.net.SerialConnection.open(SerialConnection.java:91)
What it means?
How fix it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello.
I have code
//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 mbTest {
public static void main(String[] args) {
try {
/ The important instances of the classes mentioned before /
SerialConnection con = null; //the connection
ModbusSerialTransaction trans = null; //the transaction
ReadInputRegistersRequest req = null; //the request
ReadInputRegistersResponse res = null; //the response
// ModbusCoupler.createModbusCoupler(null);
ModbusCoupler.getReference().setUnitID(1);
}
}
But I have exeption 91.
java.lang.Exception
at net.wimpi.modbus.net.SerialConnection.open(SerialConnection.java:91)
What it means?
How fix it?
my jars
Please note that it isn't Exception 91, but an Exception in line 91 of SerialConnection.
You should consider the j2mod variant of Steve O'Hara though.