Terminal Problem

09 Feb 2010

Hi Everyone,

I have a odd problem on a Terminal program I've written. The program waits for enter to be pressed then counts down from 10 to 0. The odd bit is that when teh user next hits a key, that key is displayed on screen.

The code is this...

#include "mbed.h"
#include "Terminal.h"

Terminal term(USBTX, USBRX);                         //Info transmitted to hypertermal via USB
int Flag=0, Count=10;

void Countdown(void){
    if(Flag==1){
        Count--;

    if(Count<=0){
        Flag=0;        //Turn off Flag when Count reaches 0. 
    }
    term.locate(18,6);
    term.printf("%d ",Count);
    }
}
    
int main() {
    Ticker Timer_100ms;
    Timer_100ms.attach(&Countdown, 0.1);             //Call Profile every 0.1 seconds

    term.cls();                                                //Clear the screen
    term.locate(18,5);
    term.printf("Count: %d ",Count);   
    
    while(1){                 
        int Key=term.getc();                      //Get the key pressed
        if(Key==0x0D){                             //See if it was ENTER
            Flag=1;
        }   
    }      
}

Does anyone know why this occurs?

Thanks, Martin

09 Feb 2010

Hi Martin

It might be because you have local echo enabled in hyperterminal. Have a look here to adjust the settings (assuming we are talking about Windows).

Regards
Daniel

 

09 Feb 2010

Hi Daniel,

Thanks for your help but it's not that, the box was unckecked (I did try checking the box but then I got 2 unwanted characters instead of 1!)

09 Feb 2010

Hi Martin

Then is it possible that the Terminal class has its own version of local echo? Can you post the source for that class?

Regards
Daniel

09 Feb 2010

Hi Daniel,

I have published the program on my notebook page (I thinik here http://mbed.org/users/ms523/programs/5yqpv). The Terminal header and library was based on the one Simon Ford published a few weeks ago.

Hope this helps

Martin

09 Feb 2010

Hi Martin, it's nothing to do with Terminal (which just inherits from Serial). I think it is a bug in the Serial class; I've posted a report here. Perhaps one of the mbed team can suggest a workaround (because not using printf in a timer handler might be unhelpful).

Regards
Daniel

10 Feb 2010
Daniel Peter wrote:

Hi Martin, it's nothing to do with Terminal (which just inherits from Serial). I think it is a bug in the Serial class; I've posted a report here. Perhaps one of the mbed team can suggest a workaround (because not using printf in a timer handler might be unhelpful).

Regards
Daniel

Hi Daniel,

Thanks for that. I think mabye I will rewrite the code to set a flag in the ticker and handle the printf elsewhere, but it would be interesting to know what is causing it.

Regards

Martin