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
/*Variablesforstoringtheparameters*/// String portname= null; //the name of the serial port to be usedintunitid=3;//the unit identifier we will be talking tointref=100;//the reference, where to start reading fromintcount=15;//the count of IR's to readintrepeat=1;//a loop for repeating the transaction//2. Set master identifier
//3. Setup serial parametersSerialParametersparams=newSerialParameters();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 connectioncon=newSerialConnection(params);con.open();//5. Prepare a requestreq=newReadInputRegistersRequest(ref,count);req.setUnitID(unitid);req.setHeadless();//6. Prepare a transactiontrans=newModbusSerialTransaction(con);trans.setRequest(req);//7. Execute the transaction repeat timesintk=0;do{trans.execute();res=(ReadInputRegistersResponse)trans.getResponse();for(intn=0;n<res.getWordCount();n++){System.out.println("Word "+n+"="+res.getRegisterValue(n));}k++;}while(k<repeat);//8. Close the connectioncon.close();}catch(Exceptionex){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.