def __getitem__(self, index): """ Indexes a subset of devices on this device collection. Args: index: The value of the index. The following index types are supported: - str: Name of the device. You also can specify a string that contains a list or range of names to this input. If you have a list of names, use the DAQmx Flatten Channel String function to convert the list to a string. - int: Index/position of the device in the collection. - slice: Range of the indexes/positions of devices in the collection. Returns: List[nidaqmx.system.device.Device]: Indicates the subset of devices indexed. """ if isinstance(index, six.integer_types): return Device(self.device_names[index]) elif isinstance(index, slice): return [Device(name) for name in self.device_names[index]] elif isinstance(index, six.string_types): device_names = unflatten_channel_string(index) if len(device_names) == 1: return Device(device_names[0]) return [Device(name) for name in device_names] else: raise DaqError( 'Invalid index type "{0}" used to access collection.'.format( type(index)), DAQmxErrors.UNKNOWN.value)
def devices(self): """ List[:class:`nidaqmx.system.device.Device`]: Indicates a list of Device objects representing all the devices in the task. """ cfunc = lib_importer.windll.DAQmxGetTaskDevices cfunc.argtypes = [ lib_importer.task_handle, ctypes.c_char_p, ctypes.c_uint] temp_size = 0 while True: val = ctypes.create_string_buffer(temp_size) size_or_code = cfunc( self._handle, val, temp_size) if is_string_buffer_too_small(size_or_code): # Buffer size must have changed between calls; check again. temp_size = 0 elif size_or_code > 0 and temp_size == 0: # Buffer size obtained, use to retrieve data. temp_size = size_or_code else: break check_for_error(size_or_code) return [Device(v) for v in unflatten_channel_string(val.value.decode('ascii'))]
def get_digital_pull_up_pull_down_states(self, device_name): """ Gets the resistor level for lines when they are in tristate logic. Args: device_name (str): Specifies the name as configured in MAX of the device to which this operation applies. Returns: List[nidaqmx.types.DOResistorPowerUpState]: Contains the physical channels and power up states set. Each element of the list contains a physical channel and the power up state set for that physical channel. - physical_channel (str): Indicates the physical channel that was modified. - power_up_state (:class:`nidaqmx.constants.ResistorState`): Indicates the power up state set for the physical channel specified with the **physical_channel** output. """ states = [] device = Device(device_name) args = [device_name] argtypes = [ctypes_byte_str] for do_line in device.do_lines: state = ctypes.c_int() states.append(state) args.append(do_line.name) argtypes.append(ctypes_byte_str) args.append(ctypes.byref(state)) argtypes.append(ctypes.POINTER(ctypes.c_int)) args.append(None) cfunc = lib_importer.cdll.DAQmxGetDigitalPullUpPullDownStates with cfunc.arglock: cfunc.argtypes = argtypes error_code = cfunc(*args) check_for_error(error_code) power_up_states = [] for d, p in zip(device.do_lines, states): power_up_states.append( DOResistorPowerUpState( physical_channel=d.name, power_up_state=ResistorState(p.value))) return power_up_states
def get_device_info(): from nidaqmx.system import System from nidaqmx.system.device import Device system_ni_daq = System() sys_local = system_ni_daq.local() name_device = sys_local.devices.device_names device_local = Device(name_device[0]) info_device = { "list_devices": name_device, "list_ports": device_local.ai_physical_chans.channel_names } return info_device
def get_analog_power_up_states(self, device_name): """ Gets the power up states for analog physical channels. Args: device_name (str): Specifies the name as configured in MAX of the device to which this operation applies. Returns: power_up_states (List[nidaqmx.types.AOPowerUpState]): Contains the physical channels and power up states set. Each element of the list contains a physical channel and the power up state set for that physical channel. - physical_channel (str): Specifies the physical channel that was modified. - power_up_state (float): Specifies the power up state set for the physical channel specified with the **physical_channel** input. - channel_type (:class:`nidaqmx.constants.AOPowerUpOutputBehavior`): Specifies the output type for the physical channel specified with the **physical_channel** input. """ states = [] channel_types = [] device = Device(device_name) args = [device_name] argtypes = [ctypes_byte_str] for ao_physical_chan in device.ao_physical_chans: state = ctypes.c_double() states.append(state) channel_type = ctypes.c_int() channel_types.append(channel_type) args.append(ao_physical_chan.name) argtypes.append(ctypes_byte_str) args.append(ctypes.byref(state)) argtypes.append(ctypes.POINTER(ctypes.c_double)) args.append(ctypes.byref(channel_type)) argtypes.append(ctypes.POINTER(ctypes.c_int)) args.append(None) cfunc = lib_importer.cdll.DAQmxGetAnalogPowerUpStates with cfunc.arglock: cfunc.argtypes = argtypes error_code = cfunc(*args) check_for_error(error_code) power_up_states = [] for a, p, c in zip(device.ao_physical_chans, states, channel_types): power_up_states.append( AOPowerUpState( physical_channel=a.name, power_up_state=p.value, channel_type=AOPowerUpOutputBehavior(c.value))) return power_up_states
def __reversed__(self): device_names = self.device_names device_names.reverse() for device_name in device_names: yield Device(device_name)
def __iter__(self): for device_name in self.device_names: yield Device(device_name)
def __iter__(self): for device_name in self.device_names: # if (self.debug_mode): # print("device_collection.device_name iter:\t" + str(device_name)) yield Device(device_name, self.debug_mode)