用于嵌入式系统lpcxpresso的C中的Modbus实现 [英] Modbus implementation in C for embedded system lpcxpresso

查看:184
本文介绍了用于嵌入式系统lpcxpresso的C中的Modbus实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是modbus的新手,我必须编写一个lpcxpresso基板作为主机,使用RS485 Modbus协议从电力计收集读数。

I am new to modbus and I have to program a lpcxpresso baseboard as a master to collect readings from a powermeter using RS485 Modbus protocol.

我熟悉通过从modbus.org读取规范,协议(关于PDU ADU帧,功能代码,主从)。
但是,我在C中编写代码时遇到困难。

I am familiar with the protocol (about the PDU ADU frame, function codes, master-slave) through reading of specifications from modbus.org. However I have difficulties in the implementation when writing the code in C.

所以我的问题是:


  1. 当我开始连接时,是否必须打开连接,设置波特率等?

  2. 我正在考虑将帧发送为字节[]。它是否正确?或者有什么其他方法吗?

  3. 数据发送必须是十六进制,还是二进制或整数?

  4. CRC生成和检查。

  1. Do I have to open connection, set the baud rate, etc when I am starting the connection?
  2. I am thinking to send the frame as byte[]. Is this correct? or are there any other ways to do it?
  3. Does the data send have to be in hexadecimal, or binary or integer?
  4. CRC generation and checking.

我将非常感谢所有的帮助和帮助:)对不起,如果问题不是非常具体或太基础


I will really appreciate all kind of help and assistance :) Sorry if the questions are not very specific or too basic

推荐答案

第1步:忘记电能表和modbus现在。最重要的是要让硬件工作。 RS485只是串口。阅读有关如何初始化硬件串行端口的手册,并将单字节发送到PC并返回。然后将数百个字节发送到PC并返回。

Step 1: Forget about energy meter and modbus for now. Most important thing is to get hardware working. RS485 is simply a serial port. Read manual on how to initialize serial port on your hardware, and send single byte to your PC and back. Then send hundreds of bytes to PC and back.

Setp 2:获取硬件上的计时器。 Modbus协议对时序有一些要求,所以你也需要它。

Setp 2: Get timer on your hardware working also. Modbus protocol has some requirements on timing so you'll need it too.

步骤3:获取modbus规范。它将解释协议格式和校验和。使用modbus库或编写自己的。确保您可以在PC上工作,然后再进入电能表。

Step 3: Get modbus specification. It will explain protocol format and checksums. Use modbus library or write your own. Make sure you can make it work with PC, before you move on to the energy meter.

步骤4:如果您有问题,请在SO上询问具体问题。

Step 4: If you have a problem, ask specific question about it on SO.

这篇关于用于嵌入式系统lpcxpresso的C中的Modbus实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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