以独立于平台的方式访问串口

2022-01-18 00:00:00 c serial-port c++ platform-independent

我的任务是创建一个程序,通过 RS-232 从桌面站控制设备.目前我正处于计划阶段,需要一些一般帮助来选择语言和解决问题的整体方法.

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.

该程序应在 32 位和 64 位 Intel 处理器上的 Linux(主要是 Ubuntu)和 Windows(XP、7)下构建和运行.工作站可能有物理 COM 端口或(更有可能)USB-RS232 转换器.

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.

目前我最好的选择是使用 CMake 有条件地构建的 C++ 程序.是否有某种方式,使用某种语言来配置和访问串行端口(包括通过 USB 模拟),这是平台无关的?如果不是,什么是解决这个问题的好方法?

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?

到目前为止的建议:
* C++ 与 Boost
* python 与 pySerial

推荐答案

使用Boost Asio(使用C++)!

Use Boost Asio (using C++)!

(http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio.html)

保证独立于平台:http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/using.html

尽管它比任何其他库都好得多的是它支持异步通信.我认为该功能使其在您的设备控制软件中非常有用.并且不要忘记它是 Boost 的一部分,其库非常可靠.

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.

我在我的短信程序中使用了它(使用通过串行/COM 端口发送的 AT 命令).

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.

相关文章