Exemple #1
0
    def run(self):
        taskHandle = PyDAQ.TaskHandle()
        frameCount = PyDAQ.uInt32()
        try:
            # DAQmx Configure Code
            PyDAQ.DAQmxCreateTask("", PyDAQ.byref(taskHandle))
            PyDAQ.DAQmxCreateCICountEdgesChan(taskHandle, "Dev1/ctr0", "",
                                              PyDAQ.DAQmx_Val_Rising, 0,
                                              PyDAQ.DAQmx_Val_CountUp)

            # DAQmx Start Code
            PyDAQ.DAQmxStartTask(taskHandle)
            while self.shared.main_programm_still_running.value:
                PyDAQ.DAQmxReadCounterScalarU32(taskHandle, 10.0,
                                                PyDAQ.byref(frameCount), None)
                # print(frameCount.value)
                self.shared.frameCount.value = frameCount.value
                time.sleep(
                    0.00005
                )  # this prevents this loop from over exerting the processor

        except PyDAQ.DAQError as err:
            print("DAQmx Error: %s" % err)
        finally:
            if taskHandle:
                PyDAQ.DAQmxStopTask(taskHandle)
                PyDAQ.DAQmxClearTask(taskHandle)
                print('DAQ Task Deleted')
Exemple #2
0
def configure_daq():
    """ Configures NIDAQ communication """
    counterChannel = "Dev2/ctr1"
    pulseChannel = "Dev2/ctr0"

    counterTaskHandle = daq.TaskHandle(0)
    pulseTaskHandle = daq.TaskHandle(0)

    daq.DAQmxCreateTask("2", daq.byref(counterTaskHandle))
    daq.DAQmxCreateCICountEdgesChan(\
        counterTaskHandle,counterChannel,"",
        daq.DAQmx_Val_Rising,0,daq.DAQmx_Val_CountUp)
    daq.DAQmxCreateTask("1",\
        daq.byref(pulseTaskHandle))
    daq.DAQmxCreateCOPulseChanTime(\
        pulseTaskHandle,pulseChannel,"",
        daq.DAQmx_Val_Seconds,daq.DAQmx_Val_Low,0,0.05,0.05)

    daq.DAQmxStartTask(counterTaskHandle)
    daq.DAQmxStartTask(pulseTaskHandle)

    # Reads incoming signal from microscope computer and stores it to 'data'. A rising edge is send every new frame
    # the microscope starts to record, thus the 'data' variable is incremented
    daq_data = daq.uInt32(0)
    daq.DAQmxReadCounterScalarU32(counterTaskHandle, 1.0, daq.byref(daq_data),
                                  None)
    return pulseTaskHandle, counterTaskHandle, daq_data
Exemple #3
0
def setup_event_timer(trigger, counter, clock, callback=None, edge='rising'):
    '''
    Create timer to store timestamp of rising edge of trigger. Useful for
    tracking when changes to digital state occur in high precision.

    Parameters
    ----------
    trigger : str
        Line to monitor for digital edge (e.g., '/Dev1/PFI1')
    counter : str
        Which counter channel to use (e.g., '/Dev1/Ctr0')
    clock : str
        Timebase for counter.  The value read from the counter will be in units
        of the specified clock (e.g., 'ao/SampleClock').
    edge : {'rising', 'falling'}
        Should an event time be acquired on the rising or falling edge of the
        sample clock?

    Returns
    -------
    task : niDAQmx task
        Task configured to acquire event time.
    '''
    task = create_task()
    if edge == 'rising':
        edge_value = mx.DAQmx_Val_Rising
    elif edge == 'falling':
        edge_value = mx.DAQmx_Val_Falling
    else:
        raise ValueError('Unsupported mode, {}, for edge'.format(edge))

    # Set up a counter to count the number of rising edges from an input
    # terminal. The input terminal will be set to the value specified by
    # `clock`. Example terminals include the `ao/SampClock` (in which case the
    # counter will tell us how many samples have been generated by the analog
    # output) or the `10MHzRefClock` (in which case the counter will tell us the
    # the time elapsed since the task began with an accuracy of 1/10e6 seconds).
    # Every time a trigger is detected, the value of the counter will be saved
    # to a buffer and can be read into Python.
    mx.DAQmxCreateCICountEdgesChan(task, counter, '', mx.DAQmx_Val_Rising, 0,
                                   mx.DAQmx_Val_CountUp)
    mx.DAQmxSetCICountEdgesTerm(task, counter, clock)
    mx.DAQmxCfgSampClkTiming(task, trigger, 200e3, edge_value,
                             mx.DAQmx_Val_ContSamps, 500)

    if callback is not None:
        cb = CallbackHelper(callback)

        # Create the callback. Be sure to store a reference to the callback
        # pointer on the task object otherwise the pointer will be
        # garbage-collected after this function exits. If the pointer is
        # garbage-collected, then the callback no longer exists and the program
        # will segfault when niDAQmx tries to call it.
        cb_ptr = mx.DAQmxSignalEventCallbackPtr(cb)
        mx.DAQmxRegisterSignalEvent(task, mx.DAQmx_Val_SampleCompleteEvent, 0,
                                    cb_ptr, None)
        task.__se_cb_ptr = cb_ptr

    mx.DAQmxTaskControl(task, mx.DAQmx_Val_Task_Commit)
    return task
Exemple #4
0
def configure_daq():
    """ Configures NIDAQ communication """
    counterChannel = "Dev2/ctr1"
    pulseChannel = "Dev2/ctr0"

    counterTaskHandle = daq.TaskHandle(0)
    pulseTaskHandle = daq.TaskHandle(0)

    daq.DAQmxCreateTask("2",
        daq.byref(counterTaskHandle))
    daq.DAQmxCreateCICountEdgesChan(\
        counterTaskHandle,counterChannel,"",
        daq.DAQmx_Val_Rising,0,daq.DAQmx_Val_CountUp)
    daq.DAQmxCreateTask("1",\
        daq.byref(pulseTaskHandle))
    daq.DAQmxCreateCOPulseChanTime(\
        pulseTaskHandle,pulseChannel,"",
        daq.DAQmx_Val_Seconds,daq.DAQmx_Val_Low,0,0.05,0.05)

    
    
    return pulseTaskHandle, counterTaskHandle
Exemple #5
0
import PyDAQmx as daq
import numpy as np

task_handle = daq.TaskHandle()
samps = 3000
test_array = np.full((samps, ), -1, dtype=np.uint32)

daq.DAQmxCreateTask('count_test', daq.byref(task_handle))

daq.DAQmxCreateCICountEdgesChan(task_handle, '/Dev1/Ctr0', 'Counter test',
                                daq.DAQmx_Val_Rising, 0, daq.DAQmx_Val_CountUp)

daq.DAQmxCfgSampClkTiming(task_handle, '100kHzTimebase', 100000,
                          daq.DAQmx_Val_Rising, daq.DAQmx_Val_FiniteSamps,
                          samps)

daq.DAQmxSetCICountEdgesTerm(task_handle, '/Dev1/Ctr0', '/Dev1/PFI0')

done = daq.bool32()
daq.DAQmxStartTask(task_handle)
daq.DAQmxGetTaskComplete(task_handle, done)

n_read_samples = daq.int32()
daq.DAQmxReadCounterU32(task_handle, samps, 500., test_array, len(test_array),
                        daq.byref(n_read_samples), None)

done = daq.bool32()
daq.DAQmxGetTaskComplete(task_handle, done)

daq.DAQmxStopTask(task_handle)