0

这里需要一些帮助,我有一个 DAQ 测量计算 USB-1208LS,我需要一些关于如何控制 DAQ 的想法。

我已经安装了 UniversalLibrary,但我可以找到任何示例。这个想法很简单,我需要读取 5 个不同的电压,3.3v 5.0v 7.50v,10.10v 和 12.00v。

谢谢大家的帮助。

4

1 回答 1

1

这可以通过 ctypes 模块连接到 UniversalLibrary 来完成。

我没有手头的 DAQ 来确保它有效,但这是从我拥有的一些旧 DAQ 代码中挖掘出来的,并演示了 1208LS 的基本控制。

# Pulled from some old 2.6 code
from ctypes import *  # Old code, bad import
from time import sleep

# DAQ configuration parameters
# Check the Universal Library documentation for your DAQ
BOARD = 0
LOW_CHANNEL = 0
HIGH_CHANNEL = 0
GAIN = 15  # This samples in the +-20 volt range
RATE = 100  # Samples per second
SAMPLES = 100  # Number of samples to record
OPTIONS = 1  # Run the DAQ in background mode so it isn't blocking

# Load the DAQ DLL
mcdaq = windll.LoadLibrary("cbw32")

# Initialize memory handle where the DAQ will pass data
mem_handle = mcdaq.cbWinBufAlloc(SAMPLES)

# The DAQ will update this with the actual rate used
actual_rate = c_long(RATE)

# Start the sampling
start_status = mcdaq.cbAInScan(BOARD, LOW_CHANNEL, HIGH_CHANNEL, SAMPLES,
                               byref(actual_rate), GAIN, mem_handle, OPTIONS)
if start_status != 0:
    # An error occured starting the DAQ
    exit(1)

sleep(2)  # Do other stuff while the DAQ is recording

# Make sure the scan is stopped and check the scan status
status = mcdaq.cbStopIOBackground(BOARD, 1)
if status != 0:
    # An error occured, check documentation for the specific status code
    pass

# Now pull the data
# Check the status of the DAQ and find out how many samples have been recorded
stat = c_int()
current_count = c_long()  # Count of how many samples to retrieve from memory
current_index = c_long()
s = mcdaq.cbGetIOStatus(BOARD, byref(stat), byref(current_count),
                        byref(current_index), 1)
# Make an array to hold the data
sample_array_type = c_ushort * current_count.value
data_array = sample_array_type()

# Retrieve data from DAQ memory
status = mcdaq.cbWinBufToArray(mem_handle, byref(data_array), 0,
                               current_count.value)
# Values in data_array will be in DAQ counts

有关枚举值和函数签名的完整文档,请阅读通用库文档

于 2018-05-31T17:10:12.450 回答