How to read/write to a serial port without a while(1)-loop?


#1

I use Legato 16.10.3 and my mangOH Green board has got an WP8548 module with firmware version SWI9X15Y_07.12.09.00.
The Legato docs indicate that a COMPONENT_INIT should always return.

So, how can I read and write from a serial port without using an endless loop?
Is there a Serial API with a callback function to handle received characters on a serial port?
In fact, is there something similar to an ‘le_data_AddConnectionStateHandler’ for my DataConnection or an ‘IOT0_GPIO1_AddChangeEventHandler’ for my GPIO state changes?

My serial port is connected to ttyHSL1, and in my testapplication the read an write calls work fine. But, I’m not able to return from COMPONENT_INIT, so, my application doesn’t get fully initialized.

COMPONENT_INIT
{
char uart2ReadBuffer[10] = “”;
int uart2ReadBufferLength = 0;
char uart2WriteBuffer[50] = “Write from UART2 : 123456789\r\n”;
int uart2;

LE_INFO("Hello, world.");

uart2 = open ("/dev/ttyHSL1", O_RDWR | O_NOCTTY | O_NDELAY );
le_tty_SetRaw(uart2fd, 0, 0);	//ECHO is OFF
le_tty_SetFraming(uart2, 'N', 8, 1);
write(uart2, uart2WriteBuffer, strlen(uart2WriteBuffer));

while(1)
{
    uart2ReadBufferLength = read(uart2, uart2ReadBuffer, 10 );

    //check if we received a string on UART2
    if (uart2ReadBufferLength > 0)
    {
        LE_INFO("Received from UART2 : %s \n.", uart2ReadBuffer);
    }
}

}


#2

Hi,
Please check le_fdMonitor