close()#

ModbusRTUTransport.close(holder: object | None = None) → None#

Close and teardown; with a holder, remove it and tear down only when the last owner leaves.

A holder that needs to talk to the instrument before the connection goes (releasing a remote lock, say) does that in its own close before calling this, while the session is still up.

Raises UnknownHolderError when an unrecognized holder closes while others still own the connection, because that is the case where ignoring it silently strands the real owners and leaves the connection open forever. Once the last owner has left there is nothing to strand, so a repeat close is a no-op and close stays idempotent.