Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question using DAQmxGetDevProductCategory method #27

Open
amopremcak opened this issue Feb 10, 2016 · 2 comments
Open

Question using DAQmxGetDevProductCategory method #27

amopremcak opened this issue Feb 10, 2016 · 2 comments

Comments

@amopremcak
Copy link

Hi, I wrote a class to to synchronize the Analog Inputs and Outputs of an NI PCI6221 card. Things were working just fine, but when we tried to run this program on a different computer, we received an error message when using one of the methods from this library. The strange thing is, the computer we are getting this error on is running on more recent NI drivers and the latest PyDAQmx. Here is the code:

try:
    from PyDAQmx import *
except ImportError:
    print "This program requires PyDAQmx to run."
from PyDAQmx.DAQmxCallBack import *
import numpy as np
import ctypes
import re
import time

NI_PCI_6221_MAX_VOLTAGE = 10.0;  # Max voltage output
NI_PCI_6221_MAX_SAMP_RATE = 10000;   # Measurement/generation rate ?? double check this

#Input 250 kS/s
#Output 833 kS/s for single channel, 740 kS.s for two channels
trigName = ""

class CallbackTask(Task):
    def __init__(self):
        Task.__init__(self)
        self.buffLen = 0
        self.callback =None
        self.trigName=""

    def configureCallbackTask(self, analogInputNameStr, sampRate, numSamples):
        self.buffLen = numSamples
        self.data = np.zeros(self.buffLen)
        self.CreateAIVoltageChan(analogInputNameStr,"",DAQmx_Val_Diff,-10.0,10.0,DAQmx_Val_Volts,None)
        self.CfgSampClkTiming("",float(sampRate),DAQmx_Val_Rising,DAQmx_Val_ContSamps,numSamples)
        self.trigName = self.GetTerminalNameWithDevPrefix("ai/StartTrigger")
        self.AutoRegisterEveryNSamplesEvent(DAQmx_Val_Acquired_Into_Buffer,1000,0)
        self.AutoRegisterDoneEvent(0)

    def EveryNCallback(self):
        numReadBack = int32()
        self.data=np.zeros(self.buffLen)
        self.ReadAnalogF64(self.buffLen,10.0,DAQmx_Val_GroupByChannel,self.data,self.buffLen,byref(numReadBack),None)
        if self.callback is not None:
            self.callback(self.data)
        return 0 # The function should return an integer

    def DoneCallback(self, status):
        print "Status",status.value
        return 0 # The function should return an integer

    def setCallback(self, function):
        self.callback = function

    def GetTerminalNameWithDevPrefix(self, terminalName):
        device = ctypes.create_string_buffer(256)
        productCategory = int32()
    numDevices = uInt32()
        self.GetTaskNumDevices(byref(numDevices))
        for i in range(1, numDevices.value+1):
            self.GetNthTaskDevice(i,device,256)
            #Issue occurs in the line below
            DAQmxGetDevProductCategory(device,byref(productCategory))
            if productCategory.value!=DAQmx_Val_CSeriesModule and productCategory.value!=DAQmx_Val_SCXIModule:
                triggername = "/" + device.value + "/" + terminalName
                break
        return triggername

    def getTrigName(self):
        return self.trigName

When I create an instance of the CallbackTask class, the error from the terminal says
"Error initializing wave output:
argument 1: <type 'exceptions.TypeError'>: string or integer address expected instead of c_char_Array_256 instance"

Any thoughts?

@clade
Copy link
Owner

clade commented Feb 10, 2016

Hi,

You should solve your problem by using DAQmxGetDevProductCategory(str(device),byref(productCategory))

The way strings are handled was modified for better compatibility with Python 3.

Pierre

@amopremcak
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants