Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxStartTask fails if another App is also using the same port

Hello,

I'm new the NI product. I'm trying to read/write the PXI6528 card. If at the same time I have another application read/write the port that was trying to read/write, then I'll get error code -200587. Here is a part of the code that I based on the NI example:

 

I call this read function every 2 seconds:

 

   DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
   DAQmxErrChk (DAQmxCreateDIChan(taskHandle,  channel,   "",  DAQmx_Val_ChanForAllLines));
  

   while (Is_Task_Done == 0)
   {
      DAQmxIsTaskDone (taskHandle, &Is_Task_Done);
     
      if (Is_Task_Done)
      {
        
         DAQmxErrChk (DAQmxStartTask(taskHandle));
        
         DAQmxErrChk (DAQmxReadDigitalLines(taskHandle, (int32)SamplePerChan, (float64)DAQ_Timeout,
                                         DAQmx_Val_GroupByChannel, data, (uInt32)px6528dio_ArraySizeInByte,
                                                            &read, &bytesPerSamp, NULL));
      }
   }
 

 

While this function is being called from my app, I open the NI  Measurement & Automation Explorer, open the Test Panel for the 6528, start test on Port0, this is the same port that was calling. The DAQmsStartTask would fail and give error.  This is just a demontration so you can see if 2 different Apps running and happen call on a same port & same time. How do I reserve the device or avoid getting this problem? I am using CVI 9.0 and NI-DAQmx 8.8.

 

 

 

 

0 Kudos
Message 1 of 3
(2,837 Views)

Hi tmdkelly,

 

According to this article, this error generally occurs when you have a task already running on your device or the resources are already reserved.  Looking at your code, I believe you should start your task before checking if your task is done, since you are checking that loop until completion.  Then, you need to have a stop or clear task if you are going to invoke this code again, so that when you call start task you will not have a task already running.

 

You are correct in identifying that you cannot access the same resources from two different applications.  The resources may only be reserved for one operation.  What you can do is run your DAQmx code and make sure that you clear the task before your other application takes the resources.  When that application takes the resources, you will need to have that release them before your DAQmx code tries using the resources again (2 seconds according to your statement). 

 

Kyle A.
National Instruments
Senior Applications Engineer
0 Kudos
Message 2 of 3
(2,808 Views)

It sounds like you want your main application to run without worrying about another application taking over the resource.  The best way to do this is to keep the task running throughout the application and just using the DAQmxRead and DAQmxWrite functions to interact with the board.  As long as the task is running, your resource will stay reserved.  Thus, instead of creating the task and channel, then starting the task every time you call the function, create the Task and channel and start the task at the beginning of your application and just read whenever you want data, then at the end of your application call StopTask and ClearTask.

 

Regards,

Seth B.
Principal Test Engineer | National Instruments
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 3 of 3
(2,806 Views)