simple serial program - Linux

This is a discussion on simple serial program - Linux ; Hi, everyone I wrote a simple serial program to test tty routines. It just writes a simple text to serial port "/dev/ttyS1". The open routine succeeded, which finally called serial8250_startup() in kernel, but write routine did not call the kernel ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: simple serial program

  1. simple serial program

    Hi, everyone

    I wrote a simple serial program to test tty routines.
    It just writes a simple text to serial port "/dev/ttyS1".

    The open routine succeeded, which finally called serial8250_startup() in
    kernel, but write routine did not call the kernel routine "tty_write()"
    for /dev/ttyS1.So, it did not call uart_write(), either.

    echo test > /dev/ttyS1 is OK.
    tty_write() and uart_write() are all normally called.

    Please tell what is wrong with my simple test routine.
    The routine was like this:


    #include
    #include
    #include
    #include
    #include

    int main() {
    FILE *fp;
    fp = fopen("/dev/ttyS1", "rw");
    fprintf(fp, "This is test\n");
    fclose(fp);
    }

    Thanks in advance.

    Regards,
    J.H.Kim

  2. Re: simple serial program

    On a sunny day (Mon, 10 Nov 2008 14:02:59 +0900) it happened "J.H.Kim"
    wrote in :

    >Hi, everyone
    >
    >I wrote a simple serial program to test tty routines.
    >It just writes a simple text to serial port "/dev/ttyS1".
    >
    >The open routine succeeded, which finally called serial8250_startup() in
    >kernel, but write routine did not call the kernel routine "tty_write()"
    >for /dev/ttyS1.So, it did not call uart_write(), either.
    >
    >echo test > /dev/ttyS1 is OK.
    >tty_write() and uart_write() are all normally called.
    >
    >Please tell what is wrong with my simple test routine.
    >The routine was like this:
    >
    >
    >#include
    >#include
    >#include
    >#include
    >#include
    >
    >int main() {
    > FILE *fp;
    > fp = fopen("/dev/ttyS1", "rw");
    > fprintf(fp, "This is test\n");
    > fclose(fp);
    >}
    >
    >Thanks in advance.
    >
    >Regards,
    >J.H.Kim


    Just about everything is wrong.
    At first you should check the return value from fopen().
    Here is a simple serial program that works, and actually initialises the serial device,
    simpler then this is not easy:
    http://panteltje.com/panteltje/pic/io_pic/ptlrc-0.2.tgz



  3. Re: simple serial program

    Jan Panteltje ? ?:
    > On a sunny day (Mon, 10 Nov 2008 14:02:59 +0900) it happened "J.H.Kim"
    > wrote in :
    >
    >> Hi, everyone
    >>
    >> I wrote a simple serial program to test tty routines.
    >> It just writes a simple text to serial port "/dev/ttyS1".
    >>
    >> The open routine succeeded, which finally called serial8250_startup() in
    >> kernel, but write routine did not call the kernel routine "tty_write()"
    >> for /dev/ttyS1.So, it did not call uart_write(), either.
    >>
    >> echo test > /dev/ttyS1 is OK.
    >> tty_write() and uart_write() are all normally called.
    >>
    >> Please tell what is wrong with my simple test routine.
    >> The routine was like this:
    >>
    >>
    >> #include
    >> #include
    >> #include
    >> #include
    >> #include
    >>
    >> int main() {
    >> FILE *fp;
    >> fp = fopen("/dev/ttyS1", "rw");
    >> fprintf(fp, "This is test\n");
    >> fclose(fp);
    >> }
    >>
    >> Thanks in advance.
    >>
    >> Regards,
    >> J.H.Kim

    >
    > Just about everything is wrong.
    > At first you should check the return value from fopen().
    > Here is a simple serial program that works, and actually initialises the serial device,
    > simpler then this is not easy:
    > http://panteltje.com/panteltje/pic/io_pic/ptlrc-0.2.tgz
    >
    >


    The option for fopen() was wrong.
    When I put the option "w+" rather than "rw", it works.
    Thank you.

    Regards,
    J.H.Kim

+ Reply to Thread