问题
I have a task to create a program, that control a device over RS-232 from a desktop station. Currently I am at the planning stage and need some general help selecting a language and overall approach to the problem.
The program should build and run under Linux (mostly Ubuntu) and Windows (XP, 7) on 32 and 64 bit Intel processors. The workstation might have physical COM ports or (more probably) USB-RS232 converter.
Currently my best bet is a C++ program, built with CMake conditionally. Is there some way, using some language, to configure and access serial ports (including emulated through a USB), that is platform-independent? If no, what would be a good approach to this problem?
Suggestions up to now:
* C++ with Boost
* python with pySerial
回答1:
Use Boost Asio (using C++)!
(http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio.html)
It's guaranteed to be platform independent: http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/using.html
Though what makes it much better than any other libraries is that it supports asynchronous communications. I think that feature makes it very useful in your device-control software. And don't forget that it is part of Boost whose libraries are very reliable.
I've used it on my sms messaging program (using AT commands sent through serial/COM ports).
Hope this solves your problem as it has solved mine.
回答2:
You can have a look on the Java Communication Api
For C / C++, you can use /dev/ttySx device under linux, MacOS and Cygwin (for Windows). If the USB-RS232 converter is based on a FTDI chip, you can have a look on the libFTDI. Finally, you can eventually check RS-232 for Linux and Windows
来源:https://stackoverflow.com/questions/12088071/access-the-serial-port-in-a-platform-independant-way