Access the serial port in a platform-independant way [closed]

两盒软妹~` 提交于 2020-01-22 13:10:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!