Reputation: 99
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!
Upvotes: 0
Views: 2795
Reputation: 62985
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.
Upvotes: 3
Reputation: 688
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;)
Upvotes: 2