Menu

Some modbus tcp slaves require slave id

tskjot
2016-02-09
2016-04-06
  • tskjot

    tskjot - 2016-02-09

    Some Modbus TCP slaves seem to require the setting of the modbus unit id in the modbus tcp packets, even though this should not be necessary. To ensure maximal interoperability, I suggest adding the unitid paramter to the methods in ModbusTCPMaster.java as in the following example:

      public synchronized BitVector readCoils(int unitid, int ref, int count)
          throws ModbusException {
        m_ReadCoilsRequest.setUnitID(unitid);
        m_ReadCoilsRequest.setReference(ref);
        m_ReadCoilsRequest.setBitCount(count);
        m_Transaction.setRequest(m_ReadCoilsRequest);
        m_Transaction.execute();
        BitVector bv = ((ReadCoilsResponse) m_Transaction.getResponse()).getCoils();
        bv.forceSize(count);
        return bv;
      }
    
     
  • Steve

    Steve - 2016-03-28

    This has been incorporated in v2.0 - available soon

     
  • Dan Salt

    Dan Salt - 2016-04-05

    Same goes for the ModbusCoupler. It has a unit_id field (private), but no way to set it via the API. I'm converting from Jamod to j2mod (so many improvements -- great work), and that method (setUnitId()) is one that's missing in the refactored code.

    Thanks,
    Dan

     
  • Steve

    Steve - 2016-04-06

    Check out the v2.0 - this is a junit tested scenario so you should find it works fine now.

     

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.