|
28 | 28 | import random |
29 | 29 | import re |
30 | 30 | import struct |
| 31 | +import time |
31 | 32 |
|
32 | 33 | # VXI-11 RPC constants |
33 | 34 |
|
@@ -1024,6 +1025,52 @@ def send_ifc(self): |
1024 | 1025 | if error: |
1025 | 1026 | raise Vxi11Exception(error, 'send_ifc') |
1026 | 1027 |
|
| 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 | + |
1027 | 1074 |
|
1028 | 1075 | class Instrument(Device): |
1029 | 1076 | "VXI-11 instrument interface client" |
|
0 commit comments