Menu

getUnitID

Help
Anonymous
2013-04-02
2013-05-28
  • Anonymous

    Anonymous - 2013-04-02

    Hello,

    I would like to define specific slave ID for a modbus transaction.

    Using a specifixc software (Multiway, developped by Omron), I know that I am able to define a specific slave ID by using the setUnitID function.

    Nevertheless, I am unable to retrieve this ID by using my own program :-(

    This is the code to define the TCP/IP modbus transaction (and it works)

    int nb_data = dataToSend.length;
    int indice_tab_modbus;
    unitID = dataToSend;
    for (int i=1 ; i<nb_data ; ++i) {
      indice_tab_modbus = i-1;
      SimpleRegister reg = new SimpleRegister(dataToSend_);
      write_req = new WriteSingleRegisterRequest(indice_tab_modbus, reg);
      write_req.setUnitID(unitID);

      //Prepare the transaction
    trans = new ModbusTCPTransaction(con);
    trans.setRequest(write_req);
    try {
       trans.execute();
    } catch (Exception ex) {
    }

    This is the code to retrieve the transaction

    req = new ReadMultipleRegistersRequest(reference, count);

    //4. Prepare the transaction
    openConnection();
    trans = new ModbusTCPTransaction(con);
    trans.setRequest(req);

    //5. Execute the transaction repeat times
    try {
       trans.execute();
    } catch (Exception ex) {
    }

    res = (ReadMultipleRegistersResponse) trans.getResponse();
    unitID = res.getUnitID();
    for (int i_ec = 0 ; i_ec < count ; ++i_ec) {
      tab_in = res.getRegisterValue(i_ec);
    }

    This code works too, but unitID value is always 0, event if it is different when I define the transaction.

    Can I have advices?

    Regards_

     
  • Dieter Wimberger

    Hi,

    If you are using jamod as the slave, then you need to set the unit identifier on the ModbusCopuler.
    http://jamod.sourceforge.net/apidocs/net/wimpi/modbus/ModbusCoupler.html

    If you are using jamod as master, then I would suggest to look at the debug output (hex messages)
    to see whether or not the slave you are talking to actually  sends the
    identifier and diagnose from there.

    Commonly the unit identifier is used by tcp to serial gateways.

    Regards,
    Dieter

     

Log in to post a comment.