ltib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ltib] serial interface read problem


From: Stuart Hughes
Subject: Re: [Ltib] serial interface read problem
Date: Mon, 29 Oct 2007 11:12:02 +0000

Hi Mehrdad,

I'm not sure why this is not working for you, do you have anything else
running that may be swallowing the characters from this port?

As far as stty goes, you can do a similar thing in C using
tcgetattr/tcsetattr (see the man pages).  For example I use the
following snippet to turn off buffered line mode for stdin (fd = 0):

    static struct termios tty, otty;
    char c[2]   = { 0, 0 };

    tcgetattr(0, &tty);
    otty = tty;
    tty.c_lflag &= ~ICANON;
    tcsetattr(0, TCSANOW, &tty);
    fcntl(0, F_SETFL, O_NONBLOCK);

    if( (read(0, c, 1) == 1 ) ) {
        if( isdigit(c[0]) ) {
           # do something....

Regards, Stuart

On Mon, 2007-10-29 at 12:34 +1100, Mehrdad Salami wrote:
> Hi Everyone,
> 
> I am trying to access a serial port in raw format. I am using the ltib 
> linux distribution for freescale coldfire chips. The port is defined as 
> UART but I set the port to work in raw format by running
> 
>  >stty raw -F /dev/tts/3
> 
> However I can't read from the port correctly.
> 
> I open the port in user space like
> 
> fd=open("/dev/tts/3", O_RDWR | O_NOCTTY | O_NODELAY | O_NONBLOCK);
> 
> and write into the port as
> 
> write(fd,buf_out,len);
> 
> which works correctly.
> However I can't read from the port using
> 
> read(fd,buf_in,len);
> 
> The port receive all characters and I can write the characters from 
> lower level functions in kernel space on console. However the read 
> function return -1 which is obviously no success. I tried to delay read 
> but still can't read characters.
> 
> I am not sure if the open flags are not correct, or read and write 
> procedures are not correct.
> 
> Another question : Is there any way to open the port in raw format 
> without running the stty command.
> 
> Thanks
> 
> Mehrdad
> 
> 
> _______________________________________________
> LTIB home page: http://bitshrine.org
> 
> Ltib mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/ltib





reply via email to

[Prev in Thread] Current Thread [Next in Thread]