- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
how to input characters from console, why getchar() works not properly?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-17-2008 09:21 AM
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;
}
Solved! Go to Solution.
Re: how to input characters from console, why getchar() works not properly?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-17-2008 09:24 AM
Your terminal program might not send the characters until it sees that you've hit ENTER.
-a
----------------------------------------------------------------
Yes, I do this for a living.
Re: how to input characters from console, why getchar() works not properly?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-17-2008 09:49 AM
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)
Re: how to input characters from console, why getchar() works not properly?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-17-2008 10:09 AM - edited 12-17-2008 10:17 AM
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/D
http://forums.xilinx.com/xlnx/board/message?board.
http://forums.xilinx.com/xlnx/board/message?board.
Try increasing Heap and Stack Size a lot to see if that is the problem.
Re: how to input characters from console, why getchar() works not properly?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-18-2008 08:24 AM
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
Re: how to input characters from console, why getchar() works not properly?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-18-2008 09:30 AM
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.











