def find_devices(self, filter_in_use=True): """Return a list of port numbers which can be used with :func:`open`. If *filter_in_use* parameter is `True` devices which are already opened will be filtered from the list. If set to `False`, the port numbers are still included in the returned list and the user may get an :class:`IOError` if the port number is used with :func:`open`. """ # first fetch the number of attached devices, so we can create a buffer # with the exact amount of entries. api expects array of u16 num_devices = api.py_aa_find_devices(0, array_u16(0)) assert num_devices > 0 devices = array_u16(num_devices) num_devices = api.py_aa_find_devices(num_devices, devices) assert num_devices > 0 del devices[num_devices:] if filter_in_use: devices = [d for d in devices if not d & PORT_NOT_FREE] else: devices = [d & ~PORT_NOT_FREE for d in devices] return devices
def aa_find_devices (devices): """usage: (int return, u16[] devices) = aa_find_devices(u16[] devices) All arrays can be passed into the API as an ArrayType object or as a tuple (array, length), where array is an ArrayType object and length is an integer. The user-specified length would then serve as the length argument to the API funtion (please refer to the product datasheet). If only the array is provided, the array's intrinsic length is used as the argument to the underlying API function. Additionally, for arrays that are filled by the API function, an integer can be passed in place of the array argument and the API will automatically create an array of that length. All output arrays, whether passed in or generated, are passed back in the returned tuple.""" if not AA_LIBRARY_LOADED: return AA_INCOMPATIBLE_LIBRARY # devices pre-processing __devices = isinstance(devices, int) if __devices: (devices, num_devices) = (array_u16(devices), devices) else: (devices, num_devices) = isinstance(devices, ArrayType) and (devices, len(devices)) or (devices[0], min(len(devices[0]), int(devices[1]))) if devices.typecode != 'H': raise TypeError("type for 'devices' must be array('H')") # Call API function (_ret_) = api.py_aa_find_devices(num_devices, devices) # devices post-processing if __devices: del devices[max(0, min(_ret_, len(devices))):] return (_ret_, devices)