コード例 #1
0
ファイル: gaussswitch.py プロジェクト: imrehg/labhardware
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)
コード例 #2
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
コード例 #3
0
ファイル: do.py プロジェクト: olsonse/pylibnidaqmx
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
コード例 #4
0
ファイル: digital_test.py プロジェクト: bailianfa/oct
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)
コード例 #5
0
ファイル: digital_test.py プロジェクト: bernardokyotoku/oct
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)