Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Debugging Slows Serial Monitor (Read 4771 times)
Cagurtay
Newbies
*
Offline


Posts: 1
Joined: Jan 16th, 2014
Debugging Slows Serial Monitor
Jan 20th, 2014 at 10:59am
Print Post  
Hello,
I am trying to use this code with Leonardo and Ethernet Shield but there is something wrong with Visual Micro Serial Monitor when i upload with Start Debugging, sometimes it doesn't register characters and/or registers slowly (1-2 sec delay). I tried same code without debugging or on Arduino IDE and it worked perfectly. 

If i upload with Debugging and open Arduino IDE Serial Monitor :



I am using Windows Telnet to connect to Arduino.
These three outputs came from same input.
Input:


Arduino output: 


Visual Micro With Debugging(I cut "We have a new client"): 


Visual Micro Without Debugging(I cut "We have a new client"):


It looks like Debugging Output slows down serial monitor, how can i fix this? 
Any ideas?
Thank you.


Code
Select All
/*
 Chat  Server

 A simple server that distributes any incoming messages to all
 connected clients.  To use telnet to  your device's IP address and type.
 You can see the client's input in the serial monitor as well.
 Using an Arduino Wiznet Ethernet shield.
/*
 Chat  Server

 A simple server that distributes any incoming messages to all
 connected clients.  To use telnet to  your device's IP address and type.
 You can see the client's input in the serial monitor as well.
 Using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(X,X,X,X); // blocked IP adress
IPAddress gateway(x,x,x,x); // blocked gateway IP adress
IPAddress subnet(255,255,255,192);


// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
  // start listening for clients
  server.begin();
  // Open serial communications and wait for port to open:
  Serial.begin(115200l);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Chat server address:");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // wait for a new client:
  EthernetClient client = server.available();

  // when the client sends the first byte, say hello:
  if (client) {
    if (!alreadyConnected) {
      // clead out the input buffer:
      client.flush();   
      Serial.println("We have a new client");
      client.println("Hello, client!");
      alreadyConnected = true;
    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
      // write the bytes to serial monitor:
      Serial.write(thisChar);
    }
  }
}

 

« Last Edit: Jan 20th, 2014 at 11:00am by Cagurtay »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Debugging Slows Serial Monitor
Reply #1 - Jan 20th, 2014 at 3:21pm
Print Post  
Hi,

There are a couple of things that can cause this when the debugger is active. 

1)
When the debugger is running it currently stores the data waiting for a line feed character. It times out after a couple of seconds if it does not receive a line feed and displays what is in the buffer.

So the first question is to find out if when you send "1234567890 abcdef" that you are using println() and not print()? println() sends a line feed.

2)
The seconds thing is to consider that, optionally but by default, the debugger shares the serial port with the print() messages already in the sketch. 

You can see from the VMDPE messages that with debugging enabled we had a breakpoint running frequently. This combined with the messages in the sketch can cause the serial buffer on the Arduino to overflow causing characters (such as line feed) to be lost. Depending on your pc it can also cause the debugger to work very hard.

This can especially be a problem if a breakpoint is added to an Arduino code line that also sends a serial message. So it's best to keep breakpoints away from lines that contain manual serial.print() debug messages (might not be relevant but thought I would mention it.

It would help if you confirmed if you are using the automatically created demo breakpoint that Visual Micro  adds for new users or your own? and in any case what the conditions are that have been applied to the breakpoint which can be used to reduce the number of debug packets and therefore the amount of serial.

3)

I am familiar with the telnet console on the Yun but not with the way your telnet example has been configured to intercept serial. You mention your telnet shows 3 output but it display 2 lines of text. This suggests to me that there is some serial printing without a line feed. It is okay to print without line feed but the end of a line or command should then have a line feed included otherwise you will hit the 2 second timeout before the buffer is flushed to the screen.

Summary

So to recap, line feeds serial.println() or "\n" in a string cause the debugger buffer to flush to screen avoiding 2 seconds timeout. 

Too much/many Arduino serial or debugger statements on top of manual serial messages can cause packets to be lost or corrupted but normally I would expect Visual Micro to throttle the Arduino cpu and prevent too much serial data. However Visual Micro can't know wh This is the same if you do too much serial with the Arduino in a tight loop whilst also hammering the mcu with other functions. The debugger allows breakpoints to be filtered using timers (hit count) or simple/complex Conditional expressions.

This is an area that we do expect will develop further during the next few months but you can certainly get it to work quite easily armed with this knowledge (i hope).

If you understand how to create breakpoints but want to run debug without any, you can switch off the one that is automatically created in the loop by Visual Micro by deleting it then setting this Tools>options>visual micro property to False. 

Code
Select All
Micro debug Automated > loop() - Auto create breakpoint 



Note: The auto created breakpoint can be deleted and if you have added your own breakpoints to the project then Visual Micro will not auto create another one. 

At the very least I suggest you put breakpoints within "if" conditions in the code, this is the same way that the Serial.println("Hello, client") only fires when a client connects not each iteration of the loop.

I hope this helps, you should find that by removing some of the manual print() messages in the code and/or using conditional breakpoints instead the problem is solved.

Let me know how you get on. If your problem persists then please zip and email your sketch to info [at] visualmicro.com. I have an arduino ethernet board in a box unopened so this might be a time to try it out and replicate your code  Smiley

Alternatively you can hook the debugger up to a couple of digital pins instead.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint