如何在Modbus网络中获取通信参数 [英] How to fetch the communication parameters in a modbus network

查看:142
本文介绍了如何在Modbus网络中获取通信参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个程序来获取通信参数,例如波特率,停止位和Modbus网络的奇偶校验.我需要C#中的代码.请帮忙.

I need to write a program to fetch the communication parameters like baud rate,stop bits and parity of a modbus network. I need the code in C#. please help.

推荐答案

好吧...

由于ModBus是规范,所以他们说的是:

RTU模式
1. 8位二进制编码系统
2. 1个起始位
3. 8个数据位,先发送LSB
4. 1位用于奇偶校验(要求设备支持偶数奇偶校验)
5. 1个停止位

在RTU模式下,消息以2个字节结尾,即16位CRC.所有设备都必须支持RTU模式作为默认发送模式,因此,当自动检查设备正在发送哪种模式时,应首先尝试检测RTU模式.

ASCII模式
1.十六进制ASCII字符0-9和A-F编码(成对发送)
2. 1个起始位
3. 7个数据位,LSB优先
4. 1个奇偶校验位(要求设备支持偶数奇偶校验)
5. 1个停止位

在ASCII模式下,消息必须以0x3A(冒号)开头,并以CRLF(0D0A)结尾.

需要9600bps和19,200bps,19,200bps是默认的网络速度.

因此,如果我必须自动协商网络,我将要做的是:

1.在我的驱动程序中选择RTU模式
2.将我的串行端口设置为19200,8,E,1
3.可能必须在此处发送广播消息才能使设备进行通话
4.收听传入的消息
5.检查是否通过了CRC,如果没有通过,请更改串行端口设置
6.对于所有波特率和奇偶校验,继续执行步骤2和5之间的操作
7.如果它们全部失败,请在步骤1切换到ASCII模式,然后从步骤2继续.

到ModBus串行规范的链接 [
Well...

Since ModBus is a specification, here is what they say:

RTU Mode
1. 8 Bit Binary Coding System
2. 1 Start Bit
3. 8 Data bits, LSB sent first
4. 1 Bit for Parity (Devices are REQUIRED to support EVEN parity)
5. 1 Stop bit

In RTU mode, messages end with 2 bytes which is a 16 bit CRC. All devices are required to support RTU mode as the default sending mode, so when auto-checking for what mode the device is sending in, you should start with trying to detect RTU mode.

ASCII Mode
1. Hexadecimal ASCII characters 0-9 and A-F Coding (sent as pairs)
2. 1 Start Bit
3. 7 Data bits, LSB first
4. 1 Parity Bit (Devices are REQUIRED to support EVEN parity)
5. 1 Stop Bit

In ASCII mode, messages must start with 0x3A (a colon) and end with CRLF (0D0A).

9600bps and 19,200bps are required, 19,200bps is the default network speed.

So what I would do if I had to auto-negotiate a network is:

1. Select RTU mode in my driver
2. Set my Serial port to 19200,8,E,1
3. May have to send a broadcast message here to get the devices to talk
4. Listen to the incoming message
5. Check to see if it passes the CRC, if not, change the serial port settings
6. Continue between step 2 and 5 for all baud rates, parities
7. If they all fail, switch to ASCII mode at step 1 and continue from step 2

Link to the ModBus Serial Specification[^]


这篇关于如何在Modbus网络中获取通信参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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