Skip to content
This repository was archived by the owner on Feb 2, 2026. It is now read-only.

Commit 689e84c

Browse files
committed
Add find_listeners
1 parent 14bbec0 commit 689e84c

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

vxi11/vxi11.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import random
2929
import re
3030
import struct
31+
import time
3132

3233
# VXI-11 RPC constants
3334

@@ -1024,6 +1025,52 @@ def send_ifc(self):
10241025
if error:
10251026
raise Vxi11Exception(error, 'send_ifc')
10261027

1028+
def find_listeners(self, address_list=None):
1029+
"Find devices"
1030+
if address_list is None:
1031+
address_list = range(31)
1032+
1033+
found = []
1034+
1035+
for addr in address_list:
1036+
# check for listener at primary address
1037+
cmd = bytearray([GPIB_CMD_UNL, GPIB_CMD_UNT])
1038+
cmd.append(self._bus_address | GPIB_CMD_TAD) # spec says this is unnecessary, but doesn't appear to work without this
1039+
if type(addr) == tuple:
1040+
addr = addr[0]
1041+
if addr < 0 or addr > 30:
1042+
raise Vxi11Exception("Invalid address", 'find_listeners')
1043+
cmd.append(addr | GPIB_CMD_LAD)
1044+
self.send_command(cmd)
1045+
self.set_atn(False)
1046+
time.sleep(0.0015) # probably not necessary due to network delays
1047+
if self.test_ndac():
1048+
found.append(addr)
1049+
else:
1050+
# check for listener at any sub-address
1051+
cmd = bytearray([GPIB_CMD_UNL, GPIB_CMD_UNT])
1052+
cmd.append(self._bus_address | GPIB_CMD_TAD) # spec says this is unnecessary, but doesn't appear to work without this
1053+
cmd.append(addr | GPIB_CMD_LAD)
1054+
for sa in range(31):
1055+
cmd.append(sa | GPIB_CMD_SAD)
1056+
self.send_command(cmd)
1057+
self.set_atn(False)
1058+
time.sleep(0.0015) # probably not necessary due to network delays
1059+
if self.test_ndac():
1060+
# find specific sub-address
1061+
for sa in range(31):
1062+
cmd = bytearray([GPIB_CMD_UNL, GPIB_CMD_UNT])
1063+
cmd.append(self._bus_address | GPIB_CMD_TAD) # spec says this is unnecessary, but doesn't appear to work without this
1064+
cmd.append(addr | GPIB_CMD_LAD)
1065+
cmd.append(sa | GPIB_CMD_SAD)
1066+
self.send_command(cmd)
1067+
self.set_atn(False)
1068+
time.sleep(0.0015) # probably not necessary due to network delays
1069+
if self.test_ndac():
1070+
found.append((addr, sa))
1071+
1072+
return found
1073+
10271074

10281075
class Instrument(Device):
10291076
"VXI-11 instrument interface client"

0 commit comments

Comments
 (0)