cyg_io_read

View: New views
1 Messages — Rating Filter:   Alert me  

cyg_io_read

by grahamlab :: Rate this Message:

| View Threaded | Show Only this Message

Hello all
I am having trouble understanding the operation of the cyg_io_read operation.
I have a simple programto read the /dev/ser1 device on my stm3120e dev board.
If i set blocking on read then my cyg_io_read call only returns when the specified number of bytes has been received -

char msg[10]
cyg_uint32 msglen=10;
res = cyg_io_read(handle,msg,&msglen); // returns when 10 bytes have been received.

However, I want to read bytes as they arrive. With this in mind I set the device to operate in non blocking mode -
block = 0;
len = sizeof(cyg_uint32);
cyg_io_set_config(handle,CYG_IO_SET_CONFIG_SERIAL_READ_BLOCKING,&block,&len);

I set up my code to ignore EAGAIN errors on the read -
    while(1)
    {
    char msg[10];
    cyg_uint32 msglen=10;

    res = cyg_io_read(handle,msg,&msglen);
    if (res != -EAGAIN)
    {
    diag_printf ("read %d %d\n",res,msglen);
    for (cyg_uint32 x = 0; x < msglen; ++x)
    {
    diag_printf("%c",msg[x]);
    }
    diag_printf("\n\n");
    }

With this in place I expected to receive all bytes sent by the sending program , BUT NO
I only receive the first 2 or three. If I send single characters I get these but if I send anything more I dont get what I sent.

I would be grateful if someone could explain this behavior.

Thanks Graham