Menu

Example. Cant start. net.wimpi.modbus.net.SerialConnection.open(SerialConnection.java:91)

Alexey
2016-04-27
2016-05-30
  • Alexey

    Alexey - 2016-04-27

    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
    

    // ModbusCoupler.createModbusCoupler(null);
    ModbusCoupler.getReference().setUnitID(1);

        //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?

     
  • Bram Bouwens

    Bram Bouwens - 2016-05-30

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.