简体   繁体   English

如何使用Modbus协议从COM串口读取寄存器映射? (C ++)

[英]How to Read Register Map From COM serial port using Modbus Protocol? (c++)

I have a hardware device that connects to the computer's COM port using a usb to RS232 connector. 我有一个硬件设备,使用USB转RS232连接器连接到计算机的COM端口。 It uses the Modbus RTU protocol. 它使用Modbus RTU协议。 I'm trying to read the registers using C++ on Visual Studio, do I need an external library for this (if so where could I find one)? 我试图在Visual Studio上使用C ++读取寄存器,我是否需要一个外部库(如果是这样我在哪里可以找到)? Or are there default libraries in C++ that can do this? 或者C ++中是否有默认库可以执行此操作?

I've googled Modbus libraries for C++ but only found results for specific hardware like Arduino. 我用谷歌搜索了用于C ++的Modbus库,但只找到了像Arduino这样的特定硬件的结果。

To write your own software that communicates with Modbus devices you need a library. 要编写与Modbus设备通信的自己的软件,您需要一个库。

Libmodbus works very well. Libmodbus运行良好。 It's written in C but you can use it in C++. 它是用C语言编写的,但您可以在C ++中使用它。 There is a Visual Studio project file included in the repo. 存储库中包含一个Visual Studio项目文件。

Otherwise, if you are familiar with Qt, you can take a look at this master example . 否则,如果您熟悉Qt,可以查看此主示例

In case you don't want to start from scratch you can take a look at QModMaster , which uses libmodbus and Qt. 如果你不想从头开始,你可以看看QModMaster ,它采用libmodbus和Qt。 If you want to start testing your device right away before you get busy coding you can download the binary files for Windows or compile the project with Qt Studio if you're on Linux. 如果您想在繁忙的编码之前立即开始测试您的设备,您可以下载Windows的二进制文件或使用Qt Studio编译项目(如果您使用的是Linux)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM