DAQ USB-1208LS Python 3.4

时间:2017-03-24 22:33:56

标签: python-3.x measurement daq-mx

在这里需要一些帮助,我有一个DAQ Measurement Computing USB-1208LS,我需要一些关于如何控制DAQ的想法。

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

谢谢大家的帮助。

1 个答案:

答案 0 :(得分: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

有关枚举值和函数签名的完整文档,请阅读Universal Library documentation