How to get the input from UART console


#1

I was trying to get the input from UART console port of AR7554.

#include "legato.h"
#include <stdio.h>

#define     DESTINATION_LEN_MAX     50

COMPONENT_INIT
{
    LE_INFO("Hello, world12345.");



    char Destination[DESTINATION_LEN_MAX];
    fprintf(stderr, "Set Destination Number or command: stop (hang-up), answer (pick-up) or exit to exit of application\n");

    fgets ((char*)Destination, DESTINATION_LEN_MAX, stdin);

    Destination[strlen(Destination)-1]='\0';
    fprintf(stderr, "Destination= %s !!!\n",Destination);



}

However, the console just shows the following:
root@swi-mdm9x15:/opt/legato/apps/commandLine# Set Destination Number or command: stop (hang-up), answer (pick-up) or exit to exit of applicatn
Destination= !!!

And it is not waiting for the input to type “stop” or “answer”.
Any idea?


#2

Try to run your legato app using execInApp:

This command will run the executable “commandLine” of a legato app called “commandLine”.

Using execInApp, the executed process will inherit the environment variables and file descriptors of the terminal.

Jay


#3

I think you misunderstand my question.
My code has nothing related to application commandLine.
I just want to know why fgets() is not getting input from UART console.
Thx.


#4

Hi,

My answer was not for the “commandLine” sample code (I have just reused this name because it was displayed in your initial post: “/opt/legato/apps/commandLine”).

In order to capture the terminal (console) using fgets, you need to run your Legato app using execInApp.

I succeed to run your application and to capture the console input by using execInApp:

  1. I have created a Legato component called “readStdinComponent”

  2. This component includes a source file called “readStdin.c”:

[code]#include “legato.h”
#include <stdio.h>

#define DESTINATION_LEN_MAX 50

COMPONENT_INIT
{
LE_INFO(“Hello, world12345.”);

char Destination[DESTINATION_LEN_MAX];
fprintf(stderr, "Set Destination Number or command: stop (hang-up), answer (pick-up) or exit to exit of application\n");

fgets ((char*)Destination, DESTINATION_LEN_MAX, stdin);

Destination[strlen(Destination)-1]='\0';
fprintf(stderr, "Destination= %s !!!\n",Destination);

}
[/code]
3) The “Component.cdef” content of this component is:

sources: { readStdin.c }
4) Then I have created a Legato application called “readStdin” which is using the component “readStdinComponent” in order to create an executable called “readStdinExec”.
The content of the application definition file (“readStdin.adef”) is:

executables: { readStdinExec = ( readStdinComponent ) }
5) After building/installing the “readStdin” app on the target, I can run it

[code]root@swi-mdm9x15:~# app status

[stopped] readStdin

root@swi-mdm9x15:~# app start readStdin
Starting app ‘readStdin’…
DONE

root@swi-mdm9x15:~# execInApp readStdin readStdinExec
Set Destination Number or command: stop (hang-up), answer (pick-up) or exit to exit of application
answer
Destination= answer !!![/code]
As you can see, the “answer” string has been successfully captured from the console.

Jay


#5

Hi Jay,

Thx for your help!
It works fine for me now!

thx!