59【工控通信】ModbusTCP通讯之ModbusPoll客户端工具配置

简介: 【工控通信】ModbusTCP通讯之ModbusPoll客户端工具配置

一、 Modbus Poll客户端工具安装

1.安装Modbus Poll客户端工具
在这里插入图片描述

2.Modbus Poll客户端工具安装好以后的界面
在这里插入图片描述

二、Modbus Poll客户端工具自带使用说明

Overview

Modbus Poll uses a multiple windows user interface. That means you can open several windows showing different data areas or data from different slave ID's at the same time. You can write any text in the Alias cells.

In any dialog box you can press the F1 key for more help on that specific topic.


在这里插入图片描述
This picture shows two open windows one reading 10 holding registers from ID 1, address 0 and one reading 10 holding registers from ID 2.

If your slave device allows you to change a Holding register then
youdouble click the cell or just start typing a new value in the
cell.Then an edit dialog box is shown.

Change the read/write definition

To change the read/write definition of a window you can press F8 or select "read/write definition" from the Setup menu.

在这里插入图片描述
Here you define which data to show in the window. This setup shows how toread 10 Holding Registers from address 0. Address 40001 in someprotocol descriptions. Note that Modbus Poll uses Modbus addresseswhich always counts from 0.

在这里插入图片描述
在这里插入图片描述

How to make a connection

There is no data to display if you have not made a connection. To do so press F3 or select connect from the connection menu. For more detailed help press F1.
在这里插入图片描述
This connection use Modbus TCP/IP.

5 different connection types are available however only 2 of them are standard Modbus connections:
•Serial port
•Modbus TCP/IP

For serial connection you may need an USB to RS485, or an RS232 to RS485 converter.

三、 创建自己的Modbus TCP服务端程序

1、我在自己的程序中做了个ModbusTCP服务器,在服务器开启之后,并且ModbusTCP客户端与服务端通讯成功之后,向ModbusTCP客户端写数据。ModbusPull作为客户端。

服务端程序:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Net.Sockets;
using Modbus.Device;
using Modbus.Data;

namespace ModbusTCPServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        //定义公共变量
        public static bool isModBusServerEnable = true;
        public static ModbusSlave modbusTcpSlave = null;
        public static TcpListener tcpListener;
        public static bool slaveCon = false;
        public static DataStore dataStore;

        private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = 1; i < 1000000; i++)
            {
                SetValueToModBusTcpServer(i, i);//第一个参数为写入的地址,从1开始,第二个为写入的数值
            }

            bool valueBool = true;
            SetValueToModBusTcpServer(1, valueBool);//给地址的第1位写入bool值1
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //创建并开启ModbusTcp服务器
            try
            {
                //dataStore = DataStoreFactory.CreateDefaultDataStore();//初始化服务数据区
                tcpListener = new TcpListener(System.Net.IPAddress.Parse("本地电脑IP"), 502);
                modbusTcpSlave = ModbusTcpSlave.CreateTcp(1, tcpListener);
                //modbusTcpSlave.DataStore = dataStore;
                modbusTcpSlave.Listen();
                slaveCon = true;
            }
            catch (Exception)
            {
                slaveCon = false;
            }
        }

        /// <summary>
        /// 向ModBusTcp服务写入模拟量
        /// </summary>
        /// <param name="index"></param>
        /// <param name="value"></param>
        private void SetValueToModBusTcpServer(int index, float value)
        {
            byte[] buffer = BitConverter.GetBytes(value);
            ushort highValue = BitConverter.ToUInt16(buffer, 0);
            ushort lowValue = BitConverter.ToUInt16(buffer, 2);
            ModbusDataCollection<ushort> data = modbusTcpSlave.DataStore.InputRegisters;
            data[index] = lowValue;
            data[index + 1] = highValue;
        }

        /// <summary>
        /// 向ModBusTcp服务写入数字量
        /// </summary>
        /// <param name="index"></param>
        /// <param name="value"></param>
        private void SetValueToModBusTcpServer(int index, bool value)
        {
            ModbusDataCollection<bool> data = modbusTcpSlave.DataStore.InputDiscretes;
            lock (modbusTcpSlave.DataStore.SyncRoot)
            {
                data[index] = value;
            }

        }
    }
}

四、Modbus TCP服务端(自建)与Modbus Poll客户端工具进行Modbus TCP通讯

1、客户端配置

(1)选择通讯方式
在这里插入图片描述

(2)选择数据传输寄存器类型

在这里插入图片描述

(3)运行Modbus TCP自己创建的服务端程序之后,与Modbus Poll客户端工具建立通信联系,读到的数据如下:

通信不成功Modbus Poll客户端工具界面会有红色字体出现。

获取数据区域(部分字节/双字节)

在这里插入图片描述

读到数据,没有红色字体,说明通信成功!

总结

这里Modbus TCP通讯客户端使用了自带的客户端工具Modbus Poll,服务端程序是自己写的。后续也可以自己写一个Modbus TCP通讯的客户端程序。

目录
相关文章
|
存储 编译器
什么是数据块?西门子S7-200SMART数据块如何使用?
今天我们来学习在西门子S7-200 SMART中如何使用数据块。在讲解数据块的使用之前我们先来看一下什么是数据块:数据块用来对V存储区也叫变量存储区赋初始值;可以对字节、字或双字来分配数据值。
什么是数据块?西门子S7-200SMART数据块如何使用?
|
7月前
|
Ubuntu 安全 Linux
CentOS与Ubuntu的深度对比与分析
Ubuntu更新频繁、文档丰富,适用于云服务与容器部署。 与CentOS的比较,Ubuntu基于Debian,而CentOS则源自RHEL。在软件包格式上,Ubuntu采用.deb和.snap,而CentOS则使用.rpm和flatpak。更新方面,Ubuntu使用apt,而CentOS则依赖yum。尽管CentOS以稳定性见长,不常对包进行更新,但这并不意味着Ubuntu在安全性上逊色。事实上,Ubuntu提供了更为丰富的文档和免费的技术支持。此外,Ubuntu的服务器版本在云服务和容器部署方面拥有更多的优势。
ModBus Pull的详细安装教程
ModBus Pull的详细安装教程
1324 1
|
10月前
|
传感器 物联网 Linux
Python:蓝牙心率广播设备监测(BLE 心率监测器)技术解析与实现
本文探讨了如何使用 Python 脚本与支持蓝牙低功耗(BLE)心率广播的设备交互以获取实时心率数据。重点分析了 BLE 协议、GATT 服务模型,以及具体方法。此外,还讨论了华为手表等设备的兼容性问题。
1872 19
|
安全 网络协议 网络安全
【网络连接】ping不通的常见原因+解决方案,如何在只能访问网关时诊断,并修复IP不通的问题
【网络连接】ping不通的常见原因+解决方案,如何在只能访问网关时诊断,并修复IP不通的问题
30317 0
|
传感器 物联网 人机交互
物联网:物联网,作为新一代信息技术的重要组成部分,通过智能感知、识别技术与普适计算等通信感知技术,将各种信息传感设备与互联网结合起来而形成的一个巨大网络,实现了物物相连、人物相连,开启了万物互联的新时代。
在21世纪,物联网(IoT)作为新一代信息技术的核心,正以前所未有的速度重塑生活、工作和社会结构。本文首先介绍了物联网的概念及其在各领域的广泛应用,强调其技术融合性、广泛的应用范围以及数据驱动的特点。接着,详细阐述了物联网行业的现状和发展趋势,包括政策支持、关键技术突破和应用场景深化。此外,还探讨了物联网面临的挑战与机遇,并展望了其未来在技术创新和模式创新方面的潜力。物联网行业正以其独特魅力引领科技发展潮流,有望成为推动全球经济发展的新引擎。
|
Rust 监控 网络协议
EtherCAT主站IgH解析(一)--主站初始化、状态机与EtherCAT报文
本文介绍了IgH EtherCAT Master整体运行原理
2669 0
EtherCAT主站IgH解析(一)--主站初始化、状态机与EtherCAT报文
【LVGL快速入门】SquareLine Studio安装教程(LVGL官方工具)
【LVGL快速入门】SquareLine Studio安装教程(LVGL官方工具)
4696 0
|
存储 传感器 SQL
influxdb 中得 fields 与 tag 区别总结
influxdb 中得 fields 与 tag 区别总结
1378 1

热门文章

最新文章