DAQ USB-1208LS Python 3.4

Мне нужна помощь, у меня есть USB-1208LS для измерения DAQ, и мне нужно немного узнать о том, как управлять DAQ.

Я установил UniversalLibrary, но я могу найти любой пример. Идея очень проста, мне нужно прочитать 5 различных напряжений, 3,3 В, 5 В, 7,5 В, 10,10 В и 12,00 В.

Спасибо всем за помощь.

1 ответ

Решение

Это может быть сделано путем взаимодействия с UniversalLibrary через модуль ctypes.

У меня нет под рукой 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

Полную документацию по значениям перечислений и сигнатурам функций читайте в документации Универсальной библиотеки.

Другие вопросы по тегам