Beispiel #1
0
def test_singlepoint(channel, samples):
	with daqmx.create_scoped_task("") as taskHandle:
		c_daqmx.DAQmxCreateAIVoltageChan(taskHandle, channel, "", c_daqmx.DAQmx_Val_Cfg_Default, -10.0, 10.0, c_daqmx.DAQmx_Val_Volts, None)

		with daqmx.start_task(taskHandle):
			value = ctypes.c_double()
			for i in xrange(samples):
				c_daqmx.DAQmxReadAnalogScalarF64(taskHandle, 10.0, ctypes.byref(value), None)
Beispiel #2
0
	def run(self):
		with daqmx.create_scoped_task("") as taskHandle:
			c_daqmx.DAQmxCreateAIVoltageChan(taskHandle, self.__channel, "", c_daqmx.DAQmx_Val_Cfg_Default, -10.0, 10.0, c_daqmx.DAQmx_Val_Volts, None)

			c_daqmx.DAQmxCfgSampClkTiming(taskHandle, "", 10000.0, c_daqmx.DAQmx_Val_Rising, c_daqmx.DAQmx_Val_ContSamps, self.__samplesPerChanPerIter)
			c_daqmx.DAQmxRegisterEveryNSamplesEvent(taskHandle, c_daqmx.DAQmx_Val_Acquired_Into_Buffer, self.__samplesPerChanPerIter, 0, self.__every_n_callback, None)
			c_daqmx.DAQmxRegisterDoneEvent(taskHandle, 0, self.__done_callback, None)

			with daqmx.start_task(taskHandle):
				while self.__totalSamples < self.__samplesPerChanPerIter * self.__iterations:
					time.sleep(1)
		daqmxutils.validate_status(self.__status)
Beispiel #3
0
def test_hardware_singlepoint(channel, samples):
	with daqmx.create_scoped_task("") as taskHandle:
		c_daqmx.DAQmxCreateAIVoltageChan(taskHandle, channel, "", c_daqmx.DAQmx_Val_Cfg_Default, -10.0, 10.0, c_daqmx.DAQmx_Val_Volts, None)

		c_daqmx.DAQmxCfgSampClkTiming(taskHandle, "", 1000.0, c_daqmx.DAQmx_Val_Rising, c_daqmx.DAQmx_Val_HWTimedSinglePoint, samples)

		with daqmx.start_task(taskHandle):
			value = ctypes.c_double()
			isLate = ctypes.c_uint32()
			for i in xrange(samples):
				c_daqmx.DAQmxReadAnalogScalarF64(taskHandle, 10.0, ctypes.byref(value), None)
				c_daqmx.DAQmxWaitForNextSampleClock(taskHandle, 10, ctypes.byref(isLate))
				assert isLate.value == 0, "%d" % isLate.value
Beispiel #4
0
def test_finite(channel, samplesPerChannel, iterations):
	with daqmx.create_scoped_task("") as taskHandle:
		c_daqmx.DAQmxCreateAIVoltageChan(taskHandle, channel, "", c_daqmx.DAQmx_Val_Cfg_Default, -10.0, 10.0, c_daqmx.DAQmx_Val_Volts, None)

		c_daqmx.DAQmxCfgSampClkTiming(taskHandle, "", 10000.0, c_daqmx.DAQmx_Val_Rising, c_daqmx.DAQmx_Val_FiniteSamps, samplesPerChannel)

		with daqmx.start_task(taskHandle):
			totalSamples = 0
			for i in xrange(iterations):
				DATA_BUFFER_SIZE = samplesPerChannel / iterations
				DataBuffer = ctypes.c_double * DATA_BUFFER_SIZE
				data = DataBuffer()
				samplesRead = ctypes.c_int()
				c_daqmx.DAQmxReadAnalogF64(taskHandle, DATA_BUFFER_SIZE, 10.0, c_daqmx.DAQmx_Val_GroupByChannel, data, DATA_BUFFER_SIZE, ctypes.byref(samplesRead), None)
				assert samplesRead.value == DATA_BUFFER_SIZE, "%s != %s" % (samplesRead.value, DATA_BUFFER_SIZE)
				totalSamples += samplesRead.value
			assert totalSamples == samplesPerChannel, "%s != %s" % (totalSamples, samplesPerChannel)
Beispiel #5
0
def contacq_intclk_example():
    """
	ANSI C Example program:
		ContAcq-IntClk.c

	Example Category:
		AI

	Description:
		This example demonstrates how to acquire a continuous amount of
		data using the DAQ device's internal clock.

	Instructions for Running:
		1. Select the physical channel to correspond to where your
			signal is input on the DAQ device.
		2. Enter the minimum and maximum voltage range.
		Note: For better accuracy try to match the input range to the
			 expected voltage level of the measured signal.
		3. Set the rate of the acquisition. Also set the Samples per
			Channel control. This will determine how many samples are
			read at a time. This also determines how many points are
			plotted on the graph each time.
		Note: The rate should be at least twice as fast as the maximum
			 frequency component of the signal being acquired.

	Steps:
		1. Create a task.
		2. Create an analog input voltage channel.
		3. Set the rate for the sample clock. Additionally, define the
			sample mode to be continuous.
		4. Call the Start function to start the acquistion.
		5. Read the data in the EveryNCallback function until the stop
			button is pressed or an error occurs.
		6. Call the Clear Task function to clear the task.
		7. Display an error if any.

	I/O Connections Overview:
		Make sure your signal input terminal matches the Physical
		Channel I/O control. For further connection information, refer
		to your hardware reference manual.
	"""
    # Configure Code
    with daqmx.create_scoped_task("") as taskHandle:
        c_daqmx.DAQmxCreateAIVoltageChan(
            taskHandle, "Dev1/ai0", "", c_daqmx.DAQmx_Val_Cfg_Default, -10.0, 10.0, c_daqmx.DAQmx_Val_Volts, None
        )

        c_daqmx.DAQmxCfgSampClkTiming(
            taskHandle, "", 10000.0, c_daqmx.DAQmx_Val_Rising, c_daqmx.DAQmx_Val_ContSamps, 1000
        )
        every_n_callback = create_every_n_callback()  # We need to own the reference to it
        c_daqmx.DAQmxRegisterEveryNSamplesEvent(
            taskHandle, c_daqmx.DAQmx_Val_Acquired_Into_Buffer, 1000, 0, every_n_callback, None
        )
        c_daqmx.DAQmxRegisterDoneEvent(taskHandle, 0, done_callback, None)

        with daqmx.start_task(taskHandle):
            print "Acquiring samples continuously.  Press Enter to interrupt"
            raw_input()

    print "End of program, press Enter key to quit"
    raw_input()
Beispiel #6
0
def acq_intclk_example():
    """
	ANSI C Example program:
		Acq-IntClk.c

	Example Category:
		AI

	Description:
		This example demonstrates how to acquire a finite amount of data
		using the DAQ device's internal clock.

	Instructions for Running:
		1. Select the physical channel to correspond to where your
			signal is input on the DAQ device.
		2. Enter the minimum and maximum voltages.
		Note: For better accuracy try to match the input range to the
			 expected voltage level of the measured signal.
		3. Select the number of samples to acquire.
		4. Set the rate of the acquisition.
		Note: The rate should be AT LEAST twice as fast as the maximum
			 frequency component of the signal being acquired.

	Steps:
		1. Create a task.
		2. Create an analog input voltage channel.
		3. Set the rate for the sample clock. Additionally, define the
			sample mode to be finite and set the number of samples to be
			acquired per channel.
		4. Call the Start function to start the acquisition.
		5. Read all of the waveform data.
		6. Call the Clear Task function to clear the task.
		7. Display an error if any.

	I/O Connections Overview:
		Make sure your signal input terminal matches the Physical
		Channel I/O Control. For further connection information, refer
		to your hardware reference manual.
	"""
    # Configure Code
    with daqmx.create_scoped_task("") as taskHandle:
        c_daqmx.DAQmxCreateAIVoltageChan(
            taskHandle, "Dev1/ai0", "", c_daqmx.DAQmx_Val_Cfg_Default, -10.0, 10.0, c_daqmx.DAQmx_Val_Volts, None
        )

        c_daqmx.DAQmxCfgSampClkTiming(
            taskHandle, "", 10000.0, c_daqmx.DAQmx_Val_Rising, c_daqmx.DAQmx_Val_FiniteSamps, 1000
        )

        with daqmx.start_task(taskHandle):
            # Read Code
            DATA_BUFFER_SIZE = 1000
            DataBuffer = ctypes.c_double * DATA_BUFFER_SIZE
            data = DataBuffer()
            samplesRead = ctypes.c_int()
            c_daqmx.DAQmxReadAnalogF64(
                taskHandle,
                DATA_BUFFER_SIZE,
                10.0,
                c_daqmx.DAQmx_Val_GroupByChannel,
                data,
                DATA_BUFFER_SIZE,
                ctypes.byref(samplesRead),
                None,
            )
            print "Acquired %d points" % samplesRead.value

    print "End of program, press Enter key to quit"
    raw_input()