java - Illegal data address exception in j2mod -




hello using j2mod serial connection modbus device , exception com.ghgande.j2mod.modbus.modbusslaveexception: illegal data address there me . below code.

public static void main(string[] args) throws exception {     serialconnection con = null;     modbusserialtransaction trans = null;     readmultipleregistersrequest req = null;     readmultipleregistersresponse res = null;      string portname= "com4"; //the name of serial port used     int unitid = 1; //the unit identifier talking     int ref = 41799; //the reference, start reading     int count = 100; //the count of ir's read     int repeat = 1; //a loop repeating transaction     // modbuscoupler.createmodbuscoupler(null);     modbuscoupler.getreference().setunitid(1);      serialparameters params = new serialparameters();     params.setportname(portname);     params.setbaudrate(19200);     params.setdatabits(8);     params.setparity("none");     params.setstopbits(1);     params.setencoding(modbus.serial_encoding_rtu);     params.setecho(false);      //4. open connection     con = new serialconnection(params);     con.open();      //5. prepare request     req = new readmultipleregistersrequest(ref, count);     req.setunitid(unitid);     req.setheadless();      //6. prepare transaction     trans = new modbusserialtransaction(con);     trans.setrequest(req);      int k = 0;     {       trans.execute();       res = (readmultipleregistersresponse) trans.getresponse();       (int n = 0; n < res.getwordcount(); n++) {         system.out.println("word " + n + "=" + res.getregistervalue(n));       }       k++;     } while (k < repeat);      //8. close connection     con.close();   } 

illegal data address modbus exception indicates trying access non-existent registers.

in code try access registers 41799-42798. device not have these registers.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -