def CCDTrig_open(freq, data):
    taskHandle = tp.TaskHandle()
    taskCounter = tp.TaskHandle()
    nsamples = len(data)
    idata = data.astype(tp.uInt32)
    startdata = N.array((5,5),dtype=tp.uInt32)
    try:
        daq.DAQmxCreateTask("",taskCounter)
        daq.DAQmxCreateCOPulseChanFreq(taskCounter,"Dev1/ctr0","",daq.DAQmx_Val_Hz,daq.DAQmx_Val_Low,0.0,freq,0.50)
        daq.DAQmxCfgImplicitTiming(taskCounter,daq.DAQmx_Val_ContSamps,1000)
#        print "taskCounter Value", taskCounter.value
    ##  Create Digital Channel
        daq.DAQmxCreateTask("",taskHandle)
#        print "taskHandle Value", taskHandle.value
        daq.DAQmxCreateDOChan(taskHandle,"Dev1/port0/line0:7","",daq.DAQmx_Val_ChanForAllLines)
        daq.DAQmxCfgSampClkTiming(taskHandle,"Ctr0InternalOutput",freq,daq.DAQmx_Val_Rising,daq.DAQmx_Val_FiniteSamps,nsamples)
    ##  Register done events (error checking)
#        q = daq.DAQmxRegisterDoneEvent(taskHandle,0,None,None)
#        print q,'c'
#        q = daq.DAQmxRegisterDoneEvent(taskCounter,0,None,None)
#        print q,'d'
    ##  write startup values
        daq.DAQmxWriteDigitalU32(taskHandle,2,0,10.0,cnst.DAQmx_Val_GroupByChannel,startdata,None,None)
        daq.DAQmxStartTask(taskHandle)
        daq.DAQmxStopTask(taskHandle)
    ##  load trigger sequence
        daq.DAQmxWriteDigitalU32(taskHandle,nsamples,0,10.0,cnst.DAQmx_Val_GroupByChannel,idata,None,None)
        print("Data Written\n")
    ##  start counter
        daq.DAQmxStartTask(taskCounter)
        return taskHandle,taskCounter
    except:
        errBuff=tp.create_string_buffer(b"",2048)
        daq.DAQmxGetExtendedErrorInfo(errBuff,2048)
        print(errBuff.value)
def DAQreset():
    try:
        q = daq.DAQmxResetDevice("Dev1")
        return q
    except:
        errBuff=tp.create_string_buffer(b"",2048)
        daq.DAQmxGetExtendedErrorInfo(errBuff,2048)
        print(errBuff.value)
def setVoltage_2(val):
    try:
        taskHandle = tp.TaskHandle()
        daq.DAQmxCreateTask("",taskHandle)
#        print "taskHandle Value", taskHandle.value
        daq.DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao1","",0.0,10.0,cnst.DAQmx_Val_Volts,"")
        daq.DAQmxStartTask(taskHandle)
        daq.DAQmxWriteAnalogScalarF64(taskHandle,1,5.0,tp.float64(val),None)
        if not taskHandle == 0 :
#            print "Stopping Tasks\n"
            daq.DAQmxStopTask(taskHandle)
            daq.DAQmxClearTask(taskHandle)
        return 0
    except:
        errBuff=tp.create_string_buffer(b"",2048)
        daq.DAQmxGetExtendedErrorInfo(errBuff,2048)
        print(errBuff.value)
Exemple #4
0
 def data(self):
     self._setup_task()
     self.task.StartTask()
     self.task.ReadAnalogF64(self.reads_per_run, self.timeout,
                             daqc.DAQmx_Val_GroupByChannel,
                             self.raw_data, self.reads_per_run,
                             daqt.byref(self.have_read), None)
     return self.raw_data
def getVoltage():
    try:
        taskHandle = tp.TaskHandle()
        daq.DAQmxCreateTask("",taskHandle)
#        print "taskHandle Value", taskHandle.value
        val = tp.float64()
        daq.DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",cnst.DAQmx_Val_RSE,0.0,10.0,cnst.DAQmx_Val_Volts,"")
        daq.DAQmxStartTask(taskHandle)
        daq.DAQmxReadAnalogScalarF64(taskHandle,5.0,daq.byref(val),None)
        if not taskHandle == 0 :
#            print "Stopping Tasks\n"
            daq.DAQmxStopTask(taskHandle)
            daq.DAQmxClearTask(taskHandle)
        return val.value
    except:
        errBuff=tp.create_string_buffer(b"",2048)
        daq.DAQmxGetExtendedErrorInfo(errBuff,2048)
        print(errBuff.value)
def CCDTrig_run(taskHandle,taskCounter):
    try:
        daq.DAQmxStartTask(taskHandle)
        #print("Tasks Started\n")
        daq.DAQmxWaitUntilTaskDone(taskHandle,10)
        daq.DAQmxStopTask(taskHandle)
        return 0
    except:
        errBuff=tp.create_string_buffer(b"",2048)
        daq.DAQmxGetExtendedErrorInfo(errBuff,2048)
        print(errBuff.value)
def CCDTrig_close(taskHandle,taskCounter):
    try:
        if (taskHandle != 0 ):
            #print("Stopping Tasks\n")
            daq.DAQmxStopTask(taskHandle)
            daq.DAQmxClearTask(taskHandle)
            daq.DAQmxStopTask(taskCounter)
            daq.DAQmxClearTask(taskCounter)
            return 0
    except:
        errBuff=tp.create_string_buffer(b"",2048)
        daq.DAQmxGetExtendedErrorInfo(errBuff,2048)
        print(errBuff.value)
def supports_period_measurement(device_name):
    import warnings

    with warnings.catch_warnings():
        # PyDAQmx warns about a positive return value, but actually this is how you are
        # supposed to figure out the size of the array required.
        warnings.simplefilter("ignore")
        # Pass in null pointer and 0 len to ask for what array size is needed:
        npts = daqmx.DAQmxGetDevCISupportedMeasTypes(device_name,
                                                     types.int32(), 0)
    # Create that array
    result = (types.int32 * npts)()
    daqmx.DAQmxGetDevCISupportedMeasTypes(device_name, result, npts)
    return c.DAQmx_Val_Period in [result[i] for i in range(npts)]
Exemple #9
0
 def __init__(self):
     # How many samples for each Task()?
     self.reads_per_run = 1000
     # samples/second
     self.sample_rate = 1000
     # (min, max) I *think* the NI 6009 only handles 0 to 5.
     self.voltages = (0.0, 5.0)
     # Holds the sample data
     self.raw_data = np.zeros(self.reads_per_run, dtype = np.float64)
     # Main task instance. Currently we're creating a new one for each
     # read, check if can reuse.
     self.task = None
     self.dev = 'Dev1/ai0'
     self.timeout = 10.0
     self.have_read = daqt.int32()
def incomplete_sample_detection(device_name):
    """Introspect whether a device has 'incomplete sample detection', described here:

        www.ni.com/documentation/en/ni-daqmx/latest/devconsid/incompletesampledetection/

    The result is determined empirically by outputting a pulse on one counter and
    measuring it on another, and seeing whether the first sample was discarded or not.
    This requires a non-simulated device with at least two counters. No external signal
    is actually generated by the device whilst this test is performed. Credit for this
    method goes to Kevin Price, who provided it here:

        forums.ni.com/t5/Multifunction-DAQ/_/td-p/3849429

    This workaround will hopefully be deprecated if and when NI provides functionality
    to either inspect this feature's presence directly, or to disable it regardless of
    its presence.
    """

    if is_simulated(device_name):
        msg = "Can only detect incomplete sample detection on non-simulated devices"
        raise ValueError(msg)

    if not supports_period_measurement(device_name):
        msg = "Device doesn't support period measurement"
        raise ValueError(msg)

    CI_chans = get_CI_chans(device_name)

    if len(CI_chans) < 2:
        msg = "Need at least two counters to detect incomplete sample detection"
        raise ValueError(msg)

    # The counter we will produce a test signal on:
    out_chan = CI_chans[0]
    # The counter we will measure it on:
    meas_chan = CI_chans[1]

    # Set up the output task:
    out_task = daqmx.Task()
    out_task.CreateCOPulseChanTime(out_chan, "", c.DAQmx_Val_Seconds,
                                   c.DAQmx_Val_Low, 0, 1e-3, 1e-3)
    # Prevent the signal being output on the physical terminal:
    out_task.SetCOPulseTerm("", "")
    # Force CO into idle state to prevent spurious edges when the task is started:
    out_task.TaskControl(c.DAQmx_Val_Task_Commit)

    # Set up the measurement task
    meas_task = daqmx.Task()
    meas_task.CreateCIPeriodChan(
        meas_chan,
        "",
        1e-3,
        1.0,
        c.DAQmx_Val_Seconds,
        c.DAQmx_Val_Rising,
        c.DAQmx_Val_LowFreq1Ctr,
        10.0,
        0,
        "",
    )
    meas_task.CfgImplicitTiming(c.DAQmx_Val_ContSamps, 1)
    # Specify that we are measuring the internal output of the other counter:
    meas_task.SetCIPeriodTerm("", '/' + out_chan + 'InternalOutput')

    try:
        meas_task.StartTask()
        out_task.StartTask()
        out_task.WaitUntilTaskDone(10.0)
        # How many samples are in the read buffer of the measurement task?
        samps_avail = types.uInt32()
        meas_task.GetReadAvailSampPerChan(samps_avail)
        if samps_avail.value == 0:
            # The device discarded the first edge
            return True
        elif samps_avail.value == 1:
            # The device did not discard the first edge
            return False
        else:
            # Unexpected result
            msg = "Unexpected number of samples: %d" % samps_avail.value
            raise ValueError(msg)
    finally:
        out_task.ClearTask()
        meas_task.ClearTask()
def is_simulated(device_name):
    result = types.bool32()
    daqmx.DAQmxGetDevIsSimulated(device_name, result)
    return result.value
def get_CI_chans(device_name):
    BUFSIZE = 4096
    result = ctypes.create_string_buffer(BUFSIZE)
    daqmx.DAQmxGetDevCIPhysicalChans(device_name, result,
                                     types.uInt32(BUFSIZE))
    return result.value.decode('utf8').split(', ')
def get_product_type(device_name):
    BUFSIZE = 4096
    result = ctypes.create_string_buffer(BUFSIZE)
    daqmx.DAQmxGetDevProductType(device_name, result, types.uInt32(BUFSIZE))
    return result.value.decode('utf8')
def get_devices():
    BUFSIZE = 4096
    result = ctypes.create_string_buffer(BUFSIZE)
    daqmx.DAQmxGetSysDevNames(result, types.uInt32(BUFSIZE))
    return result.value.decode('utf8').split(',')