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
Hot Topic (More than 8 Replies) Broken installation? (Read 5584 times)
chris52
Junior Member
**
Offline


Posts: 47
Joined: Jan 9th, 2017
Broken installation?
Feb 25th, 2017 at 11:34am
Print Post  
I have  a sketch which is working fine with the Arduino IDE but not with VisualMicro. 
I was having problems with serial.read() so I created  a simple sketch just to test that. File attached.
In VisualMicro, the 'readData()' function never accepts an input. Furthermore, if I add some breakpoints to see why, strange things are happening. I have a breakpoint on line 13, 'if (Serial.available() > 0)' (condition index<5), and another on line 24, 'done=true' (action log message done={done}).
With text in the 'send' box, if I don't press the 'send' button the output logs continuous messages saying 'done=0': but the code shouldn't be getting there (yet). If I put curly brackets around 'done=true' then the breakpoint isn't hit (as expected).
But the first breakpoint is odder. It is only hit after I press 'send'. It is only hit once, but I think it should be hit five times (if the input string is long enough).
And (the original reason for the post!) the function never exits. It does when running with the Arduino IDE.
(p.s. why can't I upload .ino files??)
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Broken installation?
Reply #1 - Feb 25th, 2017 at 12:51pm
Print Post  
Hi,

Please switch the tool bar from Debug to Release and then upload.

You should then see visual micro working the same as the arduino ide.

Let's keep it simple and prove if that is the case or not before looking at debug which arduino does not support.

Thanks


note: To upload files it is best to zip them first or email them to info[at]visualmicro.com along with a link to this post.
  
Back to top
IP Logged
 
chris52
Junior Member
**
Offline


Posts: 47
Joined: Jan 9th, 2017
Re: Broken installation?
Reply #2 - Feb 25th, 2017 at 1:54pm
Print Post  
OK, good idea, but tried in release mode and the function still never exits when I enter some text.
May or may not be related, but the other day I also  installed VisualMicro for AtmelStudio 7. It's uninstalled again now, though. I know AtmelStudio is 'powered by' VS2015 so maybe there's some overlap here?
Happy to re-install VisualMicro for VS2015, to see if it solves the problem, but thought you might want to try other things first.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Broken installation?
Reply #3 - Feb 25th, 2017 at 2:06pm
Print Post  
Hi,

I don't think this is related to a visual micro installation issue. 

I am unclear from your report of a few things.

1)
In release mode can you compile and upload?

2)
With Release mode enabled, it would be helpful if you could restate your report of the issue. Please also state the comparison/difference between arduino ide and visual micro with exact same code.


Thanks
  
Back to top
IP Logged
 
chris52
Junior Member
**
Offline


Posts: 47
Joined: Jan 9th, 2017
Re: Broken installation?
Reply #4 - Feb 25th, 2017 at 2:49pm
Print Post  
OK, I'll detail this as accurately as I can:

Take the file serialread2.ino and load it into Arduino 1.8.0. 
Connect Uno board.
Compile and run it and wait for prompt 'input'. Enter 4 or 5 characters to the input box then return (or hit send button). Output shows the characters just entered (as expected).

Now load same file into VisualMicro, release mode. Compile and run it and wait for prompt 'input'. Enter 4 or 5 characters to the input box then return (or hit send button). Nothing happens. (adding an additional serial.print line to loop() also shows that the program never exited setup()).

Repeat whole exercise with MegaADK. Same results.

There are a couple of other projects in the 'Solution' (including one where I first noticed the problem, where I was trying to use the Serial class inside an interrupt), but the simple 'serialraed2.ino' is the active project for these tests (I haven't found a way of creating a new empty solution).

(edit) Just tried an earlier version of serialRead that I wrote , which uses 'Serial.readBytesUntil('\n', buffer, maxlen)' rather than reading individual characters. That runs as expected.
« Last Edit: Feb 25th, 2017 at 2:54pm by chris52 »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Broken installation?
Reply #5 - Feb 25th, 2017 at 3:43pm
Print Post  
I think the problem is you have not specified a line terminator for serial sent from pc to mcu.

Your code reads looking for line feed as terminator.

If you right click and GoTo definition on the arduino readBytesUntil() method you will see it uses a time out for the read of 1 second. See code extract below.

Both your code and arduino read one byte at a time so maybe the ide > serial monitor > line terminator isn't sending the \n your code expects? 

What is No 8 set to in the Serial Monitor?



arduino stream.cpp

Code
Select All

int Stream::timedRead()
{
  int c;
  _startMillis = millis();
  do {
    c = read();
    if (c >= 0) return c;
  } while(millis() - _startMillis < _timeout);
  return -1;     // -1 indicates timeout
} 




arduino stream.h defines _timeout

Code
Select All
class Stream : public Print
{
  protected:
    unsigned long _timeout;      // number of milliseconds to wait for the next char before aborting timed read
    unsigned long _startMillis;  // used for timeout measurement
    int timedRead();    // private method to read stream with timeout
    int timedPeek();    // private method to peek stream with timeout
    int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout

  public:
    virtual int available() = 0;
    virtual int read() = 0;
    virtual int peek() = 0;
    virtual void flush() = 0;

    Stream() {_timeout=1000;}
 

« Last Edit: Feb 25th, 2017 at 3:52pm by Tim@Visual Micro »  
Back to top
IP Logged
 
chris52
Junior Member
**
Offline


Posts: 47
Joined: Jan 9th, 2017
Re: Broken installation?
Reply #6 - Feb 25th, 2017 at 4:23pm
Print Post  
OK, thanks. The lack of CR or LF in the 'line endings' box is what caused the difference from the Arduino IDE. Clearly that's  important, so could I suggest two improvements:
a) move it nearer the left, I didn't even see the box until I made it very wide;
b) default it to CR/LF rather than blank?

Now, moving back to the debug (which I still need to use for my 'real' project), it still doesn't seem correct. I put a breakpoint on the line 'if (Serial.avaialble() > 0)' but this isn't hit until after I send in some data. Surely it should be hit hundreds of times while waiting for me to enter data? 
If I put a condition to stop on hit count=2, for example, again it doesn't hit until I press 'send'. Then I pres 'continue', then 'send' again, and my input data is prefaced with a '?' that I didn't send (which is where I started with my 'real' project.)

Dare I say that if the breakpoints had worked as expected, I would have been able to solve the CR/LF issue without help?  Wink

(edit) just tried in AtmelStudio and have same problem.
« Last Edit: Feb 25th, 2017 at 4:37pm by chris52 »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Broken installation?
Reply #7 - Feb 25th, 2017 at 4:54pm
Print Post  
Thanks, you are right there are so many options these days that it needs to be clearer. It defaults to "No Line Endings" because that is what the Arduino Ide does (or used to do). I will test sometime to see if they have changed the default.

For debug you need to switch on "vMicro>Debugger>Trace Only" which will give you non-stopping read only trace points.

The docs try to explain that arduino does not have a debugger so Visual Micro provides a simple debugger with Serial. This message and the importance of it can be lost in the depths of the docs so it will help.

For debug to be able to break/pause/continue (and update variables) during run time visual micro needs exclusive use of the serial.read and serial.available() systems. 

When sharing the port with the debugger, your code can use serial.println etc but can not read.

You can override the serial port that visual micro uses for debugging. 

If you have more than one Serial port you can assign a different port to the debugger... For example "vMicro>Debugger>Remote Port" = Serial2 and "vMicro>Debugger>Local Port" = COMx

If you do not have a different hardware port but have one or two available digital pins you can set the debugger to use SoftwareSerial. One pin for Trace only and two pins for trace/break

Debugging-With-Different-Ports.html

In summary, for a clean debug experience that keeps serial usage separate between your own code and the debugger you will need something like an FTDI adapter or cable so that you have a second usb connection to the board via pins on the board.

  
Back to top
IP Logged
 
chris52
Junior Member
**
Offline


Posts: 47
Joined: Jan 9th, 2017
Re: Broken installation?
Reply #8 - Feb 25th, 2017 at 5:30pm
Print Post  
Ok, thanks, I understand the conflict with Serial. I can deal with that in some way.
But that doesn't explain the breakpoint I mentioned misbehaving. I've since discovered why. It's actually setting a breakpoint on the line after the one indicated.
If I do this:
Code
Select All
      test = 1;
      if (Serial.available() > 0)
      { 


and put a breakpoint on the line 'test=1', the value of test is already 1 when the breakpoint is reached.
To demo another way:
Code
Select All
void setup() {
  // put your setup code here, to run once:
  int count = 0;
  int copycount = 0;
  ++count;
  ++count;
  ++count;
  ++count;
  ++count;
  copycount = count;
} 


...breakpoints showing the value of 'count' on successive lines are always thinking ahead!
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Broken installation?
Reply #9 - Feb 25th, 2017 at 6:11pm
Print Post  
Thanks for the update. Yes that's right... 

Because the serial debug code has to be injected into the temp code copy during build it was easier to insert after the current line. if that a single line "if" it's handled and turned into mult-line. 

It tries it's best to insert code but the simpler the code line the easier. Unlike normal debugger breakpoints on blank lines work and can sometimes be useful but it's certainly different Smiley

The Debugging Your Sketch topic  in the documentation index is a useful doc. See the section called "The Exact Location of a Breakpoint" 

« Last Edit: Feb 25th, 2017 at 6:12pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint