UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Explorer
Explorer
3,949 Views
Registered: ‎11-13-2009

UART Input Parsing with getchar() or better yet getline()?

Jump to solution

All,

 

Searched a few forum articles about using getchar() for input parsing which is often defined to be XUART*_RecvByte(UART_ADDRESS) for example.

 

My question has Xilinx or somone decided to write something like getline() function for this interface?  I have a need to read a number from 0-127 which is 1, 2 or 3 characters -- getline() seems like the right thing to do, but of course the returned vector I have to do some more pasing to make it a number.  I could always make the user enter the value in hex and force it to always have 2 values for example 01 to 7F.

 

I know in the "non-embedded" world I would just use scanf()!

 

Just looking for some way to reduce my coding load this afternoon, I could knock it out if necessary but thought that anyone doing simple UART Interfaces would have a clean snippet of code to do this!

 

Thanks in advance, to anyone that replies!

TomT...

0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
5,388 Views
Registered: ‎08-02-2007

Re: UART Input Parsing with getchar() or better yet getline()?

Jump to solution

Hi,


Can you use inbyte function to recieve bytes from input terminal?

 

include <stdio.h>

main()
{
  unsigned char mychar;

  while(1)
    {
      xil_printf("Press any key...\r\n");

      mychar=inbyte();

      xil_printf("You pressed %c (%x)\r\n", mychar, mychar);
    }
}

 

--Hem

----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos
2 Replies
Explorer
Explorer
3,929 Views
Registered: ‎11-13-2009

Re: UART Input Parsing with getchar() or better yet getline()?

Jump to solution
I noticed in the ns550 library that the _Send and _Recv functions actually take a pointer to char and a length. So it seems what i need is already provided; sorry for my less than informed post -- I have been writing TCL and PERL the last several years and not c/c++ for embedded; I forget how nice a big library and machine can be. Time to get my thinking to the tiny memory footprint I really have. Thanks -- TomT...
0 Kudos
Xilinx Employee
Xilinx Employee
5,389 Views
Registered: ‎08-02-2007

Re: UART Input Parsing with getchar() or better yet getline()?

Jump to solution

Hi,


Can you use inbyte function to recieve bytes from input terminal?

 

include <stdio.h>

main()
{
  unsigned char mychar;

  while(1)
    {
      xil_printf("Press any key...\r\n");

      mychar=inbyte();

      xil_printf("You pressed %c (%x)\r\n", mychar, mychar);
    }
}

 

--Hem

----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos