Sign In

Don't have a Xilinx account yet?

  • Choose to receive important news and product information
  • Gain access to special content
  • Personalize your web experience on Xilinx.com

Create Account

Username

Password

Forgot your password?
XClose Panel
Xilinx Home
Reply
Regular Visitor
wangf
Posts: 25
Registered: ‎09-05-2008
0
Accepted Solution

how to input characters from console, why getchar() works not properly?

I try to input character from console, I use standard C function, getchar(), but it does not works properly,

first, it is especially large, second, it can get character back only after I push return key, It is not the way as in standard C.

 

What is wrong, and how can I input character? Must I use XUartLite_RecvByte() ? I'd like to use standard C functions to make the program easy.

 

 

test_id = getchar();
switch (test_id)
 {
    case '1':
     print("input 1\n");
     break;
    case '2':
     print("input 2\n");
     break;
    case '3':
     print("input 3\n");
     break;
    case 'C':
     print("input C\n");
     break;
    default:
     print("wrong enter");
     break;
   }

Expert Contributor
bassman59
Posts: 4,741
Registered: ‎02-25-2008
0

Re: how to input characters from console, why getchar() works not properly?

Your terminal program might not send the characters until it sees that you've hit ENTER.

 

-a


----------------------------------------------------------------
Yes, I do this for a living.
Regular Visitor
wangf
Posts: 25
Registered: ‎09-05-2008
0

Re: how to input characters from console, why getchar() works not properly?

my terminal program is SecureCRT, and it works well with others embedded system. Also I tried HyperTerminal, it works in same way.

so, do anyone use getchar() successfuly before?  and Must I turn to xilinx uart api?  Thanks.

 

(My tools and envirorment is Microblaze, EDK92, uartlite v1.0)

Expert Contributor
golson
Posts: 879
Registered: ‎04-07-2008
0

Re: how to input characters from console, why getchar() works not properly?

[ Edited ]

I did a search on getchar and EDK.  Other people have been using it according to search in Xilinx Forum.

 

 

http://www.xilinx.com/support/answers/29379.htm

 

and

 

http://warp.rice.edu/trac/browser/trunk/EDK/LEDs/Demo1.c?rev=56

 

http://forums.xilinx.com/xlnx/board/message?board.id=EMBEDDED&message.id=876&query.id=392564#M876

 

http://forums.xilinx.com/xlnx/board/message?board.id=EDK&message.id=4510&query.id=392610#M4510

 

 

Try increasing Heap and Stack Size a lot to see if that is the problem.

 

 

Message Edited by golson on 12-17-2008 10:17 AM
Regular Visitor
ralfcantnerbosch
Posts: 22
Registered: ‎09-05-2008

Re: how to input characters from console, why getchar() works not properly?

Hi together,

I had the same problem.

 

You can change the buffering behaviour of stdin by calling

setvbuf() before calling getchar();

 

Example :

 

setvbuf(stdin, NULL, _IONBF, 0);

for (;;)

{

  Input = getchar();

  if (Input != EOF)

    xil_printf("%c", Input);

}

 

You may omit the line with EOF, I never got that value.

I have tested the code above with XMK, it should work

in a standalone version too.

 

BTW: Hyperterminal sends each character as soon as you type it.

It does not wait for the <RETURN> key.

 

Hope this helps

  Ralf

Regular Visitor
wangf
Posts: 25
Registered: ‎09-05-2008
0

Re: how to input characters from console, why getchar() works not properly?

Your method works. But it seems that the getchar() function is huge! I decided to use xilinx's api, and deal with all the input myself.

Still, many thanks for your reply.