以独立于平台的方式访问串口 [英] Access the serial port in a platform-independant way

查看:33
本文介绍了以独立于平台的方式访问串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是创建一个程序,通过 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.

这篇关于以独立于平台的方式访问串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆