Esempio n. 1
0
def runner(parser, options, args):
    task = DigitalInputTask()

    print('Created DigitalInputTask %s (task.value=%s)' % (task, task.value))

    args, kws = get_method_arguments('create_channel', options)
    print('create_channel', kws)
    task.create_channel(**kws)

    channels = task.get_names_of_channels()
    if not channels:
        print('No channels specified')
        return

    print('task start')
    task.start()
    args, read_kws = get_method_arguments('di_read', options)
    kws = read_kws
    fill_mode = kws.get('fill_mode', 'group_by_scan_number')
    print('read', read_kws)

    if options.di_task == 'print':
        try:
            data, bytes_per_sample = task.read(**kws)
        finally:
            del task
        print(bytes_per_sample)
        print(data)
    else:
        del task
        raise NotImplementedError(repr(options.di_task))
Esempio n. 2
0
def runner (parser, options, args):
    task = DigitalInputTask()
  
    print 'Created DigitalInputTask %s (task.value=%s)' % (task, task.value)
  
    args, kws = get_method_arguments('create_channel', options)
    print 'create_channel', kws
    task.create_channel (**kws)
  
    channels = task.get_names_of_channels()
    if not channels:
        print 'No channels specified'
        return
  
    print 'task start'
    task.start()
    args, read_kws = get_method_arguments('di_read', options)
    kws = read_kws
    fill_mode = kws.get ('fill_mode', 'group_by_scan_number')
    print 'read', read_kws
  
    if options.di_task=='print':
        try:
            data, bytes_per_sample = task.read (**kws)
        finally:
            del task
        print bytes_per_sample
        print data
    else:
        del task
        raise NotImplementedError (`options.di_task`)
Esempio n. 3
0
def runner(parser, options, args):
    task = DigitalOutputTask()

    print 'Created DigitalOutputTask %s (task.value=%s)' % (task, task.value)

    args, kws = get_method_arguments('create_channel', options)
    print 'create_channel', kws
    task.create_channel(**kws)

    channels = task.get_names_of_channels()
    if not channels:
        print 'No channels specified'
        return

    args, kws = get_method_arguments('ao_write', options)
    layout = kws.get('layout', 'group_by_scan_number')

    if not options.do_write_auto_start:
        task.start()

    if options.do_task == 'tenfive':
        try:
            for n in range(options.do_task_duration):
                if n % 2:
                    data = np.array([1, 0, 1, 0], dtype=np.uint8)
                else:
                    data = np.array([0, 1, 0, 1], dtype=np.uint8)
                task.write(data.ravel(), **kws)
                time.sleep(1)
        except KeyboardInterrupt:
            print 'Caught Ctrl-C.'
        task.stop()
        del task
        return

    if options.do_task == 'scalar0':
        data = np.uint8(0)
    elif options.do_task == 'scalar1':
        data = np.uint8(1)
    elif options.do_task == 'ten':  # 1010
        data = np.array([1, 0, 1, 0], dtype=np.uint8)
    else:
        raise ` options.do_task `

    if layout == 'group_by_scan_number':
        data = data.T

    print 'samples available/written per channel= %s/%s ' % (
        data.size // len(channels), task.write(data.ravel(), **kws))

    try:
        time.sleep(options.do_task_duration)
    except KeyboardInterrupt:
        print 'Caught Ctrl-C.'

    task.stop()
    del task
Esempio n. 4
0
def runner (parser, options, args):
    task = DigitalOutputTask()

    print('Created DigitalOutputTask %s (task.value=%s)' % (task, task.value))

    args, kws = get_method_arguments('create_channel', options)
    print('create_channel', kws)
    task.create_channel (**kws)

    channels = task.get_names_of_channels()
    if not channels:
        print('No channels specified')
        return

    args, kws = get_method_arguments('ao_write', options)
    layout = kws.get('layout', 'group_by_scan_number')

    if not options.do_write_auto_start:
        task.start()

    if options.do_task=='tenfive':
        try:
            for n in range(options.do_task_duration):
                if n%2:
                    data = np.array([1,0,1,0], dtype=np.uint8)
                else:
                    data = np.array([0,1,0,1], dtype=np.uint8)
                task.write (data.ravel (), **kws)
                time.sleep(1)
        except KeyboardInterrupt:
            print('Caught Ctrl-C.')
        task.stop ()
        del task
        return

    if options.do_task=='scalar0':
        data = np.uint8(0)
    elif options.do_task=='scalar1':
        data = np.uint8(1)
    elif options.do_task=='ten': # 1010
        data = np.array([1,0,1,0], dtype=np.uint8)
    else:
        raise NotImplementedError (repr(options.do_task))

    if layout=='group_by_scan_number':
        data = data.T

    print('samples available/written per channel= %s/%s ' % (data.size//len(channels), task.write(data.ravel(), **kws)))

    try:
        time.sleep (options.do_task_duration)
    except KeyboardInterrupt:
        print('Caught Ctrl-C.')

    task.stop ()
    del task
Esempio n. 5
0
def runner(parser, options, args):
    task = AnalogInputTask()

    print('Created AnalogInputTask %s (task.value=%s)' % (task, task.value))

    args, kws = get_method_arguments('create_voltage_channel', options)
    print('create_voltage_channel', kws)
    task.create_voltage_channel(**kws)

    channels = task.get_names_of_channels()
    if not channels:
        print('No channels specified')
        return

    args, kws = get_method_arguments('configure_timing_sample_clock', options)
    print('configure_timing_sample_clock', kws)
    clock_rate = kws.get('rate', 1000.0)
    task.configure_timing_sample_clock(**kws)
    print('task')
    task.start()
    args, read_kws = get_method_arguments('ai_read', options)
    kws = read_kws
    fill_mode = kws.get('fill_mode', 'group_by_scan_number')
    print('read', read_kws)

    if options.ai_task == 'show':
        from nidaqmx.wxagg_plot import animated_plot
        start_time = time.time()

        def func(task=task):
            current_time = time.time()
            data = task.read(**read_kws)
            if fill_mode == 'group_by_scan_number':
                data = data.T
            tm = np.arange(data.shape[-1], dtype=float) / clock_rate + (
                current_time - start_time)
            return tm, data, channels

        try:
            animated_plot(func,
                          1000 * (task.samples_per_channel / clock_rate + 0.1))
        finally:
            del task
        return
    elif options.ai_task == 'print':
        try:
            data = task.read(**kws)
        finally:
            del task
        print(data)
    else:
        del task
        raise NotImplementedError(repr(options.ai_task))
Esempio n. 6
0
def runner (parser, options, args):
    task = AnalogInputTask()

    print('Created AnalogInputTask %s (task.value=%s)' % (task, task.value))

    args, kws = get_method_arguments('create_voltage_channel', options)
    print('create_voltage_channel', kws)
    task.create_voltage_channel (**kws)

    channels = task.get_names_of_channels()
    if not channels:
        print('No channels specified')
        return

    args, kws = get_method_arguments('configure_timing_sample_clock', options)
    print('configure_timing_sample_clock', kws)
    clock_rate = kws.get('rate', 1000.0)
    task.configure_timing_sample_clock(**kws)
    print('task')
    task.start()
    args, read_kws = get_method_arguments('ai_read', options)
    kws = read_kws
    fill_mode = kws.get ('fill_mode', 'group_by_scan_number')
    print('read', read_kws)

    if options.ai_task=='show':
        from nidaqmx.wxagg_plot import animated_plot
        start_time = time.time()
        def func(task=task):
            current_time = time.time()
            data = task.read(**read_kws)
            if fill_mode == 'group_by_scan_number':
                data = data.T
            tm = np.arange(data.shape[-1], dtype=float)/clock_rate + (current_time - start_time)
            return tm, data, channels
        try:
            animated_plot(func, 1000*(task.samples_per_channel/clock_rate+0.1))
        finally:
            del task
        return
    elif options.ai_task=='print':
        try:
            data = task.read (**kws)
        finally:
            del task
        print(data)
    else:
        del task
        raise NotImplementedError (repr(options.ai_task))
Esempio n. 7
0
def runner(parser, options, args):
    task = AnalogOutputTask()
    args, kws = get_method_arguments('create_voltage_channel', options)
    phys_channel = kws['phys_channel']
    task.create_voltage_channel(**kws)

    channels = task.get_names_of_channels()
    if not channels:
        print 'No channels specified'
        return

    args, kws = get_method_arguments('configure_timing_sample_clock', options)
    clock_rate = kws.get('rate', 1000.0)

    if not task.configure_timing_sample_clock(**kws):
        return

    args, kws = get_method_arguments('ao_write', options)
    layout = kws.get('layout', 'group_by_scan_number')

    if options.ao_task == 'sin':
        min_val = task.get_min(phys_channel)
        max_val = task.get_max(phys_channel)
        samples_per_channel = clock_rate / len(channels)
        x = np.arange(samples_per_channel,
                      dtype=float) * 2 * np.pi / samples_per_channel
        data = []
        for index, channel in enumerate(channels):
            data.append(0.5 * (max_val + min_val) + 0.5 * (max_val - min_val) *
                        np.sin(x - 0.5 * index * np.pi / len(channels)))
        data = np.array(data)
        if layout == 'group_by_scan_number':
            data = data.T
    else:
        raise NotImplementedError( ` options.ai_task `)
    print 'samples available/written per channel= %s/%s ' % (
        data.size // len(channels), task.write(data.ravel(), **kws))

    if not options.ao_write_auto_start:
        task.start()
    try:
        time.sleep(options.ao_task_duration)
    except KeyboardInterrupt, msg:
        print 'Caught Ctrl-C.'
Esempio n. 8
0
def runner (parser, options, args):
    task = AnalogOutputTask()
    args, kws = get_method_arguments('create_voltage_channel', options)
    phys_channel = kws['phys_channel']
    task.create_voltage_channel (**kws)

    channels = task.get_names_of_channels()
    if not channels:
        print('No channels specified')
        return

    args, kws = get_method_arguments('configure_timing_sample_clock', options)
    clock_rate = kws.get('rate', 1000.0)

    if not task.configure_timing_sample_clock(**kws):
        return

    args, kws = get_method_arguments('ao_write', options)
    layout = kws.get('layout', 'group_by_scan_number')

    if options.ao_task=='sin':
        min_val = task.get_min(phys_channel)
        max_val = task.get_max(phys_channel)
        samples_per_channel = clock_rate / len(channels)
        x = np.arange(samples_per_channel, dtype=float)*2*np.pi/samples_per_channel
        data = []
        for index, channel in enumerate(channels):
            data.append(0.5*(max_val+min_val) + 0.5*(max_val-min_val)*np.sin(x-0.5*index*np.pi/len(channels)))
        data = np.array(data)
        if layout=='group_by_scan_number':
            data = data.T
    else:
        raise NotImplementedError (repr(options.ao_task))
    print('samples available/written per channel= %s/%s ' % (data.size//len(channels), task.write(data.ravel(), **kws)))

    if not options.ao_write_auto_start:
        task.start()
    try:
        time.sleep(options.ao_task_duration)
    except KeyboardInterrupt as msg:
        print('Caught Ctrl-C.')
    task.stop()
    del task