用 ADAM-6052 学习 ModBus TCP 协议 (2) – Modbus TCP 的扫描速率

目录 Content
[hide]

Modbus TCP 的工作原理是 POLLING(即轮询)的方式,那么速率能有多快呢? 希望本文能给你带来感性认识。

一、设置

以读取 DO 状态为例,将  Modbus Poll 做如下设置:

1.  请求间隔

帮助文件的介绍:

Min Delay between polls:
This setting ensures a minimum delay until next request is transmitted no matter of the scan rate. The resolution of this setting is approximately 15ms. It’s possible on some computers to obtain better resolution but not all.

Important: If you set this value lower than 20ms the 3.5 char time gap between response and a new request can not be guaranteed. This is because the Windows scheduler switch task every 10 – 20ms.

  1. If you Polls several slaves in a serial RS485 network you should NOT set the value lower than 20ms. This is to ensure the 3.5 char time gap.
  2. In a TCP/IP network less than 20ms is ok.
  3. Serial connection to only one slave device less than 20ms is ok.

2.  扫描速率

帮助文件的介绍:

Scan Rate:
The scan rate can be set from 0 to 3600000ms. Note that setting the scan rate less than the transaction time makes no sense. If a serial connection at 9600baud is used and 125 registers are requested the transaction time is roughly 8 + 2 + 250 + 2 = 262ms + the gap (>3.5 char time) between the request and the response. In this case setting the scan rate at e.g. 100ms do not make sense as the transaction time is at least 262ms + delay in the slave (gap) + min time between polls. (Set in the connection dialog).

二、测量

用秒表计时,测算 50416 秒时间段(电脑开了一夜 ~)总共发送接收 3287292 次,每次发送数据为12 Byte,每次接收字节为10 Byte。

  • 每秒传输的数据量: (12+10)*3287292/50416/2 = 717 Byte
  • 计算网络使用率: (717*8/1024/1024)/100 = 0.054%,与任务管理器里 0.06% 大概相符。
  • 每秒传送的指令: 3287292 / 50416 = 65 个
  • 每个指令耗时: 50416 / 3287292 = 15 毫秒

三、结论

可以看出,尽管设置了 scan rate 为 1 毫秒,每次查询间隔 1 毫秒,但实测下来,每次查询平均耗时 15  毫秒,这还只是一个 slave 设备(ADAM-6052)并且只读取 1 个  Byte 的情况下,如果读取多个(设备和)字节,所需时间估计要大于 15 毫秒。单纯的设置很小间隔的扫描速率是没有意义的。

扩展阅读

Leave a Reply

Your email address will not be published. Required fields are marked *