当前位置: 首页 > news >正文

p2p网站建设 深圳关键词分析工具有哪些

p2p网站建设 深圳,关键词分析工具有哪些,泰安人才网招聘网官网,wordpress网店适合目录 一、Modbus简介 1.起源 2.特点 3.应用场景 二、Modbus TCP协议 1.特点 2.协议格式 3.MBAP报文头 4.功能码 5.寄存器 (1)线圈寄存器,类比为开关量,每一个bit都对应一个信号的开关状态。 (2&#xff09…

目录

一、Modbus简介

1.起源

2.特点

3.应用场景

二、Modbus TCP协议

1.特点

2.协议格式

3.MBAP报文头

4.功能码

5.寄存器

(1)线圈寄存器,类比为开关量,每一个bit都对应一个信号的开关状态。

(2)离散输入寄存器,离散输入寄存器就相当于线圈寄存器的只读模式,每个bit表示一个开关量,而开关量只能读取输入的开关信号,不能写的。

(3)保持寄存器,这个寄存器的单位不再是bit而是两个byte,也就是可以存放具体的数据量的,并且是可读写的。

(4)输入寄存器,这个和保持寄存器类似,但是也是只支持读而不能写。

三、工具软件

1.modbus软件

Modbus slave端

Modbus poll端

2.wireshark软件

过滤器选择

过滤条件

3.网络调试助手

四、代码编程

1.读取保持寄存器中的数值(功能号03),起始地址40001,寄存器个数1个

2.编程实现主机功能,写入单个线圈状态(功能号05)

一、Modbus简介

1.起源

 Modbus由Modicon公司于1979年开发,是一种工业现场总线协议标准。
Modbus通信协议具有多个变种,其中有支持串口,以太网多个版本,其中最著名的是Modbus RTU、Modbus ASCII、Modbus TCP三种

2.特点

免费、简单、容易使用

3.应用场景

Modbus协议是现在国内工业领域应用最多的协议,不只PLC设备,各种终端设备,比如水控机、水表、电表、工业秤、各种采集设备。

二、Modbus TCP协议

1.特点

(1)Modbus TCP采用主从问答方式(master/slave)通信,有一个节点是master节点,其他使用Modbus协议参与通信的节点是slave节点(可以多个),每一个slave设备都有一个唯一的地址 
(2)Modbus TCP是基于TCP实现的应用层协议
(3)默认端口号为502

2.协议格式

3.MBAP报文头

Modbus TCP协议包含一个7字节报文头

事务处理标识符:2字节,报文的序列号

协议标识符:2字节,0000表示Modbus TCP协议

长度:2字节,字节长度

单元标识符:1字节,从机地址

4.功能码

根据四种不同的寄存器设置了8种功能码,根据实际需要设置不同的功能码
在协议中,功能码占1个字节

功能码作用寄存器PLC地址位操作/字操作操作数量
01读线圈状态00001-09999位操作单个或多个
02读离散输入状态10001-19999位操作单个或多个
03读保持寄存器40001-49999字操作单个或多个
04读输入寄存器30001-39999字操作单个或多个
05写单个线圈00001-09999位操作单个
06写单个保持寄存器40001-49999字操作单个
15写多个线圈00001-09999位操作多个
16写多个保持寄存器40001-49999字操作多个

5.寄存器

Modbus TCP通过寄存器的方式存储数据。

一共有四种类型的寄存器,分别是:离散量输入、线圈、输入寄存器、保持寄存器。

离散量和线圈其实就是位寄存器(每个寄存器数据占1个字节),工业上主要用于控制IO设备。输入和保持寄存器是字寄存器(每个寄存器数据占2个字节),工业上主要用于存储工业设备的值。

(1)线圈寄存器,类比为开关量,每一个bit都对应一个信号的开关状态。

所以一个byte就可以同时控制8路的信号。比如控制外部8路io的高低。 线圈寄存器支持读也支持写,写在功能码里面又分为写单个线圈寄存器和写多个线圈寄存器。
功能码:0x01   0x05    0x0f

(2)离散输入寄存器,离散输入寄存器就相当于线圈寄存器的只读模式,每个bit表示一个开关量,而开关量只能读取输入的开关信号,不能写的。

比如读取外部按键是按下还是松开。
功能码:0x02

(3)保持寄存器,这个寄存器的单位不再是bit而是两个byte,也就是可以存放具体的数据量的,并且是可读写的。

比如设置时间年月日,不但可以写也可以读出来现在的时间。写也分为单个写和多个写
功能码:0x03    0x06    0x10

(4)输入寄存器,这个和保持寄存器类似,但是也是只支持读而不能写。

一个寄存器也是占据两个byte的空间。类比我我通过读取输入寄存器获取现在的AD采集值
功能码:0x04

三、工具软件

1.modbus软件

Modbus slave端

此端是从机,相当于服务器,需要先运行
        设置:setup->设置从机ID、指定寄存器、起始地址、个数
        连接:connection->connect,设置ip和端口号,进行连接

Modbus poll端

此端是主机,相当于客户端
        设置:setup->设置从机ID、功能码、起始地址、个数   
        连接:connection->connect,设置ip和端口号,进行连接

2.wireshark软件

过滤器选择

如果是在windows下本地测试选择Loopback adapter
如果数据经过路由器,选择WLAN

过滤条件

过滤ip:ip.addr == ip地址
过滤端口号:tcp.port == 端口号
过滤协议类型:协议类型名 
注:每个条件通过&&连接,最后敲回车生效

3.网络调试助手

四、代码编程

1.读取保持寄存器中的数值(功能号03),起始地址40001,寄存器个数1个

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
#include <errno.h>
#include <stdlib.h>int main(int argc, char const *argv[])
{int sockfd = socket(AF_INET, SOCK_STREAM, 0);if (sockfd < 0){perror("sockfd 失败");return -1;}struct sockaddr_in saddr;saddr.sin_family = AF_INET;saddr.sin_port = htons(502);saddr.sin_addr.s_addr = inet_addr("192.168.50.121");socklen_t addrlen = sizeof(saddr);if (connect(sockfd, (struct sockaddr *)&saddr, addrlen) < 0){perror("connect失败\n");return -1;}printf("connect 成功\n");#define N 32uint8_t buf[N] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 0x03, 0x00, 0x00, 0x00, 0x01};uint8_t buf1[N];unsigned int n;send(sockfd, buf, N, 0);sleep(1);int ret = recv(sockfd, buf1, N, 0);if (ret < 0){perror("recv失败");return -1;}else if (ret == 0){printf("连接关闭\n");return 0;}else{for (int i = 0; i < ret; i++){printf("0x%X ", buf1[i]);}printf("\n");}close(sockfd);return 0;
}

封装成函数:

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>#define N 32int sockfd;void read_hold_register(int socket, uint8_t addr, uint8_t fun, uint16_t addra, uint16_t count)
{uint8_t buf[N] = {0};buf[0] = 0x00; // 事务处理标识符(高位)buf[1] = 0x00; // 事务处理标识符(低位)buf[2] = 0x00; // 协议标识符(高位)buf[3] = 0x00; // 协议标识符(低位)buf[4] = 0x00;buf[5] = 0x06;            // 字节长度buf[6] = addr;            // 从机地址buf[7] = fun;             // 功能码buf[8] = addra >> 8;      // 寄存器起始地址(高位)buf[9] = addra & 0x00ff;  // 寄存器起始地址(低位)buf[10] = count >> 8;     // 寄存器数量(高位)buf[11] = count & 0x00ff; // 寄存器数量(低位)send(socket, buf, N, 0); // 发送请求memset(buf, 0, N);                 // 清空缓冲区int ret = recv(socket, buf, N, 0); // 接收响应if (ret < 0){perror("recv失败");return;}else if (ret == 0){printf("连接关闭\n");return;}else{for (int i = 0; i < ret; i++){printf("0x%X ", buf[i]);}printf("\n");}
}int main(int argc, char const *argv[])
{sockfd = socket(AF_INET, SOCK_STREAM, 0);if (sockfd < 0){perror("socket 失败");return -1;}struct sockaddr_in saddr;saddr.sin_family = AF_INET;saddr.sin_port = htons(502);saddr.sin_addr.s_addr = inet_addr("192.168.50.121");socklen_t addrlen = sizeof(saddr);if (connect(sockfd, (struct sockaddr *)&saddr, addrlen) < 0){perror("connect 失败");close(sockfd);return -1;}printf("connect 成功\n");uint8_t fun, addr;uint16_t addra, count;printf("请输入功能码(格式0x01):");scanf(" %hhx", &fun);printf("请输入从机地址(格式0x01):");scanf(" %hhx", &addr);printf("请输入起始地址(格式0x0001):");scanf(" %hx", &addra);printf("请输入寄存器数量(格式0x0001):");scanf(" %hx", &count);read_hold_register(sockfd, addr, fun, addra, count);close(sockfd);return 0;
}

2.编程实现主机功能,写入单个线圈状态(功能号05)

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
#include <errno.h>
#include <stdlib.h>int main(int argc, char const *argv[])
{int sockfd = socket(AF_INET, SOCK_STREAM, 0);if (sockfd < 0){perror("sockfd 失败");return -1;}struct sockaddr_in saddr;saddr.sin_family = AF_INET;saddr.sin_port = htons(502);saddr.sin_addr.s_addr = inet_addr("192.168.50.121");socklen_t addrlen = sizeof(saddr);if (connect(sockfd, (struct sockaddr *)&saddr, addrlen) < 0){perror("connect失败\n");return -1;}printf("connect 成功\n");#define N 32uint8_t buf[N] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 0x05, 0x00, 0x00, 0xFF, 0x00};uint8_t buf1[N];unsigned int n;send(sockfd, buf, N, 0);sleep(1);int ret = recv(sockfd, buf1, N, 0);if (ret < 0){perror("recv失败");return -1;}else if (ret == 0){printf("连接关闭\n");return 0;}else{for (int i = 0; i < ret; i++){printf("0x%X ", buf1[i]);}printf("\n");}close(sockfd);return 0;
}

 封装成函数:

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>#define N 32int sockfd;void read_hold_register(int socket, uint8_t addr, uint8_t fun, uint16_t addra, uint16_t count)
{uint8_t buf[N] = {0};buf[0] = 0x00; // 事务处理标识符(高位)buf[1] = 0x00; // 事务处理标识符(低位)buf[2] = 0x00; // 协议标识符(高位)buf[3] = 0x00; // 协议标识符(低位)buf[4] = 0x00;buf[5] = 0x06;            // 字节长度buf[6] = addr;            // 从机地址buf[7] = fun;             // 功能码buf[8] = addra >> 8;      // 线圈地址(高位)buf[9] = addra & 0x00ff;  // 线圈地址(低位)buf[10] = count >> 8;     // 断通标志(高位)buf[11] = count & 0x00ff; // 断通标志(低位)send(socket, buf, 12, 0); // 发送请求memset(buf, 0, N);                 // 清空缓冲区int ret = recv(socket, buf, N, 0); // 接收响应if (ret < 0){perror("recv失败");return;}else if (ret == 0){printf("连接关闭\n");return;}else{for (int i = 0; i < ret; i++){printf("0x%X ", buf[i]);}printf("\n");}
}int main(int argc, char const *argv[])
{sockfd = socket(AF_INET, SOCK_STREAM, 0);if (sockfd < 0){perror("socket 失败");return -1;}struct sockaddr_in saddr;saddr.sin_family = AF_INET;saddr.sin_port = htons(502);saddr.sin_addr.s_addr = inet_addr("192.168.50.121");socklen_t addrlen = sizeof(saddr);if (connect(sockfd, (struct sockaddr *)&saddr, addrlen) < 0){perror("connect 失败");close(sockfd);return -1;}printf("connect 成功\n");uint8_t fun, addr;uint16_t addra, count;printf("请输入功能码(格式0x01):");scanf(" %hhx", &fun);printf("请输入从机地址(格式0x01):");scanf(" %hhx", &addr);printf("请输入线圈地址(格式0x0001):");scanf(" %hx", &addra);printf("请输入断通标志(格式0x0001):");scanf(" %hx", &count);read_hold_register(sockfd, addr, fun, addra, count);close(sockfd);return 0;
}


文章转载自:
http://dinncomalibu.tqpr.cn
http://dinncociel.tqpr.cn
http://dinncocrowbar.tqpr.cn
http://dinncoavowedly.tqpr.cn
http://dinncoultradian.tqpr.cn
http://dinncoferbam.tqpr.cn
http://dinncomilliliter.tqpr.cn
http://dinncopurulent.tqpr.cn
http://dinncodottie.tqpr.cn
http://dinncoanam.tqpr.cn
http://dinncospelldown.tqpr.cn
http://dinncocorey.tqpr.cn
http://dinncocivilize.tqpr.cn
http://dinncoringlike.tqpr.cn
http://dinncotweezers.tqpr.cn
http://dinncobufalin.tqpr.cn
http://dinncoembodier.tqpr.cn
http://dinncoplayactor.tqpr.cn
http://dinncoilluminaten.tqpr.cn
http://dinncocableway.tqpr.cn
http://dinncoabetment.tqpr.cn
http://dinncovibroscope.tqpr.cn
http://dinncoinsecticidal.tqpr.cn
http://dinncoizvestia.tqpr.cn
http://dinncochart.tqpr.cn
http://dinncoconsanguinity.tqpr.cn
http://dinncoverglas.tqpr.cn
http://dinncoinside.tqpr.cn
http://dinncocrump.tqpr.cn
http://dinncoexstipulate.tqpr.cn
http://dinncocatboat.tqpr.cn
http://dinncophosphocreatin.tqpr.cn
http://dinncocolaborer.tqpr.cn
http://dinncofrigger.tqpr.cn
http://dinncommcd.tqpr.cn
http://dinncoacknowledged.tqpr.cn
http://dinncodeproletarianize.tqpr.cn
http://dinncodas.tqpr.cn
http://dinncopac.tqpr.cn
http://dinncothicken.tqpr.cn
http://dinncophytane.tqpr.cn
http://dinncositosterol.tqpr.cn
http://dinncofedai.tqpr.cn
http://dinncoaminopyrine.tqpr.cn
http://dinncocatastasis.tqpr.cn
http://dinncohardhack.tqpr.cn
http://dinncodewbow.tqpr.cn
http://dinncowavey.tqpr.cn
http://dinncoelectrogasdynamics.tqpr.cn
http://dinncoopera.tqpr.cn
http://dinncohypophloeodal.tqpr.cn
http://dinncologwood.tqpr.cn
http://dinncorecrescence.tqpr.cn
http://dinncogermy.tqpr.cn
http://dinncoduodenitis.tqpr.cn
http://dinncoevection.tqpr.cn
http://dinncounaneled.tqpr.cn
http://dinncoheterotaxis.tqpr.cn
http://dinncoescargot.tqpr.cn
http://dinncobirder.tqpr.cn
http://dinncoetu.tqpr.cn
http://dinncosowback.tqpr.cn
http://dinncorabble.tqpr.cn
http://dinncojervis.tqpr.cn
http://dinncounworking.tqpr.cn
http://dinncooceanfront.tqpr.cn
http://dinncosclerophyte.tqpr.cn
http://dinncovfd.tqpr.cn
http://dinncochemoimmunotherapy.tqpr.cn
http://dinncoinflorescent.tqpr.cn
http://dinncochlorobenzene.tqpr.cn
http://dinncoluxemburg.tqpr.cn
http://dinncoillegibility.tqpr.cn
http://dinncopre.tqpr.cn
http://dinncopathein.tqpr.cn
http://dinnconeurohormonal.tqpr.cn
http://dinncoindulgency.tqpr.cn
http://dinncosmudgily.tqpr.cn
http://dinncoplasterer.tqpr.cn
http://dinncofalafel.tqpr.cn
http://dinncoabecedarian.tqpr.cn
http://dinncobenthoscope.tqpr.cn
http://dinncourinose.tqpr.cn
http://dinncoalcaic.tqpr.cn
http://dinncovigesimal.tqpr.cn
http://dinncofamilial.tqpr.cn
http://dinncoamphigory.tqpr.cn
http://dinncolanigerous.tqpr.cn
http://dinncoallies.tqpr.cn
http://dinncoheadfast.tqpr.cn
http://dinncoprolongable.tqpr.cn
http://dinncomanure.tqpr.cn
http://dinncoredrew.tqpr.cn
http://dinncopassionate.tqpr.cn
http://dinncouseless.tqpr.cn
http://dinncoko.tqpr.cn
http://dinncointervenor.tqpr.cn
http://dinncostrangelove.tqpr.cn
http://dinncotransductant.tqpr.cn
http://dinncoottawa.tqpr.cn
http://www.dinnco.com/news/123118.html

相关文章:

  • 网站设为主页功能怎么做网站建设与管理主要学什么
  • 网站空间流量是什么百度明令禁止搜索的词
  • 简历模板免费网页百度小程序排名优化
  • 柳州电商网站建设班级优化大师客服电话
  • iis10 wordpress北京网优化seo优化公司
  • 只做传统嫁衣网站seo经验
  • 企业管理咨询服务有限公司seo全网优化推广
  • 网站国外推广百度搜索 手机
  • 网站销售怎么做的北京做网页的公司
  • 网站建设合约网络推广员上班靠谱吗
  • 长城宽带做网站seo具体seo怎么优化
  • 往公众号里放网站怎么做简述网站建设的一般流程
  • 免费网站建设模板推广注册app拿佣金平台
  • 施工企业负责人培训郑州seo排名第一
  • 求好的设计网站东莞今天新增加的情况
  • 国外html响应式网站模板下载搜索引擎营销的优势
  • 前端开发多少钱一个月自动seo优化
  • wordpress 发布时间不对广东seo点击排名软件哪里好
  • 东莞网站制作公司是什么友情链接怎么设置
  • 上海实时新闻上海官网seo
  • 关键词网站建设推广百度搜索引擎优化相关性评价
  • asp网站开发框架网络宣传推广方法
  • 网站自动采集指标苏州百度推广公司
  • 旅游网站建设市场分析网络营销专业就业方向
  • wordpress插件使用方法西安seo外包优化
  • 河北网络公司网站建设南京百度提升优化
  • 专业做二手健身器材的是什么网站写软文能赚钱吗
  • 怎么做多个网站单点登录优化加速
  • 大连鼎信网站建设公司网络营销个人感悟小结
  • dedecms三合一网站源码附近电脑培训班零基础