windows 串口通讯教程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5767226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Serial port communication tutorial
提问by MichaelGabrielR
I'm trying to write a C++ program that reads a stream of data from a measurement device through an RS-232 serial port and translates it into a readable format. I never coded serial port communication before.
我正在尝试编写一个 C++ 程序,该程序通过 RS-232 串行端口从测量设备读取数据流并将其转换为可读格式。我以前从未编码过串口通信。
Question:Does anyone have a useful, easy to understand linkor a tutorialthat might help?
问题:有没有人有一个有用的、易于理解的链接或可能有帮助的教程?
Constraints:
约束:
Programming language: C++
OS: Windows (XP) 32 bit
Compilers: MinGW (for prototyping), Eclipse (final version)
编程语言:C++
操作系统:Windows (XP) 32 位
编译器:MinGW(用于原型设计)、Eclipse(最终版)
This means:
这意味着:
NOVisual Studio
NOBorland,
NOCode Blocks
NOBlodshed DevC++
没有视觉工作室
没有Borland,
没有代码块
没有血腥的 DevC++
回答by Neil
The standard Win32 APIs work with handles to communication ports. (In fact the overlapped APIs even worked on Windows 9x/ME!)
标准 Win32 API 使用通信端口句柄。(事实上,重叠的 API 甚至可以在 Windows 9x/ME 上运行!)
回答by rlduffy
If you have access to the boost libraries, there are facilities for doing serial port I/O in boost::asio. The documentation can be a bit cumbersome, but when you get down to brass tacks it's pretty straightforward.
如果您可以访问 boost 库,则在 boost::asio 中有用于执行串行端口 I/O 的工具。文档可能有点麻烦,但是当您深入了解黄铜钉时,它非常简单。