如何操作使用 DAQmx Python AI Trigger

更新 Jan 2, 2025

產品資訊

驅動程式

  • NI-DAQmx

程式語言

  • Python

問題敘述

我想使用 DAQmx Python AI Trigger (觸發器)在收到 AI Start Trigger 後觸發一些操作。我如何透過 Python DAQmx API 實現這一目標?

解決方案

請參考 DAQmx Python檔案以了解 API 使用詳細資訊。

對於觸發訊號來源,我認為您可以按照知識library文章中提到的步驟: 使用 PXI(e) 控制器上的 SMB 連線器路由觸發訊號,呼叫“ cfg_dig_edge_start_trig ”,並將來源設為[nameofthecontroller/TRIG_SMB] ,例如知識library中LV 範例做了什麼。

請參考下面一個簡單的Python範例程式碼來實現這一點:

import pprint
import nidaqmx

pp = pprint.PrettyPrinter(indent=4)

with nidaqmx.Task() as task:
   clk_rate = 2.0e6 # Sampling freq. It is determined by the ext. clk rate. Unit: [Hz] Please note that the maximum sampling freq. of DAQ board(PXIe-6378) is 3.5 MSa/s/ch.
   tr = [-0.1,1.0] # Timerange to plot.
   num_pts = int(clk_rate * (tr[1]-tr[0])) # Total data acquisition time.

   task.ai_channels.add_ai_voltage_chan("PXIe6378/ai0")
   task.timing.cfg_samp_clk_timing(rate=float(clk_rate), samps_per_chan=num_pts) # Configure the clock configuration.
   task.triggers.start_trigger.cfg_anlg_edge_start_trig(trigger_source = 'APFI1', trigger_level=1.5) # Setup the trigger conditions
   print("1 Channel N Sample Read: ")
   data = task.read(number_of_samples_per_channel=num_pts, timeout=100)
   pp.pprint(data)

注意:此範例是使用  NI MAX 模擬一台 PXIe-6378 裝置來執行 Python 腳本,請根據您的情況變更 add_ai_Voltage_chan 的參數。