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;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
This has been incorporated in v2.0 - available soon
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
Check out the v2.0 - this is a junit tested scenario so you should find it works fine now.