LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxFailed - cannot find definition

I cannot find where DAQmxFailed() function is defined.  Apparently, it is used all over the place.  Please help.

0 Kudos
Message 1 of 9
(6,661 Views)

DAQmxFailed macro is defined in nidaqmx.h.

You can find actual definition of a term in a CVI program by right-clicking on it and choosing "Go to definition" item in the context menu.

This is valid for variables, macros, functions and even UI objects.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 9
(6,657 Views)

I did use that Go To Definition and it did not work.

0 Kudos
Message 3 of 9
(6,655 Views)

OK, I open that file and it says:

 

#define       DAQmxFailed (error)              ((error) < 0)

 

what does that mean???

 

 

Message 4 of 9
(6,653 Views)

1. Go to definition works only if you have compiled and linked the project

 

2. This is a macro the returns TRUE when error < 0. A typical usage of itcan be found in several examples from CVI:

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

The key is DAQmxFailed(error=(functionCall))  instruction: when the program is compiled, DAQmxFailed macro tests the return code from the function where it is used, returns TRUE if the function fails and passes it to calling DAQmxErrChk macro.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 5 of 9
(6,648 Views)

Hello, hn_sofec!

 

Some questions:

  1. Did you include "nidaqmx.h" in you source files?
  2. Which version of CVI are you using?

Note, that beginning with CVI 2013, Go to Definition uses the CVI source code browsing information, generated by CVI, according to the browse information generation policy (Option » Environment » Generate browse information policy). The default value for this setting is On Edit, which means that CVI is generating browsing information whitout requiring a compilation. Note, that CVI 2013 (or later) generates browsing information only from source files (.c files) added to your active project.

 

On the other hand, CVI 2012 (and earlier versions of CVI) require an explicit successful build of your project, in order for you to benefit from source code navigation.

 

Assuming you are using CVI 2013, here are some reasons why you cannot find the definition of the macro:

  1. "nidaqmx.h" is not included in your source file.
  2. Previous syntax/compilation errors might prevent the background parsing mechanism to be able to retrieve the definition of your symbol.
  3. If 1. is true, make sure your source file is added in the currently active project.

Also, assuming that you are using CVI 2013, can you confirm which types of usages does the DAQmxFailed have?

Are these direct usages in the source code, (e.g. if (DAQmxFailed(error)) { ... }), or only usages inside #define preprocessing directives (e.g. #define MACRO(error) DAQmxFailed(error) )?

 

Best regards!

- Johannes

0 Kudos
Message 6 of 9
(6,628 Views)

I am using CVI 2013 SP2.  I have not compiled the code yet.  I suppose that is the reason Go To Def does not work.

0 Kudos
Message 7 of 9
(6,613 Views)

I need help understanding this:

 

1. 

#define     DAQmxFailed(error)      ((error) < 0)  

when DAQmxFailed(error) is used, it returns TRUE is error < 0 and FALSE otherwise, correct?

 

2. and this one:

 

DAQmxErrChk(functionCall)     if( DAQmxFailed(error=(functionCall)) )     goto Error; else

 

inside if(), the argument of DAQmxFailed() is an assignment of error = functionCall, correct?

 

3. why are error in Q1, and functionCall in Q2 placed between parentheses?

Message 8 of 9
(6,610 Views)

hn_sofec,

 

CVI 2013 SP2 does not require a build of your source code, for you to benefit from browsing information, unless the CVI ADE browsing generation policy is set to On Compile.

 

  1. DAQmxFailed(error) returns:
    • 0, if error >= 0 and
    • a value greather than 0 (e.g. 1) if error < 0.
    • You can try that for yourself in a simple C-application: int value = (1 < 0);
  2. What the DAQmxErrChk macro:
    1. first calls functionCall function,
    2. then assigns the return value of the functionCall functin to the error variable.
    3. After that, DAQmxFailed checks whether error is strictly smaller than 0.
    4. If error is smaller than 0, goto Error is executed and the program jumps to the Error: label.
  3. In Q1 and Q2, error and functionCall respectively, are placed inside parentheses to prevent syntax errors or errors at run time.
    Macro arguments are literally pasted inside the macro body letter-by-letter.
    This means that:
    #define MYMACRO(argument) argument < 0
    ...
    if (MYMACRO(1)) { ...

    translates into:
    if (1 < 0) { ...

    However, there are cases, in which you may paste some weird constructions of expressions into the macro parameter list, which cause the end result to be ambiguous or erroneus:
    #define MYMACRO(argument) (argument < 1)
    3 + MYMACRO(0)
    translates into:
    3 + 0 < 1
    which is false, because instead of computing 0 < 1 first, (which would be 1) and then adding the result to 3, which is 4, the + actually takes greater precedence over the <.
    The point is, that you usually want to protect the input of the macro argument because of this caveat.

 

Best regards!

- Johannes

Message 9 of 9
(6,605 Views)