本文整理汇总了Python中PyDAQmx.int32方法的典型用法代码示例。如果您正苦于以下问题:Python PyDAQmx.int32方法的具体用法?Python PyDAQmx.int32怎么用?Python PyDAQmx.int32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyDAQmx
的用法示例。
在下文中一共展示了PyDAQmx.int32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: digital_task
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def digital_task(semaphore, semaphore_dev, counter, samples_queue, settings):
"""
Digital
Need to start the dio task first!
"""
try:
print("\nCreating digital task %s." % settings['name'])
sys.stdout.flush()
# settings
samples_per_channel = settings['samples_per_channel']
number_of_channels = settings['number_of_channels_di']
total_samps = pydaq.int32()
total_bytes = pydaq.int32()
data_size = samples_per_channel * number_of_channels
task = pydaq.Task()
task.CreateDIChan(
settings['digital_input'].encode('utf-8'),
b'', pydaq.DAQmx_Val_ChanPerLine
)
task.CfgSampClkTiming(
**settings['parameters_sample_clock_time_di']
)
print("\nStarting digital task %s." % settings['name'])
sys.stdout.flush()
task.StartTask()
total_samps.value = 0
total_bytes.value = 0
run = True
while run:
run = yield
data = np.zeros((data_size,), dtype=np.uint8 )
task.ReadDigitalLines(
samples_per_channel, # numSampsPerChan
10.0, # timeout
pydaq.DAQmx_Val_GroupByChannel, # fillMode
data, # readArray
data_size, # arraySizeInBytes
pydaq.byref(total_samps), # sampsPerChanRead
pydaq.byref(total_bytes), # numBytesPerChan
None # reserved
)
yield data
except:
pass
task.StopTask()
task.ClearTask()
示例2: __init__
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def __init__(self, device='Dev1', ports=['ao0'], read_buffer_size=10, timeout=5., sample_rate=400., AI_mode=pydaq.DAQmx_Val_Diff, save_buffer_size=8000, analog_minmax=(-10,10)):
# DAQ properties
pydaq.Task.__init__(self)
self.device = device
self.port_names = ports
self.ports = ['/'.join([self.device,port]) for port in self.port_names]
self.timeout = timeout
self.minn,self.maxx = analog_minmax
self.sample_rate = sample_rate
self.AI_mode = AI_mode
# params & data
self.read_success = pydaq.int32()
self.read_buffer_size = read_buffer_size
self.effective_buffer_size = self.read_buffer_size * len(self.ports)
self.read_data = np.zeros(self.effective_buffer_size) # memory for DAQmx to write into on read callbacks
self.last_ts = None
self.data_q = mp.Queue()
# Setup task
try:
self.CreateAIVoltageChan(','.join(self.ports), '', self.AI_mode, self.minn, self.maxx, pydaq.DAQmx_Val_Volts, None)
self.CfgSampClkTiming('', self.sample_rate, pydaq.DAQmx_Val_Rising, pydaq.DAQmx_Val_ContSamps, self.read_buffer_size)
self.AutoRegisterEveryNSamplesEvent(pydaq.DAQmx_Val_Acquired_Into_Buffer, self.read_buffer_size, 0)
self.AutoRegisterDoneEvent(0)
self.StartTask()
except:
warnings.warn("DAQ task did not successfully initialize")
raise
示例3: read
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def read(self, name=None, timeout=0.01, num_samples=None):
"""
Reads data from a given physical channel
:param name: The name of the channel from which we are going to read the data
:param timeout: The amount of time, in seconds, to wait for the function to read the sample(s)
(-1 for infinite)
:param num_samples: The number of samples to acquire
:return: Returns an array with the data read
"""
if name is None:
name = self.physical_channels[0]
if num_samples is None:
index = self.physical_channels.index(name)
num_samps_channel = self.n_samples[index]
else:
num_samps_channel = num_samples
# Get task handle
task = self.tasks[name]
# Prepare the data to be read
data = numpy.zeros((num_samps_channel,), dtype=numpy.float64)
read = PyDAQmx.int32()
# Start the task
task.StartTask()
# Read the data and return it!
task.ReadAnalogF64(
num_samps_channel, timeout, GROUP_BY_CHANNEL, data, num_samps_channel, PyDAQmx.byref(read), None
)
# Stop the task
task.StopTask()
# Return in a list instead of numpy.array
return data.tolist()
示例4: read_and_clean
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def read_and_clean(self):
"""
This should be called after start().
Collects data from the running task, cleans up, then returns the data.
"""
# Fetch the data
debug("fetch data")
array_size = self["ai_samples"]*len(self["ai_channels"])
# create the array in which to store the data
data = _n.zeros(array_size, dtype=_n.float64)
bytes_read = _mx.int32()
# read the data
debug("_handle", self._handle)
_mx.DAQmxReadAnalogF64(
self._handle, # handle to the task
self["ai_samples"], # number of samples per channel (-1 => Read ALL in Buffer)
self["ai_timeout"], # timeout (sec)
_mx.DAQmx_Val_GroupByChannel, # how to fill the data array
data, # array to fill
array_size, # array size (samples)
_mx.byref(bytes_read), # samples per channel actually read
None) # "reserved"
# clean up the task
self.clean()
#Organize the data
data = _n.split(data, len(self["ai_channels"]))
return data
示例5: get_internal_chan_old
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def get_internal_chan_old(self, chan):
"""
Modifies example of PyDAQmx from https://pythonhosted.org/PyDAQmx/usage.html#task-object . There was a simpler version that I didn't notice before, now that one is implemented above.
"""
print('start get chan %s' %chan)
# Declaration of variable passed by reference
taskHandle = mx.TaskHandle()
read = mx.int32()
data = numpy.zeros((1,), dtype=numpy.float64)
try:
# DAQmx Configure Code
mx.DAQmxCreateTask("",mx.byref(taskHandle))
mx.DAQmxCreateAIVoltageChan(taskHandle,"Dev1/_%s_vs_aognd" %chan,"",mx.DAQmx_Val_Cfg_Default,-10.0,10.0,mx.DAQmx_Val_Volts,None)
mx.DAQmxCfgSampClkTiming(taskHandle,"",10000.0,mx.DAQmx_Val_Rising,mx.DAQmx_Val_FiniteSamps,2)
# DAQmx Start Code
mx.DAQmxStartTask(taskHandle)
# DAQmx Read Code
mx.DAQmxReadAnalogF64(taskHandle,1000,10.0,mx.DAQmx_Val_GroupByChannel,data,1000,mx.byref(read),None)
except mx.DAQError as err:
print ("DAQmx Error: %s"%err)
finally:
if taskHandle:
# DAQmx Stop Code
mx.DAQmxStopTask(taskHandle)
mx.DAQmxClearTask(taskHandle)
print('end get chan %s' %chan)
return float(data[0])
示例6: writeValues
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def writeValues(self, chanNames, data):
DebugLog.log("DAQhardware.writeValue(): chanNames= %s val= %s" % (repr(chanNames), repr(data)))
self.analog_output = None # ensure the output task is closed
samplesWritten = daqmx.int32()
analog_output = daqmx.Task()
data = np.vstack((data, data))
data = data.transpose()
data = np.require(data, np.double, ['C', 'W'])
numSamples = 2
outputRate = 1000
for chanName in chanNames:
analog_output.CreateAOVoltageChan(chanName,"",-10.0,10.0, daqmx.DAQmx_Val_Volts, None)
analog_output.CfgSampClkTiming("",outputRate, daqmx.DAQmx_Val_Rising, daqmx.DAQmx_Val_FiniteSamps, numSamples)
analog_output.WriteAnalogF64(numSampsPerChan=numSamples, autoStart=True,timeout=1.0, dataLayout=daqmx.DAQmx_Val_GroupByChannel, writeArray=data, reserved=None, sampsPerChanWritten=byref(samplesWritten))
DebugLog.log("DAQhardware.setupAnalogOutput(): Wrote %d samples" % samplesWritten.value)
# wait until write is completeled
isDone = False
isDoneP = daqmx.c_ulong()
while not isDone:
err = analog_output.IsTaskDone(byref(isDoneP))
isDone = isDoneP.value != 0
analog_output = None
示例7: analog_task
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def analog_task(settings):
"""
"""
try:
samples_per_channel = settings['samples_per_channel']
number_of_channels = settings['number_of_channels_ai']
# Analog dev
print("\nCreating analog task %s." % settings['name'])
sys.stdout.flush()
# settings
task = pydaq.Task()
task.CreateAIVoltageChan(
settings['analog_input'].encode('utf-8'),
**settings['parameters_create_ai']
)
task.CfgSampClkTiming(
**settings['parameters_sample_clock_time_ai'])
if 'parameters_export_signal' in settings:
for sig in settings['parameters_export_signal']:
task.ExportSignal(**sig)
if 'parameters_start_trigger' in settings:
task.CfgDigEdgeStartTrig(**settings['parameters_start_trigger'])
total_samples = pydaq.int32()
data_size = samples_per_channel * number_of_channels
print("\nStarting analog task %s." % settings['name'])
task.StartTask()
total_samples.value = 0
run = True
while run:
run = yield
data = np.zeros((data_size,), dtype=np.float64)
task.ReadAnalogF64(
samples_per_channel,
10.0,
pydaq.DAQmx_Val_GroupByChannel,
data,
data_size,
pydaq.byref(total_samples),
None
)
yield data
except:
pass
task.StopTask()
task.ClearTask()
示例8: get_voltage_ai
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def get_voltage_ai(self, **kwargs):
"""
get_voltage_ai(self, **kwargs)
Usage example:
get_voltage_ai(self, channel='Dev1/ai6', voltage_limit=10, clock_freq=1e4, sampling_pts=1000, input_mode='diff')
"""
# Set the default values below
channel = 'Dev1/ai6'
voltage_limit = 10
clock_freq = 1e4
sampling_pts = 1000
input_mode = daq.DAQmx_Val_Diff
# Read input args
for key, value in kwargs.items():
if key == 'channel':
channel = value
elif key == 'voltage_limit':
voltage_limit = value
elif key == 'clock_freq':
clock_freq = value
elif key == 'sampling_pts':
sampling_pts = value
elif key == 'input_mode':
if value.lower() == 'diff':
input_mode = daq.DAQmx_Val_Diff
elif value.lower() == 'nrse':
input_mode = daq.DAQmx_Val_NRSE
elif value.lower() == 'rse':
input_mode = daq.DAQmx_Val_RSE
else:
raise ValueError('Unrecognized input mode!')
# The code below is adopted from http://pythonhosted.org/PyDAQmx/usage.html
sampling_pts = int(sampling_pts) # force int type for sampling_pts, otherwise will be type error
analog_input = daq.Task()
read = daq.int32()
data = numpy.zeros((sampling_pts,), dtype=numpy.float64)
recording_time = float(sampling_pts) / clock_freq
if recording_time <= 5:
fill_mode = 5
else:
fill_mode = recording_time * 1.01
# The fill_mode here determines the max recording time USB6211 can go
# DAQmx Configure Code
#analog_input.CreateAIVoltageChan("Dev1/ai6","",DAQmx_Val_Cfg_Default,-voltage_range,voltage_range,DAQmx_Val_Volts,None)
analog_input.CreateAIVoltageChan(channel,"",input_mode,-voltage_limit,voltage_limit,daq.DAQmx_Val_Volts,None)
analog_input.CfgSampClkTiming("",clock_freq,daq.DAQmx_Val_Rising,daq.DAQmx_Val_FiniteSamps, sampling_pts)
# DAQmx Start Code
analog_input.StartTask()
# DAQmx Read Code
analog_input.ReadAnalogF64(sampling_pts, fill_mode, daq.DAQmx_Val_GroupByChannel,data,sampling_pts, daq.byref(read), None)
print "Acquired %d points" % read.value
return data
示例9: every_n
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def every_n(self, taskHandle, everyNsamplesEventType, nSamples, callbackData_ptr):
callbackdata = get_callbackdata_from_id(callbackData_ptr)
read = pydaq.int32()
self.read_data[:] = 0
pydaq.DAQmxReadAnalogF64(taskHandle,self.read_buffer_size,self.timeout,pydaq.DAQmx_Val_GroupByScanNumber,self.read_data,self.read_buffer_size,pydaq.byref(read),None)
callbackdata.extend(self.read_data.tolist())
self.new_data = True
return 0
示例10: send_signal
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def send_signal(self):
read = Daq.int32()
self.StartTask()
self.WriteDigitalU32(1, 0, 10.0, Daq.DAQmx_Val_GroupByChannel,
self.strobeOn, Daq.byref(read), None)
self.WriteDigitalU32(1, 0, 10.0, Daq.DAQmx_Val_GroupByChannel,
self.strobeOff, Daq.byref(read), None)
self.StopTask()
示例11: __init__
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def __init__(self, dev='Dev1/'):
self.analog_output0 = mx.Task()
self.analog_output0.CreateAOVoltageChan(dev + 'ao0', '', -10.0, 10.0, mx.DAQmx_Val_Volts, None)
self.analog_output1 = mx.Task()
self.analog_output1.CreateAOVoltageChan(dev + 'ao1', '', -10.0, 10.0,
mx.DAQmx_Val_Volts, None)
self.voltage_data = np.zeros(1, dtype=mx.float64) # array for voltages
self.read = mx.int32() # how many values were read by the DAQ
self.voltage_input = mx.Task()
示例12: send_signal
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def send_signal(self, event):
#print event
read = Daq.int32()
self.encode[0] = event
#print self.encode
self.StartTask()
self.WriteDigitalU32(10000, 0, 5.0, Daq.DAQmx_Val_GroupByChannel,
self.encode, Daq.byref(read), None)
self.StopTask()
示例13: readAnalogInput
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def readAnalogInput(self, timeout=3.0):
## DAQmx Read Code
read = daqmx.int32()
numSamplesIn = len(self.dataIn)
self.analog_input.ReadAnalogF64(numSamplesIn, timeout, daqmx.DAQmx_Val_GroupByChannel, self.dataIn, numSamplesIn, byref(read), None)
DebugLog.log("DAQhardware.sendDigTrig(): Read %s samples" % repr(read))
data = self.dataIn
return data
示例14: __init__
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def __init__(self,resource_name, Name = 'NI6120 Digitizer'):
Instrument.__init__(self, resource_name, Name = Name)
self.read = pdmx.int32() # for sampsPerChanRead
self.inputrange_max = 0.2 # can be 42, 20, 10, 5, 2, 1, 0.5, 0.2 Volts
self.inputrange_min = -1.0*self.inputrange_max
self.sample_rate = 8.0e5 # samples per second
self.timeout = 20.0 # seconds
self.samples_per_channel = 2e4
示例15: EveryNCallback
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import int32 [as 别名]
def EveryNCallback(self):
#print 'callback'
read = Daq.int32()
#print 'read', read
self.ReadAnalogF64(1, 10.0, Daq.DAQmx_Val_GroupByScanNumber,
self.EOGData, 2, Daq.byref(read), None)
if self.event:
self.event(self.EOGData)
#print 'x,y', self.EOGData[0], self.EOGData[1]
#print 'okay'
return 0 # the function should return an integer