H
Hal Vaughan
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 <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
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 <iostream>
#include <fstream>
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
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 <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
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 <iostream>
#include <fstream>
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