C#上位机序列6: modbus通信(NModbus4 modbus tcp)

C#上位机序列1: 多线程(线程同步,事件触发,信号量,互斥锁,共享内存,消息队列)

C#上位机序列7: 分库分表

C#上位机序列8: 数据库同步

C#上位机序列9: 批量读写+事件广播+数据类型处理

C#上位机序列10: Winform上位机通用框架

 

modbus点位多,轮询慢问题,造成数据延时问题

1. 采用并行的方式采集从站设备,采用串行的方式获取从站点位数据;
2. 制定轮询策略,实时性要求高的点位,轮询周期短;实时性要求低的点位,轮询周期长;非必要不轮询,数据有变化才写入;
3. 一次读取从站的所有数据,不要按点位多次读取;
4. 提高串口的波特率;
5. 采用can通信方式

 

  

modbus tcp

读取

bool
[调试] 2021-04-27 09:34:57.940 Thread [009] ModbusTcpServer[502] : Tcp 接收:00 00 00 00 00 06 01 01 00 63 00 01
[调试] 2021-04-27 09:34:57.940 Thread [009] ModbusTcpServer[502] : Tcp 发送:00 00 00 00 00 04 01 01 01 00

short
[调试] 2021-04-27 09:33:23.307 Thread [013] ModbusTcpServer[502] : Tcp 接收:00 00 00 00 00 06 01 03 00 63 00 01
[调试] 2021-04-27 09:33:23.307 Thread [013] ModbusTcpServer[502] : Tcp 发送:00 00 00 00 00 05 01 03 02 00 00

int
[调试] 2021-04-27 09:33:52.148 Thread [013] ModbusTcpServer[502] : Tcp 接收:00 00 00 00 00 06 01 03 00 63 00 02
[调试] 2021-04-27 09:33:52.148 Thread [013] ModbusTcpServer[502] : Tcp 发送:00 00 00 00 00 07 01 03 04 00 00 00 01

float
[调试] 2021-04-27 09:34:29.733 Thread [013] ModbusTcpServer[502] : Tcp 接收:00 00 00 00 00 06 01 03 00 63 00 02
[调试] 2021-04-27 09:34:29.733 Thread [013] ModbusTcpServer[502] : Tcp 发送:00 00 00 00 00 07 01 03 04 00 00 00 01

long
[调试] 2021-04-28 15:41:46.049 Thread [008] ModbusTcpServer[502] : Tcp 接收:00 09 00 00 00 06 01 03 00 64 00 04
[调试] 2021-04-28 15:41:46.049 Thread [008] ModbusTcpServer[502] : Tcp 发送:00 09 00 00 00 0B 01 03 08 3F 80 00 00 00 00 00 00

double
[调试] 2021-04-28 15:42:12.893 Thread [009] ModbusTcpServer[502] : Tcp 接收:00 0B 00 00 00 06 01 03 00 64 00 04
[调试] 2021-04-28 15:42:12.893 Thread [009] ModbusTcpServer[502] : Tcp 发送:00 0B 00 00 00 0B 01 03 08 3F 80 00 00 00 00 00 00


写入

bool
[调试] 2021-04-28 15:43:27.742 Thread [008] ModbusTcpServer[502] : Tcp 接收:00 00 00 00 00 06 01 05 00 64 FF 00
[调试] 2021-04-28 15:43:27.742 Thread [008] ModbusTcpServer[502] : Tcp 发送:00 00 00 00 00 06 01 05 00 64 FF 00

short
[调试] 2021-04-28 15:44:05.406 Thread [003] ModbusTcpServer[502] : Tcp 接收:00 02 00 00 00 06 01 06 00 64 00 01
[调试] 2021-04-28 15:44:05.406 Thread [003] ModbusTcpServer[502] : Tcp 发送:00 02 00 00 00 06 01 06 00 64 00 01

int
[调试] 2021-04-28 15:44:24.557 Thread [003] ModbusTcpServer[502] : Tcp 接收:00 03 00 00 00 0B 01 10 00 64 00 02 04 00 00 00 01
[调试] 2021-04-28 15:44:24.558 Thread [003] ModbusTcpServer[502] : Tcp 发送:00 03 00 00 00 06 01 10 00 64 00 02

float
[调试] 2021-04-28 15:44:45.854 Thread [003] ModbusTcpServer[502] : Tcp 接收:00 04 00 00 00 0B 01 10 00 64 00 02 04 3F 80 00 00
[调试] 2021-04-28 15:44:45.854 Thread [003] ModbusTcpServer[502] : Tcp 发送:00 04 00 00 00 06 01 10 00 64 00 02

long
[调试] 2021-04-28 15:45:37.896 Thread [006] ModbusTcpServer[502] : Tcp 接收:00 06 00 00 00 0F 01 10 00 64 00 04 08 00 00 00 00 00 00 00 01
[调试] 2021-04-28 15:45:37.896 Thread [006] ModbusTcpServer[502] : Tcp 发送:00 06 00 00 00 06 01 10 00 64 00 04

double
[调试] 2021-04-28 15:45:07.224 Thread [003] ModbusTcpServer[502] : Tcp 接收:00 05 00 00 00 0F 01 10 00 64 00 04 08 3F F0 00 00 00 00 00 00
[调试] 2021-04-28 15:45:07.224 Thread [003] ModbusTcpServer[502] : Tcp 发送:00 05 00 00 00 06 01 10 00 64 00 04

 

bool 读写测试

 short 读写测试

int 读写测试

float 读写测试

double 读写测试

long 读写测试

int, float 涉及传输顺序,必须按照相同的传输顺序进行传送和解析,否则会造成数据错误

 

ModBusTcpServer 与 ModBusTcpClient

 

更新日志

2023-10-25  新增批量读取及批量写入功能

2023-11-16  支持02指令

 

posted @ 2021-06-19 13:58  CHHC  阅读(4783)  评论(0编辑  收藏  举报