Check that resource manager session is active before trying to close an instrument

If the Resource Manager is closed before an instrument, the instruments sessions
are invalidated by the VISA library. This patch check for that before trying to
close an instrument.

See #33