Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx ANSI C Not Dev Found while Dev has been confirmed to be on list

Hi All, 

 

I am using ANSI C of NI DAQmx to develop my imaging acquisition software. The use of ANSI C is interfaced with PyDAQmx using Python language. The code is attached at the end of this message. By using DAQmxGetSysDevName and 

DAQmxGetTaskChannels, I can get the right device name as "Dev2" and all relevant channels, such as "Dev2/ao0". Before DAQmxWriteAnalogF64, everything came right as expected. However, when calling DAQmxWriteAnalogF64, it generated errors as shown below. I have double checked the device name in NI MAX and it is "Dev2". So now it is out of my knowledge what is going on. So please help me figure out what happened in my implementation. Thanks a lot. 
 

DAQmx Error: No device by the given name was found.
Device Specified: Dev

Task Name: Galvo_Control_Signal

Status Code: -88717
in function DAQmxWriteAnalogF64

 

####################################################

Codes in Python 

####################################################

class DAQInit():
    def __init__(self,GalvoData,scanMode="2D",NumOfAscans=1024,LineScanRate=5000,XOffset=2,YOffset=2,GalvoRate=10000,swapAxis=0,PointsInEachWvm=1000000,deviceName="Dev2"😞
        self.GalvoData = GalvoData
        self.scanMode = scanMode
        self.NumOfAscans = NumOfAscans
        self.LineScanRate = LineScanRate
        self.XOffset = XOffset
        self.YOffset = YOffset
        self.GalvoRate = GalvoRate 
        self.swapAxis = swapAxis 
        self.deviceName = deviceName.encode("utf-8"
        self.AOphysicalChannel = "Dev2/ao0:3"
        self.AOphysicalChannelClkSoure = "/Dev2/PFI12" 
        self.PointsInEachWvm = PointsInEachWvm 
        self.AOphysicalChannelTriggerSource = "/Dev/PFI14"
        self.CreateDevAO(self.GalvoData,self.AOphysicalChannel,self.AOphysicalChannelClkSoure,self.GalvoRate,self.PointsInEachWvm,self.AOphysicalChannelTriggerSource)

    def CreateDevAO(self,Galvodata,physicalChannel,ClkSource,Rate,sampsPerChan,TriggerSource,limit = [-5,5]):
        self.physicalChannel  = physicalChannel
        self.AOphysicalChannelGalvoData = Galvodata 
        self.AOphysicalChannelClkSoure = ClkSource.encode('utf-8'
        self.AOClkRate = Rate 
        self.sampsPerChan = sampsPerChan 
        self.triggerSource = TriggerSource.encode('utf-8')     
        taskHandles = TaskHandle(0)
        self.DevAOtaskHandles = []
        self.ActualSampsPerChan = C.c_int32(0)
        self.limit = limit       
        xt = 'e'
        attr = C.create_string_buffer(xt.encode("utf-8"),64
        buffer = C.c_uint32(40)
        try:
            DAQmxCreateTask("Galvo_Control_Signal",C.byref(taskHandles))
            print(taskHandles.value)
            # create physical channel as Analog Output
            DAQmxCreateAOVoltageChan(taskHandles,self.physicalChannel.encode("utf-8"),"",self.limit[0],self.limit[1],DAQmx_Val_Volts,None)
            DAQmxGetSysDevNames(attr,buffer)
            print("System Device Name(s): {}".format(attr.value))
            # configure sample clock 
            DAQmxCfgSampClkTiming(taskHandles,self.AOphysicalChannelClkSoure,self.AOClkRate,DAQmx_Val_Rising, DAQmx_Val_FiniteSamps,self.sampsPerChan)
            # start trigger of analog output write 
            DAQmxCfgDigEdgeStartTrig(taskHandles,self.triggerSource,DAQmx_Val_Rising)
            # set trigger to be retriggerable
            DAQmxSetStartTrigRetriggerable(taskHandles,True
            # write data into buffer of analog output channel
            DAQmxWriteAnalogF64(taskHandles,self.sampsPerChan,True,0,DAQmx_Val_GroupByChannel,self.AOphysicalChannelGalvoData,C.byref(self.ActualSampsPerChan),None)  # None is passed as c null pointer

        except DAQError as err:
            print("DAQmx Error: %s"%err)
        finally:
            if taskHandles:
                # DAQmx Stop Code
                DAQmxStopTask(taskHandles)
                DAQmxClearTask(taskHandles) 
        
        self.DevAOtaskHandles = taskHandles         
    

if __name__ == "__main__":
    t = np.linspace(0,100,10000)
    f = 1 
    y = 0.01*np.sin(2*np.pi*f*t)  
    d = np.asarray([y,-y,y*2,-y*2])
    DAQInit_examp = DAQInit(GalvoData=d.astype(np.float64),PointsInEachWvm=np.size(t))  
0 Kudos
Message 1 of 2
(1,624 Views)
        self.AOphysicalChannel = "Dev2/ao0:3"
        self.AOphysicalChannelClkSoure = "/Dev2/PFI12" 
        self.PointsInEachWvm = PointsInEachWvm 
        self.AOphysicalChannelTriggerSource = "/Dev/PFI14"

 

One of these things is not like the others...

 

I only use LabVIEW so I don't totally follow the text syntax in detail.  A second factor that's *probably* at work is that your AO task may have an "auto-start on write" behavior.  (I don't see it being set up explicitly, perhaps the python API makes it a default behavior?)  

 

The DAQmx Task State Model shows how tasks are transitioned through various resource-reservation and verification steps before actually starting the task.  Many error conditions are not discovered until these steps are attempted so that's where the error is first reported, even if the real syntax problem occurred upstream a ways. 

    The real problem is the simple typo shown at the top, I only bother getting into the other stuff b/c I recognize that it can be confusing when the error is noticed and thrown in a different place than where the mistake was made. 

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 2
(1,566 Views)