I'm writing a test program that need to access serial port. I'm doing it in Visual studio 2012 now, but I want to port to Linux later. (For using in my Pandaboard)
Can you suggest me a way to access serial port that has almost the same interface between Win & Linux?
I used to do it in Labview, but now I want to turn to C++
Thank you so much for your help!
Boost.ASIO is well-documented, well-tested, has been peer reviewed by thousands of people, and fully supports serial port communication in a cross-platform manner. Specific documentation can be found here .
That being said, it does assume a moderate skill level in modern C++, so if you're new to the language then the learning curve may be a bit steep.
There isn't much to a serial port interface...you should be able to wrap all of the implementation details underneath it.
class ISerialPort
{
public:
void open(const std::string &serialPortName) = 0;
void close() = 0;
void write(const vector<char> &data) = 0;
vector<char> read(size_t bytesToRead) = 0;
}
Although it isn't much of an "interface" as it is a common header that two different platforms would implement.
Edit: Serial Ports under Linux are accessed by opening device nodes. Such as /dev/ttyS0 (Serial Port 0). In windows you're doing the same thing, but instead of opening a device node, you're opening a file (a COM port). Such as COM1.
In linux you're diving into platform dependent issues such as opening device nodes. In Linux it'll be opening files (COM ports).
Google c++ windows/linux serial port and come back with a more specific question. You just asked about an interface;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.