Ejemplo n.º 1
0
class Relay:

    def __init__(self, channel, value=0):
        ''' Simple relay class

        Input params:
        channel : name of digital channel. E.g. "Dev2/port1/line0"
        value=0 : starting value of the output.
        '''
        self._relay = DigitalOutputTask()
        self._relay.create_channel(channel)
        self.set(value)

    def set(self, value):
        ''' Set the output of the digital channel

        Input params:
        value : set output to this [0, 1]
        '''
        if value in [0, 1]:
            self.value = value
            self._relay.write(self.value,auto_start=True,timeout=1)
        else:
            raise(ValueError)

    def toggle(self):
        ''' Toggle the relay between the two possible valies'''
        self.set(1-self.value)
Ejemplo n.º 2
0
    def __init__(self, channel, value=0):
        ''' Simple relay class

        Input params:
        channel : name of digital channel. E.g. "Dev2/port1/line0"
        value=0 : starting value of the output.
        '''
        self._relay = DigitalOutputTask()
        self._relay.create_channel(channel)
        self.set(value)
Ejemplo n.º 3
0
from nidaqmx import DigitalOutputTask
import numpy as np

task = DigitalOutputTask()
task.create_channel('Dev1/port0/line0')
task2 = DigitalOutputTask()
task2.create_channel('Dev1/port0/line1')
#task.configure_timing_sample_clock()
#data = np.ones(1000)
Ejemplo 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 ` 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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
from nidaqmx import DigitalOutputTask
import numpy as np 

task = DigitalOutputTask()
task.create_channel('Dev1/port0/line0')
task2 = DigitalOutputTask()
task2.create_channel('Dev1/port0/line1')
#task.configure_timing_sample_clock()
#data = np.ones(1000)