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 count(high_time, low_time, samples): global Reader, data print('Configure internal connections..') system = System.local() system.connect_terms('/Dev1/PFI32', '/Dev1/RTSI0') with Task('ct1_task') as ct1_task, Task('timer') as timer_task: data = np.zeros(samples) # configure counter channel and task ct1 = ct1_task.ci_channels.add_ci_pulse_width_chan( 'Dev1/ctr2', 'counter', min_val=2, max_val=100000000, units=TimeUnits.TICKS) ct1_task.timing.cfg_implicit_timing(samps_per_chan=samples) ct1.ci_ctr_timebase_src = '/Dev1/PFI31' ct1.ci_pulse_width_term = '/Dev1/RTSI0' Reader = CounterReader(ct1_task.in_stream) ct1_task.register_every_n_samples_acquired_into_buffer_event( 1, sample_readies) ct1_task.start() timer_task.co_channels.add_co_pulse_chan_time( 'Dev1/ctr1', high_time=high_time, low_time=low_time) timer_task.timing.cfg_implicit_timing( sample_mode=AcquisitionType.FINITE, samps_per_chan=samples) timer_task.start() while not timer_task.is_task_done(): time.sleep(0.001) print(data) print(len(data))
def write_data_to_file_from_nidaq(amount_of_second=10, path_file="", name_device="Dev1", channel="ai0"): pass_time = time.time() list_name_device = System().devices.device_names if name_device in list_name_device: task = nidaqmx.Task() channel_port = name_device + "/" + channel task.ai_channels.add_ai_voltage_chan(channel_port) file = open(path_file, "w") while True: present_time = time.time() if present_time - pass_time > amount_of_second: task.close() file.close() break data = task.read() file.write(str(data) + "\n")
def __init__(self, yaml_file: str): with open(yaml_file) as f: self.config = yaml.full_load(f) # Do connections self.system = System.local() if 'connections' in self.config: term_from = self.config['connections']['from'] terms_to = self.config['connections']['to'] for term_to in terms_to: self.system.connect_terms(term_from, term_to) print('Connect', term_from, 'to', term_to) else: print("Do not find the connectios in the config file") self._timer = PulseTimeGenerator(self.config['timer']['channel']) self._channels = {} self._channels_started = [] if 'counters' in self.config: for name, config in self.config['counters'].items(): self._channels[name] = PulseCounter(config['channel'], name, config['gate'], config['source']) else: print("Do not find the counters in the config file") # TODO implement encoder capture if 'position_capture' in self.config: for name, config in self.config['position_capture'].items(): channel = config['channel'] trigger = config['trigger'] encoder = config['encoder'] options = self._encoder_to_object(encoder['type'], encoder['zindexphase'], encoder['angleunit']) if False not in options: self._channels[name] = CapturePosition( channel, name, trigger, options[0], options[1], options[2]) else: print("At least one of the parameters is wrong") else: print("Do not find the position capture in the config file")
def __init__(self, yaml_file): with open(yaml_file) as f: self.config = yaml.full_load(f) # Do connections self.system = System.local() self.system.devices term_from = self.config['connections']['from'] terms_to = self.config['connections']['to'] for term_to in terms_to: self.system.connect_terms(term_from, term_to) print('Connect', term_from, 'to', term_to) self._timer = PulseGenerator(self.config['timer']['channel']) self._counters = {} for name, config in self.config['counters'].items(): self._counters[name] = PulseCounter(config['channel'], name, config['gate'], config['source'])
def get_number_of_devices(system=True, drivers=False): errors = (FileNotFoundError, DaqNotFoundError) has_drivers = True try: from __main__ import PyInstallerImportError errors += (PyInstallerImportError, ) except ImportError: pass the_system = System.local() try: num_of_devices = len(the_system.devices) except errors: num_of_devices = 0 has_drivers = False if system and drivers: return the_system, num_of_devices, has_drivers elif system: return the_system, num_of_devices elif drivers: return has_drivers, num_of_devices else: return num_of_devices
def get_adc_device_name(): system = System() return system.devices.device_names[0]
def scanserial(): sys = System.local() for i, dev in enumerate(sys.devices): print("%s. %s" % (i + 1, dev.name)) devices = sys.devices return devices