
[XOP] C macros for printing to the history

thomas_braun
One can also move the variable definition char buf[] out of the macro and use a global buffer instead (single threaded code only).
<br /> #define ARRAY_SIZE 1024<br /> // Accepts multipe arguments like printf and prints them to the history<br /> // Custom prefixes can be also inserted, see the DEBUGPRINT macro<br /> // Copies only ARRAY_SIZE-2 characters in _snprintf, because we want to have space for the terminating \0 (1) and for the CR (1)<br /> // Checking the return value of _snprintf is not done on purpose, we just always append a \0 to be safe<br /> // @param A prints only if A evaluates to true<br /> // @param B uses silent printing (does not mark the experiment as changed) if true<br /> #define PRINT_TO_HISTORY(A,B,...) \<br /> if (RunningInMainThread() && A) \<br /> { \<br /> char buf[ARRAY_SIZE]; \<br /> _snprintf(buf,ARRAY_SIZE-2, __VA_ARGS__); \<br /> buf[ARRAY_SIZE-2] = '\0'; \<br /> strcat(buf,CR_STR); \<br /> if (!B) \<br /> { \<br /> XOPNotice(buf); \<br /> } \<br /> else \<br /> { \<br /> XOPNotice2(buf,0); \<br /> } \<br /> }<br /> <br /> // debuggingEnabled is a global boolean variable or similar which turns debug output on/off<br /> <br /> // Convenience wrapper using silent debug print<br /> #define DEBUGPRINT_SILENT(...) \<br /> PRINT_TO_HISTORY(debuggingEnabled,true,"DEBUG: "__VA_ARGS__)<br /> <br /> // Convenience wrapper using debug print<br /> #define DEBUGPRINT(...) \<br /> PRINT_TO_HISTORY(debuggingEnabled,false,"DEBUG: "__VA_ARGS__)<br /> <br /> // Convenience wrapper for printing<br /> #define HISTPRINT(...) \<br /> PRINT_TO_HISTORY(true,false,__VA_ARGS__)<br /> <br /> // Convenience wrapper for silent printing<br /> #define HISTPRINT_SILENT(...) \<br /> PRINT_TO_HISTORY(true,true,__VA_ARGS__)<br />
Usage:
<br /> int ret = MDSetWaveScaling(m_waveHandle,dimension,sfAPtr,sfBPtr);<br /> if(ret != 0){<br /> HISTPRINT("MDSetWaveScaling returned error %d",ret);<br /> }<br /> // [...]<br /> DEBUGPRINT("traceUpRawBrickletIndex=%d,rawBrickletSize=%d",rawIndex,rawBrickletSize);<br /> // [...]<br /> DEBUGPRINT("numPointsRootAxis=%d",numPointsRootAxis);<br />

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More