Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

why am i getting the error -200428, NI-USB 6218 on CentOS5.3

We are using a NI-USB 6218 running on CentOS5.3.  My goal is to create a code that switches from DO to AI many times (moving a stepper motor, then acquiring, then moving again etc). I am working with ematlis on this problem who posted earlier questions.

 

We do not want to create multiple instances of a task. Therefore in the main function, we create task, and then call DAQmxBaseWriteDigitalU32 in a function writeDigPort.  Following are snippets of the code:

 

-----------------------------------------------------------------------------

main() {

TaskHandle taskHandleDO = 0;

DAQmxBaseCreateTask("",&taskHandleDO);

DAQmxBaseCreateDOChan(taskHandleDO,chan,"",DAQmx_Val_ChanForAllLines);

DAQmxBaseStartTask(taskHandleDO);

writeDigPort(taskHandleDO)

writeDigPort(taskHandleDO)

------------------------------------------------------------------------------

writeDigPort(taskHandle taskHandleDO) {

DAQmxBaseWriteDigitalU32(taskHandleDO,1,1,10.0,DAQmx_Val_GroupByChannel,w_data,&written,NULL));

 }

 __________________________________________________________________

 

We are getting the following error just prior to WriteDigitalU32 on the second call to writeDigPort:

 

DAQmxBaseError -200428: Value passed to the Task/Channels In control is invalid.

 

Can we get some advice on this?

 

Thanks.

 

 

 

 

0 Kudos
Message 1 of 11
(4,330 Views)

Hi user031481,

 

The correct way to accomplish the desired behavior would be to create an analog task as well as a digital task.  Look at some of the examples mentioned here: Excerpt from Programming Data Acquisition for Linux with NI-DAQmx Base

 

C examples are installed by default to /usr/local/natinst/nidaqmxbase/examples. The make files create the links to the necessary libraries. Run the device configuration utility (lsdaq) before running the examples. An example that is shipped with NI-DAQmx Base is 'Acquire N Scans'. To compile and run this example:
  1. cd /usr/local/natinst/nidaqmxbase/examples/ai
  2. make
  3. ./acquireNScans

LabVIEW help files are accessible from the LabVIEW Help menu.

Documentation is located in /usr/local/natinst/nidaqmxbase/documentation and includes the NI-DAQmx Base C Function Reference, the hardware references, and supporting PDFs. 

For more information, please refer to the readme file available for download along with NI-DAQmx Base for Linux.

 


Here is a Knowledge Base Article about the error you are receiving.  Good Luck!

 

Regards, 

Dustin D

0 Kudos
Message 2 of 11
(4,307 Views)

Dustin D-

 

thanks for your response, however we are using text-based programming in C, not in labview.  The links you mention seem to have the labview programmer in mind.  We hope to avoid using it.  The Knowledge Base Article discusses dynamic vs static tasks.  Can anybody elaborate on what the difference is, taking into mind that we are programming in a text-based environment?

 

thanks much.

 

eric

0 Kudos
Message 3 of 11
(4,286 Views)

Hi Eric,

 

If you look at my last post, it gives the paths for all of the C examples and help files.  Also the related link on the Knowledge Base will explain your question between dynamic and static tasks.  Post back if you still have questions!

 

Regards,
Dustin D

0 Kudos
Message 4 of 11
(4,271 Views)

Dustin-

 

I have read the Knowledge Base article:

 

" This error indicates that you are configuring your task incorrectly. As you may know, there are two types of tasks: Dynamic Tasks and Static Tasks. Dynamic Tasks are created manually in LabVIEW, Static Tasks are generated from the NI-DAQmx Base Configuration Utility."

 

As I am working in a text-based environment, programming C-code, this does not shed any light.  I am not using LabVIEW, and I am not using the NI-DAQmx Base Configuration Utility.  So I am not sure what I am supposed to gain by reading that article.  I am still clueless on what the difference is between a dynamic task and a static task, and what if anything that has to do with my problem.

 

I browsed the sample codes in the examples directory, and they do not shed any light on this issue.

 

To recap what may not have been clear in the original posting:I am trying to do multiple DO operations (as well as AI, but I haven't got that far yet).  I created a test code to do this.  I can do this with one instance of a CreateTask if I keep all the code in the main calling program.  If I separate the guts of the DO from the main program and put it into a subroutine, I get the 200428 error, but only on the second execution of that subroutine- the first one works fine.  Here is the version of the code with this problem, I have put a note where the subroutine is successfully called and where it fails.  The subroutine in question is called "writeDigPort":

 

 

 #define DAQmxErrChk(functionCall) { if(DAQmxFailed(error=(functionCall)) ) {goto Error; }}
int writeDigPort(TaskHandle taskhandle,uInt32,int);
int acquireNScans(char[],uInt64,float64,char[]);
int genDigPulseTrain(char[],int,int,uInt32,float32);

int main(void) {
TaskHandle taskHandleDO = 0;
          int direction ;
// Set Channel Numbers, filenames
        char chan[] = "Dev1/port1";
// Task parameters
        int32     error=0;    
        char errBuff[2048];

// Begin Program
    DAQmxErrChk (DAQmxBaseCreateTask ("",&taskHandleDO));
    DAQmxErrChk (DAQmxBaseCreateDOChan(taskHandleDO,chan,"",DAQmx_Val_ChanForAllLines));
        DAQmxErrChk (DAQmxBaseStartTask (taskHandleDO));
        direction = 1;

/********** Subroutine Works Successfully! *****/

    DAQmxErrChk (writeDigPort (taskHandleDO,1,direction));  //First execution of DO subroutine works successfully

         usleep(1000000);
    direction = 0;

/***********Subroutine Fails with 200428 ******/

    DAQmxErrChk (writeDigPort (taskHandleDO,1,direction));  //Second execution of DO subroutine fails with 200428

Error:
    if (DAQmxFailed (error))
       DAQmxBaseGetExtendedErrorInfo (errBuff, 2048);
        if (taskHandleDO != 0)
    {
       DAQmxBaseStopTask (taskHandleDO);
           DAQmxBaseClearTask (taskHandleDO);
    }

    if (error)
       printf ("DAQmxBase Error: %ld: %s\n", error, errBuff);

return 0;
}

 
int writeDigPort(TaskHandle  taskHandleDO, uInt32 lineNum,int direction)
{
   // Task parameters
   int32       error = 0;
   char        errBuff[2048];

   // Channel parameters
   //char        chan[] = "Dev1/port1";

   // Write parameters
   uInt32      w_data[1];
   int32       written;

   printf("Entering writeDigPortFunc.c\n");
   // Create Digital Output (DO) Task and Channel
   printf("direction = %d\n",direction);
   if(direction == 0) {w_data[0]=0;} //set all channels to zero
   else {w_data[0]=lineNum;} //turn on selected channel
   
   printf("Data to write: %ld\n", w_data[0]);
   printf("taskHandle: %d\n",taskHandleDO);
    //DAQmxErrChk (DAQmxBaseCreateDOChan(taskHandleDO,chan,"",DAQmx_Val_ChanForAllLines));
    //DAQmxErrChk (DAQmxBaseStartTask (taskHandleDO));
   DAQmxErrChk (DAQmxBaseWriteDigitalU32(taskHandleDO,1,1,10.0,DAQmx_Val_GroupByChannel,w_data,&written,NULL));
   printf("after\n");

Error:

   if (DAQmxFailed (error))
      DAQmxBaseGetExtendedErrorInfo (errBuff, 2048);

   if (taskHandleDO != 0)
   {
      DAQmxBaseStopTask (taskHandleDO);
      DAQmxBaseClearTask (taskHandleDO);
   }

   if (error)
      printf ("DAQmxBase Error %ld: %s\n", error, errBuff);

   return 0;
}

 

Any advice is appreciated.

 

thanks,

eric

0 Kudos
Message 5 of 11
(4,266 Views)

eric,


What happens if you remove the DAQmxErrChk() from your subroutine call?  Does that change the behavior at all?  Also can you tell where in the subroutine that it fails?  Also a good test would be to change the parameters of the subroutine to match so they are the same time so you can isolate whether the error comes from a second execution or the parameters provided.  Keep me updated!

 

Regards, 

Dustin D

0 Kudos
Message 6 of 11
(4,238 Views)

Dustin-  removing the error call from the subroutine eliminates the error, which had ocurred when the DAQmxBaseWriteDigitalU32 function was called.  However, the second call still does not work correctly; the output port is not being addressed.  I can send a high (1) in the first call, but sending a low (0) in the second does nothing; the signal remains high. 

 

thanks,

eric

0 Kudos
Message 7 of 11
(4,225 Views)

Eric,

 

Try setting the "autoStart" parameter to FALSE 

 

Function Prototype From Documentation: 

int32 DAQmxBaseWriteDigitalU32 (TaskHandle taskHandle, int32 numSampsPerChan,
bool32 autoStart, float64 timeout, bool32 dataLayout, uInt32 writeArray[ ],
int32 *sampsPerChanWritten, bool32 *reserved)

 

Your Function Call: 

DAQmxBaseWriteDigitalU32(taskHandleDO,1,1,10.0,DAQmx_Val_GroupByChannel,w_data,&written,NULL)

 

It states int the function reference that "Specifies whether or not this function automatically starts the task if you do
not start it. This is used only for static digital tasks, otherwise set
autoStart to False."
 You are using dynamic tasks, so this is the next red flag that I see.  Keep me updated. Good Luck

 

Regards,
Dustin D

0 Kudos
Message 8 of 11
(4,218 Views)

Dustin, thanks once again but this did not change anything.  I set that third parameter to FALSE (and also 0), but it did not help; only the first execution of that subroutine works.

 

The data value I am sending is a 0 or a 1.  Do I need to send these as hex values, mask it with a 32-bit word since I am sending to all 4 ports?

 

thanks,

eric

0 Kudos
Message 9 of 11
(4,216 Views)

Hi Eric,


You may want to make sure that the argument you are providing matches the data type correctly.  Here's a link to the C Function Reference to find the data types of the input parameters.

 

Regards,
Dustin D

0 Kudos
Message 10 of 11
(4,188 Views)