You can do this in two ways:
1) Check if it is in get_instruments_list ()
from visa import *
my_instrument_name = "GPIB::14"
if my_instrument_name in visa.get_instruments_list():
print('Instrument exists connecting to it')
my_instrument = instrument(my_instrument_name)
else:
print('Instrument not found, not connecting')
2) Try to connect and catch the exception, you will need to wait for the timeout
from visa import *
my_instrument_name = "GPIB::14"
try:
my_instrument = instrument(my_instrument_name)
print('Instrument connected')
except(visa.VisaIOError):
print('Instrument not connected (timeout error)')
source
share