Difference between revisions of "Debug Stream"

From ROBOTC API Guide
Jump to: navigation, search
Line 24: Line 24:
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''void writeDebugStream(const string sFormatString, ...)'''
+
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| <span class="keywordBI">void </span><span class="keywordB">writeDebugStream</span><span class="codePunc">(</span><span class="keywordBI">const string </span><span class="codeBasic">sFormatString</span><span class="codePunc">, </span><span class="codeBasic">...</span><span class="codePunc">)</span>
 
|-
 
|-
 
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Writes a String to the Debug Stream.
 
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Writes a String to the Debug Stream.
Line 51: Line 51:
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''void writeDebugStreamLine(const string sFormatString, ...)'''
+
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| <span class="keywordBI">void </span><span class="keywordB">writeDebugStreamLine</span><span class="codePunc">(</span><span class="keywordBI">const string </span><span class="codeBasic">sFormatString</span><span class="codePunc">, </span><span class="codeBasic">...</span><span class="codePunc">)</span>
 
|-
 
|-
 
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Writes a String to the Debug Stream starting on a new line.
 
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Writes a String to the Debug Stream starting on a new line.

Revision as of 17:33, 9 January 2012

Main >> NXT >> Functions >> Debug Stream


“Traditional” Debugging Techniques

Debugging a program – finding the errors and correcting them – can be a slow process in solutions without a run-time debugger. Without a debugger you may have to resort to different techniques like:

  • There’s no way to determine if your program is executing the intended logic. So you add code to play different tones/sounds to your program as it executes different “blocks” of code. You determine from the sound what is being executed within your program.
  • If your robot platform supports a display device (which could be a serial link to your PC or an LCD display on the robot) then you would have to add “print” statements to your program code at various points in your program. By examining the display, you can (hopefully) determine what’s happened in your program's execution by the display.

Both of the above techniques are available in ROBOTC. However, a real-time debugger eliminates the need to resort to them. There’s no need to add code for debugging to your program. A built-in debugger provides better functionality without ever having to modify your source code!

There is also a built-in Debug Stream that you can use to keep track of your program from behind the scenes. For example, you could print a message to the Debug Stream when you enter and exit loops, functions, etc. Then you can view the cached Debug Stream to help in the debugging process.

Debug stream 3.png



writeDebugStream

void writeDebugStream(const string sFormatString, ...)
Writes a String to the Debug Stream.


Parameter Explanation
sFormatString A string to write to the debug stream (can be formatted!)


writeDebugStream("int x is: %d", x);  // writes the current value of int 'x' to the debug stream


writeDebugStreamLine

void writeDebugStreamLine(const string sFormatString, ...)
Writes a String to the Debug Stream starting on a new line.


Parameter Explanation
sFormatString A string to write to the debug stream (can be formatted!)


writeDebugStreamLine("int x is: %d", x);  // writes the current value of int 'x' to the debug stream on a new line.