0

PythonでUSB 6211を使用している場合、2つのチャネルを同時に読み出そうとしています。そのために、行を変更してhttp://www.scipy.org/Cookbook/Data_Acquisition_with_NIDAQmxの例を適応させようとしました

CHK(nidaq.DAQmxCreateAIVoltageChan(
        taskHandle,
        "Dev1/ai0",
        "", 
        DAQmx_Val_Cfg_Default, 
        float64(-10.0),
        float64(10.0), 
        DAQmx_Val_Volts,
        None))

CHK(nidaq.DAQmxCreateAIVoltageChan(
    taskHandle,
    "Dev1/ai0:1",
    "", 
    DAQmx_Val_Cfg_Default, 
    float64(-10.0),
    float64(10.0), 
    DAQmx_Val_Volts,
    None))

しかし、「nidaq call failed with error -200229: 'Buffer is too small to fit read data」というエラー メッセージが表示され続けます。行を追加しCHK(nidaq.DAQmxCfgInputBuffer(taskHandle, uInt32(10000000)))たり、データ配列の長さを増やしたりしても解決しませんでした...

誰かが変更する正しい変数を教えてもらえますか?

4

2 に答える 2

2

ここで答えを見つけました:http://www.physics.oregonstate.edu/~hetheriw/whiki/py/topics/ni/files/ni-daq_ctypes_multichannel_adc_usb_6008.txt

つまり、nidaq.DAQmxReadAnalogF64() の引数は、taskHandle の後に追加の引数「-1」が必要です。行は次のようになります。

CHK(nidaq.DAQmxReadAnalogF64(taskHandle, -1,float64(1.0),
    DAQmx_Val_GroupByScanNumber,#DAQmx_Val_GroupByChannel,#DAQmx_Val_GroupByScanNumber
    data.ctypes.data,max_num_samples,
    ctypes.byref(read),None))
于 2013-02-28T07:46:47.527 に答える
1

これは、USB-6009 で A to D を行うために使用するオブジェクトです。注: 下部に呼び出し手順の例があります。

#-------------------------------------------------------------------------------
# Name:       This is a object that takes data from the AtoD board
# Purpose:
#
# Author:      Carl Houtman
#
# Created:     12/10/2012
# Copyright:   (c) Carl Houtman 2012
# Licence:     none
#-------------------------------------------------------------------------------
from PyDAQmx import *
import numpy

class DAQInput:

    def __init__(self, num_data, num_chan, channel, high, low):
        """ This is init function that opens the channel"""
        # Declare variables passed by reference
        taskHandle = TaskHandle()
        read = int32()
        data = numpy.zeros((10000,),dtype=numpy.float64)
        sumi = [0,0,0,0,0,0,0,0,0,0]

        #Get the passed variables
        self.num_data = num_data
        self.channel = channel
        self.high = high
        self.low = low
        self.num_chan = num_chan

        # Create a task and configure a channel
        DAQmxCreateTask(b"",byref(self.taskHandle))
        DAQmxCreateAIVoltageChan(self.taskHandle,self.channel,b"",DAQmx_Val_Cfg_Default,
                                 self.low,self.high,DAQmx_Val_Volts,None)
        # Start the task
        DAQmxStartTask(self.taskHandle)

    def getData(self):
        """ This function gets the data from the board and calculates the average"""
        DAQmxReadAnalogF64(self.taskHandle,self.num_data,10.0,DAQmx_Val_GroupByChannel,
                           self.data,10000,byref(self.read),None)

        # Calculate the average of the values in data (could be several channels)
        i = self.read.value
        for j in range(self.num_chan):
            self.sumi[j] = numpy.sum(self.data[j*i:(j+1)*i])/self.read.value
        return self.sumi

    def killTask(self):
        """ This function kills the tasks"""
        # If the task is still alive kill it
        if self.taskHandle != 0:
            DAQmxStopTask(self.taskHandle)
            DAQmxClearTask(self.taskHandle)

if __name__ == '__main__':
    myDaq = DAQInput(100, 2, b"Dev1/ai0:1", 10.0, -10.0)
    result = myDaq.getData()
    print ("the average readings were {:.4f} and {:.4f} volts".format(result[0], result[1]))
    myDaq.killTask()
于 2013-03-25T21:38:31.620 に答える