def _read_ctr_ticks(
task_handle, high_tick, low_tick, num_samps_per_chan, timeout,
interleaved=FillMode.GROUP_BY_CHANNEL):
samps_per_chan_read = ctypes.c_int()
cfunc = lib_importer.windll.DAQmxReadCtrTicks
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_double,
ctypes.c_int,
wrapped_ndpointer(dtype=numpy.uint32, flags=('C', 'W')),
wrapped_ndpointer(dtype=numpy.uint32, flags=('C', 'W')),
ctypes.c_uint, ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(c_bool32)]
error_code = cfunc(
task_handle, num_samps_per_chan, timeout, interleaved.value,
high_tick, low_tick, numpy.prod(high_tick.shape),
ctypes.byref(samps_per_chan_read), None)
check_for_error(error_code)
return samps_per_chan_read.value
python类c_uint()的实例源码
def _parse_typedefs(self):
"""
Determines the ctypes data types of the Task and Cal handles
based on the version of the NI-DAQmx driver installed.
"""
from nidaqmx.system.system import System
system = System.local()
# If DAQmx 8.8 and lower, TaskHandle is a typedef for uInt32 since
# DAQmx didn't support 64-bit applications then.
version = system.driver_version
if version.major_version <= 8 and version.minor_version <= 8:
self._task_handle = ctypes.c_uint
else:
self._task_handle = ctypes.c_void_p
self._cal_handle = ctypes.c_uint
def _major_version(self):
"""
int: Indicates the major portion of the installed version of NI-
DAQmx, such as 7 for version 7.0.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetSysNIDAQMajorVersion
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
ctypes.byref(val))
check_for_error(error_code)
return val.value
def _update_version(self):
"""
int: Indicates the update portion of the installed version of
NI-DAQmx, such as 1 for version 9.0.1.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetSysNIDAQUpdateVersion
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
ctypes.byref(val))
check_for_error(error_code)
return val.value
def di_port_width(self):
"""
int: Indicates in bits the width of digital input port.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetPhysicalChanDIPortWidth
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def do_port_width(self):
"""
int: Indicates in bits the width of digital output port.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetPhysicalChanDOPortWidth
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def teds_mfg_id(self):
"""
int: Indicates the manufacturer ID of the sensor.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetPhysicalChanTEDSMfgID
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def teds_model_num(self):
"""
int: Indicates the model number of the sensor.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetPhysicalChanTEDSModelNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def teds_serial_num(self):
"""
int: Indicates the serial number of the sensor.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetPhysicalChanTEDSSerialNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def teds_version_num(self):
"""
int: Indicates the version number of the sensor.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetPhysicalChanTEDSVersionNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def ai_lowpass_cutoff_freq_range_vals(self):
"""
List[float]: Indicates pairs of lowpass cutoff frequency ranges
supported by this device. Each pair consists of the low
value, followed by the high value. If the device supports a
set of discrete lowpass cutoff frequencies, use
**ai_lowpass_cutoff_freq_discrete_vals** to determine the
supported frequencies.
"""
cfunc = lib_importer.windll.DAQmxGetDevAILowpassCutoffFreqRangeVals
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def carrier_serial_num(self):
"""
int: Indicates the serial number of the device carrier. This
value is zero if the carrier does not have a serial number.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetCarrierSerialNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def ci_max_size(self):
"""
int: Indicates in bits the size of the counters on the device.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevCIMaxSize
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def co_max_size(self):
"""
int: Indicates in bits the size of the counters on the device.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevCOMaxSize
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def dev_serial_num(self):
"""
int: Indicates the serial number of the device. This value is
zero if the device does not have a serial number.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevSerialNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def num_dma_chans(self):
"""
int: Indicates the number of DMA channels on the device.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevNumDMAChans
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def pci_bus_num(self):
"""
int: Indicates the PCI bus number of the device.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevPCIBusNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def pci_dev_num(self):
"""
int: Indicates the PCI slot number of the device.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevPCIDevNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def product_num(self):
"""
int: Indicates the unique hardware identification number for the
device.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevProductNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def pxi_chassis_num(self):
"""
int: Indicates the PXI chassis number of the device, as
identified in MAX.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevPXIChassisNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def pxi_slot_num(self):
"""
int: Indicates the PXI slot number of the device.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetDevPXISlotNum
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._name, ctypes.byref(val))
check_for_error(error_code)
return val.value
def number_of_channels(self):
"""
int: Indicates the number of virtual channels in the task.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetTaskNumChans
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value
def number_of_devices(self):
"""
int: Indicates the number of devices in the task.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetTaskNumDevices
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value
def pretrig_samples(self):
"""
int: Specifies the minimum number of pretrigger samples to
acquire from each channel before recognizing the reference
trigger. Post-trigger samples per channel are equal to
**samp_quant_samp_per_chan** minus the number of pretrigger
samples per channel.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetRefTrigPreTrigSamples
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle,
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value
def rdy_for_xfer_event_deassert_cond_custom_threshold(self):
"""
int: Specifies in samples the threshold below which the Ready
for Transfer Event deasserts. This threshold is an amount of
space available in the onboard memory of the device.
**rdy_for_xfer_event_deassert_cond** must be
**DeassertCondition.ONBOARD_MEMORY_CUSTOM_THRESHOLD** to use
a custom threshold.
"""
val = ctypes.c_uint()
cfunc = (lib_importer.windll.
DAQmxGetExportedRdyForXferEventDeassertCondCustomThreshold)
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle,
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value
def do_num_booleans_per_chan(self):
"""
int: Indicates the number of Boolean values expected per channel
in a sample for line-based writes. This property is
determined by the channel in the task with the most digital
lines. If a channel has fewer lines than this number, NI-
DAQmx ignores the extra Boolean values.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetWriteDigitalLinesBytesPerChan
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle,
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value
def output_buf_size(self):
"""
int: Specifies the number of samples the output buffer can hold
for each channel in the task. Zero indicates to allocate no
buffer. Use a buffer size of 0 to perform a hardware-timed
operation without using a buffer. Setting this property
overrides the automatic output buffer allocation that NI-
DAQmx performs.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetBufOutputBufSize
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle,
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value
def output_onbrd_buf_size(self):
"""
int: Specifies in samples per channel the size of the onboard
output buffer of the device.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetBufOutputOnbrdBufSize
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle,
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value
def raw_data_width(self):
"""
int: Indicates in bytes the required size of a raw sample to
write to the task.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetWriteRawDataWidth
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle,
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value
def space_avail(self):
"""
int: Indicates in samples per channel the amount of available
space in the buffer.
"""
val = ctypes.c_uint()
cfunc = lib_importer.windll.DAQmxGetWriteSpaceAvail
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle,
ctypes.POINTER(ctypes.c_uint)]
error_code = cfunc(
self._handle, ctypes.byref(val))
check_for_error(error_code)
return val.value