Reputation: 103
I am attempting to use C to echo characters from a pic32 processor to a terminal emulator via a serial port. The user would be prompted to enter a string and all that happens is that the characters would appear on the screen as the user typed. This is only to set up an initial program that could later be used for real time menu selections from the user. Example below:
main()
{
// 1. init the console serial port
initU2();
// 2. text prompt
clrscr();
home();
fputs("Enter some text: ", stdout);
puts(stdout);
// 3. main loop
while (1)
{
// 3.1 read a full line of text
getsn(stdout, sizeof(stdout));
// 3.2 send a string to the serial port
puts(stdout);
} // main loop
} // main
Here is what I get at the command line(regardless of input from the user or not):
Enter some text: ÿÿÿÿ
I can simply echo characters to the terminal program display however if I need to have the user type characters in, the C program doesn't seem to respond. Any help would be appreciated!
Upvotes: 1
Views: 614
Reputation: 87396
You wrote:
fputs("Enter some text: ", stdout);
puts(stdout);
I think your call to puts is invalid. In normal C libraries puts
expects to be passed a pointer to a string, but you are passing stdout
to it, which is NOT a string. As a result, you are seeing some junk characters get transmitted on the serial port.
Try either removing the puts
lines or changing your code to this:
puts("Enter some text: ");
Upvotes: 3