本文整理汇总了Python中PyDAQmx.byref方法的典型用法代码示例。如果您正苦于以下问题:Python PyDAQmx.byref方法的具体用法?Python PyDAQmx.byref怎么用?Python PyDAQmx.byref使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyDAQmx
的用法示例。
在下文中一共展示了PyDAQmx.byref方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: digital_task
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [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: send_signal
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [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()
示例3: read_and_clean
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [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
示例4: get_internal_chan_old
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [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])
示例5: read
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [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()
示例6: analog_task
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [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()
示例7: send_signal
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [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()
示例8: set_voltage_ao1
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [as 别名]
def set_voltage_ao1(self, voltage):
"""Set voltage on ao1
"""
self.voltage_data[0] = voltage
self.analog_output1.WriteAnalogF64(1, True,
mx.DAQmx_Val_WaitInfinitely,
mx.DAQmx_Val_GroupByChannel,
self.voltage_data,
mx.byref(self.read), None)
return self.read
示例9: get_sample_rate
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [as 别名]
def get_sample_rate(self):
""" Get the sample rate of the pulse generator hardware
@return float: The current sample rate of the device (in Hz)
Do not return a saved sample rate from an attribute, but instead retrieve the current
sample rate directly from the device.
"""
rate = daq.float64()
daq.DAQmxGetSampClkRate(self.pulser_task, daq.byref(rate))
return rate.value
示例10: ReadTask
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [as 别名]
def ReadTask(task, num):
read = PDm.int32()
data = (np.zeros((num,), dtype=np.float64))
task.ReadAnalogF64(num,
1000.0,
PDm.DAQmx_Val_GroupByChannel,
data,
num,
PDm.byref(read),
None)
return data[:read.value]
示例11: wait_and_clean
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [as 别名]
def wait_and_clean(self):
"""
This should be called after start().
Waits for the task to finish and then cleans up.
"""
#Wait for the task to finish
complete = _mx.bool32()
while not (complete): _mx.DAQmxGetTaskComplete(self._handle, _mx.byref(complete))
self.clean()
示例12: EveryNCallback
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [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
示例13: read_voltage
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [as 别名]
def read_voltage(self, channel):
"""Read voltage on specific channel. Not efficient!!
Debug use only."""
voltage_input = mx.Task()
voltage_input.CreateAIVoltageChan('Dev1/ai' + str(channel), '',
mx.DAQmx_Val_RSE, -10, 10,
mx.DAQmx_Val_Volts, None)
voltage_input.ReadAnalogF64(1, mx.DAQmx_Val_WaitInfinitely,
mx.DAQmx_Val_GroupByChannel,
self.voltage_data, 1,
mx.byref(self.read), None)
return self.voltage_data
示例14: __init__
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [as 别名]
def __init__(self, mode, device='Dev1', port="ao0", analog_minmax=(-10,10), read_buffer_size=1000, timeout=5., sample_rate=10000.):
# example digital port: 'Port1/Line0:3'
# example analog port: 'ao0'
# DAQ properties
self.mode = mode
self.device = device
self.port_name = port
self.port = '/'.join([device,port])
self.timeout = timeout
self.sample_rate = sample_rate
# Trigger properties
self.minn,self.maxx = analog_minmax
self.read_buffer_size = read_buffer_size
if self.mode == self.ANALOG_OUT:
self.clear_trig = Trigger(msg=self.minn)
elif self.mode == self.DIGITAL_OUT:
self.clear_trig = Trigger(msg=[0,0,0,0])
# Runtime values
self.new_data = False
self.read_data = np.zeros(self.read_buffer_size)
# Setup task
try:
pydaq.DAQmxResetDevice(self.device)
self.task = pydaq.TaskHandle()
pydaq.DAQmxCreateTask("", pydaq.byref(self.task))
if self.mode == self.DIGITAL_OUT:
pydaq.DAQmxCreateDOChan(self.task, self.port, "OutputOnly", pydaq.DAQmx_Val_ChanForAllLines)
elif self.mode == self.ANALOG_OUT:
pydaq.DAQmxCreateAOVoltageChan(self.task, self.port,"", self.minn,self.maxx,pydaq.DAQmx_Val_Volts,None)
elif self.mode == self.ANALOG_IN:
pydaq.DAQmxCreateAIVoltageChan(self.task, self.port,"",pydaq.DAQmx_Val_Cfg_Default, self.minn,self.maxx,pydaq.DAQmx_Val_Volts,None)
pydaq.DAQmxCfgSampClkTiming(self.task,"",self.sample_rate,pydaq.DAQmx_Val_Rising,pydaq.DAQmx_Val_ContSamps,self.read_buffer_size)
self.ai_data = List()
self.id_a = create_callbackdata_id(self.ai_data)
self.every_n_callback = pydaq.DAQmxEveryNSamplesEventCallbackPtr(self.every_n)
pydaq.DAQmxRegisterEveryNSamplesEvent(self.task,pydaq.DAQmx_Val_Acquired_Into_Buffer,self.read_buffer_size,0,self.every_n_callback,self.id_a)
pydaq.DAQmxStartTask(self.task)
except:
self.task = None
warnings.warn("DAQ task did not successfully initialize")
示例15: on_activate
# 需要导入模块: import PyDAQmx [as 别名]
# 或者: from PyDAQmx import byref [as 别名]
def on_activate(self):
""" Activate module
"""
config = self.getConfiguration()
if 'pulsed_file_dir' in config.keys():
self.pulsed_file_dir = config['pulsed_file_dir']
if not os.path.exists(self.pulsed_file_dir):
homedir = self.get_home_dir()
self.pulsed_file_dir = os.path.join(homedir, 'pulsed_files')
self.log.warning(
'The directory defined in parameter "pulsed_file_dir" in the config for '
'SequenceGeneratorLogic class does not exist!\nThe default home directory\n'
'{0}\n will be taken instead.'.format(self.pulsed_file_dir))
else:
homedir = self.get_home_dir()
self.pulsed_file_dir = os.path.join(homedir, 'pulsed_files')
self.log.warning(
'No parameter "pulsed_file_dir" was specified in the config for NIPulser '
'as directory for the pulsed files!\nThe default home directory\n{0}\n'
'will be taken instead.'.format(self.pulsed_file_dir))
if 'device' in config.keys():
self.device = config['device']
else:
self.device = 'Dev0'
self.host_waveform_directory = self._get_dir_for_name('sampled_hardware_files')
self.pulser_task = daq.TaskHandle()
daq.DAQmxCreateTask('NI Pulser', daq.byref(self.pulser_task))
self.current_status = -1
self.current_loaded_asset = None
self.init_constraints()
# analog voltage
self.min_volts = -10
self.max_volts = 10
self.sample_rate = 1000
self.a_names = []
self.d_names = []
self.set_active_channels({
k: True for k in self.constraints['activation_config']['analog_only']})