@@ -1048,42 +1048,48 @@ def find_listeners(self, address_list=None):
10481048
10491049 found = []
10501050
1051- for addr in address_list :
1052- # check for listener at primary address
1053- cmd = bytearray ([GPIB_CMD_UNL , GPIB_CMD_UNT ])
1054- cmd .append (self ._bus_address | GPIB_CMD_TAD ) # spec says this is unnecessary, but doesn't appear to work without this
1055- if type (addr ) == tuple :
1056- addr = addr [0 ]
1057- if addr < 0 or addr > 30 :
1058- raise Vxi11Exception ("Invalid address" , 'find_listeners' )
1059- cmd .append (addr | GPIB_CMD_LAD )
1060- self .send_command (cmd )
1061- self .set_atn (False )
1062- time .sleep (0.0015 ) # probably not necessary due to network delays
1063- if self .test_ndac ():
1064- found .append (addr )
1065- else :
1066- # check for listener at any sub-address
1051+ try :
1052+ self .lock ()
1053+ for addr in address_list :
1054+ # check for listener at primary address
10671055 cmd = bytearray ([GPIB_CMD_UNL , GPIB_CMD_UNT ])
10681056 cmd .append (self ._bus_address | GPIB_CMD_TAD ) # spec says this is unnecessary, but doesn't appear to work without this
1057+ if type (addr ) is tuple :
1058+ addr = addr [0 ]
1059+ if addr < 0 or addr > 30 :
1060+ raise Vxi11Exception ("Invalid address" , 'find_listeners' )
10691061 cmd .append (addr | GPIB_CMD_LAD )
1070- for sa in range (31 ):
1071- cmd .append (sa | GPIB_CMD_SAD )
10721062 self .send_command (cmd )
10731063 self .set_atn (False )
10741064 time .sleep (0.0015 ) # probably not necessary due to network delays
10751065 if self .test_ndac ():
1076- # find specific sub-address
1066+ found .append (addr )
1067+ else :
1068+ # check for listener at any sub-address
1069+ cmd = bytearray ([GPIB_CMD_UNL , GPIB_CMD_UNT ])
1070+ cmd .append (self ._bus_address | GPIB_CMD_TAD ) # spec says this is unnecessary, but doesn't appear to work without this
1071+ cmd .append (addr | GPIB_CMD_LAD )
10771072 for sa in range (31 ):
1078- cmd = bytearray ([GPIB_CMD_UNL , GPIB_CMD_UNT ])
1079- cmd .append (self ._bus_address | GPIB_CMD_TAD ) # spec says this is unnecessary, but doesn't appear to work without this
1080- cmd .append (addr | GPIB_CMD_LAD )
10811073 cmd .append (sa | GPIB_CMD_SAD )
1082- self .send_command (cmd )
1083- self .set_atn (False )
1084- time .sleep (0.0015 ) # probably not necessary due to network delays
1085- if self .test_ndac ():
1086- found .append ((addr , sa ))
1074+ self .send_command (cmd )
1075+ self .set_atn (False )
1076+ time .sleep (0.0015 ) # probably not necessary due to network delays
1077+ if self .test_ndac ():
1078+ # find specific sub-address
1079+ for sa in range (31 ):
1080+ cmd = bytearray ([GPIB_CMD_UNL , GPIB_CMD_UNT ])
1081+ cmd .append (self ._bus_address | GPIB_CMD_TAD ) # spec says this is unnecessary, but doesn't appear to work without this
1082+ cmd .append (addr | GPIB_CMD_LAD )
1083+ cmd .append (sa | GPIB_CMD_SAD )
1084+ self .send_command (cmd )
1085+ self .set_atn (False )
1086+ time .sleep (0.0015 ) # probably not necessary due to network delays
1087+ if self .test_ndac ():
1088+ found .append ((addr , sa ))
1089+ self .unlock ()
1090+ except :
1091+ self .unlock ()
1092+ raise
10871093
10881094 return found
10891095
0 commit comments