Reading the Linux Serial Port in C++ - Help

This is a discussion on Reading the Linux Serial Port in C++ - Help ; I posted this on comp.lang.c++ and was told to go to a group on my OS (Linux) and ask it, so I'm asking it here. Thanks for any help! I've done a fair amount of Googling for information on reading ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Reading the Linux Serial Port in C++

  1. Reading the Linux Serial Port in C++

    I posted this on comp.lang.c++ and was told to go to a group on my OS
    (Linux) and ask it, so I'm asking it here. Thanks for any help!

    I've done a fair amount of Googling for information on reading the serial
    port in C++ (and in Linux). *Unfortunately, out of every 4 hits, 1 seems to
    be an unanswered question, 1 is someone saying, "That's easy, there's a lot
    out there, Google it,", 1 is a discussion on it without examples and the
    other is who knows what.

    I did find some info on it and have been experimenting. *The one example
    that I liked the best in terms of explanations and readability for a new
    C++ programmer (coming over from Java and Perl) used this to open the
    serial port (yes, with the .h on each include, I know it's older):

    #include
    #include
    #include
    #include
    #include
    int fd1;
    fd1=open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);

    I understand the serial port will be binary and may be different from other
    files, but I don't understand why this won't work just as well:

    #include
    #include

    ofstream myfile;
    myfile.open("/dev/ttyS0", ios:ut | ios::binary);

    Would that work as well or is there a reason for handling it the first way?
    Basically, after I catch up on everything, one program will be reading the
    serial port and reporting the output and another will be sending data to
    the port. *(It's possible, if I can ever find a good thread tutorial for
    C++ that instead of different programs, they'll be different threads.)

    Thanks for any help on the significance and differences of these two
    methods!

    Hal

  2. Re: Reading the Linux Serial Port in C++

    On Tue, 11 Mar 2008 18:48:00 GMT, Hal Vaughan wrote:

    >I posted this on comp.lang.c++ and was told to go to a group on my OS
    >(Linux) and ask it, so I'm asking it here. Thanks for any help!


    Since you're presumably doing this in Linux, why not just get the
    kernel source and look at the appropriate functions? See how it's
    done in C, and you'll probably know how to do it in C++. HTH, HAND.

    --
    Joe Zeff
    The Guy With the Sideburns
    This has been a D'oh! moment.
    http://www.lasfs.info http://www.zeff.us

  3. Re: Reading the Linux Serial Port in C++

    Joe Zeff wrote:

    > On Tue, 11 Mar 2008 18:48:00 GMT, Hal Vaughan wrote:
    >
    >>I posted this on comp.lang.c++ and was told to go to a group on my OS
    >>(Linux) and ask it, so I'm asking it here. Thanks for any help!

    >
    > Since you're presumably doing this in Linux, why not just get the
    > kernel source and look at the appropriate functions? See how it's
    > done in C, and you'll probably know how to do it in C++. HTH, HAND.


    I hadn't though about that. Thanks!

    Hal


+ Reply to Thread