CN104796415B - A kind of conversion method between multi-protocols and TCP procotols in RS485 buses - Google Patents

A kind of conversion method between multi-protocols and TCP procotols in RS485 buses Download PDF

Info

Publication number
CN104796415B
CN104796415B CN201510159994.6A CN201510159994A CN104796415B CN 104796415 B CN104796415 B CN 104796415B CN 201510159994 A CN201510159994 A CN 201510159994A CN 104796415 B CN104796415 B CN 104796415B
Authority
CN
China
Prior art keywords
communication
slave station
station equipment
protocol
communication slave
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510159994.6A
Other languages
Chinese (zh)
Other versions
CN104796415A (en
Inventor
杜大军
王凯
漆波
商立立
费敏锐
王海宽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
SHANGHAI UNIVERSITY
Original Assignee
SHANGHAI UNIVERSITY
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by SHANGHAI UNIVERSITY filed Critical SHANGHAI UNIVERSITY
Priority to CN201510159994.6A priority Critical patent/CN104796415B/en
Publication of CN104796415A publication Critical patent/CN104796415A/en
Application granted granted Critical
Publication of CN104796415B publication Critical patent/CN104796415B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/08Protocols for interworking; Protocol conversion

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Communication Control (AREA)
  • Computer And Data Communications (AREA)

Abstract

本发明涉及一种RS485总线上的多协议与TCP网络协议之间的转换方法。本方法下行通信采用RS485总线通过RS485接口与微处理器连接,上行通信采用微处理器通过以太网接口接入互联网,微处理器还连接有NandFlash、SDRAM和SD卡,构建起了协议转换的硬件平台,并通过以太网接口在系统中生成系统配置文件,然后根据该配置文件构建一张通信从站设备信息表,最后采用该通信从站设备信息表定时轮询RS485总线上的各从站设备,并对接收的协议数据包进行解析,将解析得到的数据以一定的XML格式(以文本形式)打包成TCP/IP数据包进行远传,从而实现DL/T645‑1997、CJ/T188‑2004和GB/T19582‑2008通信协议与TCP网络协议之间的转换。本发明主要应用在建筑能耗数据采集器中。

The invention relates to a conversion method between multi-protocol and TCP network protocol on the RS485 bus. The downlink communication of this method adopts the RS485 bus to connect with the microprocessor through the RS485 interface, and the uplink communication adopts the microprocessor to access the Internet through the Ethernet interface, and the microprocessor is also connected with NandFlash, SDRAM and SD card, and the hardware for protocol conversion is constructed. platform, and generate a system configuration file in the system through the Ethernet interface, then construct a communication slave station device information table according to the configuration file, and finally use the communication slave station device information table to regularly poll each slave station device on the RS485 bus , and analyze the received protocol data packets, and pack the parsed data into TCP/IP data packets in a certain XML format (in text form) for remote transmission, so as to realize DL/T645‑1997, CJ/T188‑2004 And the conversion between GB/T19582-2008 communication protocol and TCP network protocol. The invention is mainly applied in building energy consumption data collectors.

Description

一种RS485总线上的多协议与TCP网络协议之间的转换方法A conversion method between multi-protocol and TCP network protocol on RS485 bus

技术领域technical field

本文涉及一种RS485总线上的多协议与TCP网络协议之间的转换方法,属于现场This article involves a conversion method between multi-protocol and TCP network protocol on the RS485 bus, which belongs to the field

总线控制技术领域。field of bus control technology.

背景技术Background technique

现场总线是用于生产制造现场的底层通信网络,它实现了微机化的现场测量控制仪器或设备之间的双向串行节点数字通信,具有实时性、稳定性高的特点。自从2000年国际电工委员会(IEC)公布通过了IEC61158现场总线标准,现在已有十多种现场总线标准。The field bus is the underlying communication network used in the production and manufacturing field. It realizes the bidirectional serial node digital communication between computerized on-site measurement and control instruments or equipment, and has the characteristics of real-time and high stability. Since the International Electrotechnical Commission (IEC) announced and passed the IEC61158 fieldbus standard in 2000, there are now more than ten fieldbus standards.

以太网是商业领域里普遍采用的局域网络,结合TCP/IP协议构成了Internet的Ethernet is a local area network commonly used in the commercial field, combined with the TCP/IP protocol to form the Internet

基础,成为网络应用中事实上的标准,这也使得现场总线控制系统通过以太网与国家信息网It has become the de facto standard in network applications, which also makes the fieldbus control system communicate with the national information network through Ethernet

集成实现全国监控一体化成为大势所趋。Integration to realize the integration of national monitoring has become the general trend.

DL/T 645-1997《多功能电表通信规约》是我国为统一和规范多功能电能表的费率DL/T 645-1997 "Communication Protocol for Multi-function Electric Energy Meters" is the tariff rate for the unification and standardization of multi-functional electric energy meters in my country

装置与数据终端设备进行数据交换时的物理连接和协议而制定的一个电力行业标准。A power industry standard developed for the physical connection and protocol for data exchange between devices and data terminal equipment.

CJ/T 188-2004《户用计量仪表数据传输技术条件》是我国针对户用计量仪表制定CJ/T 188-2004 "Technical Conditions for Data Transmission of Household Metering Instruments" is formulated by my country for household metering instruments.

的一个行业标准,包括水表、燃气表、热量表等仪表数据传输的基本原则、接口形式及物理An industry standard, including the basic principles, interface forms and physical

性能、数据链路、数据标识及数据安全和数据表达格式的要求。Performance, data link, data identification and data security and data expression format requirements.

Modbus协议最初由Modicon公司开发出来,现已成为工业领域全球最流行的通用The Modbus protocol was originally developed by Modicon and has become the world's most popular general-purpose protocol in the industrial field.

工业标准协议之一。2008年我国颁布国标GB/T 19582-2008《基于Modbus协议的工业自动化网络规范》,并于2008-09-01起实施。One of the industry standard protocols. In 2008, my country promulgated the national standard GB/T 19582-2008 "Industrial Automation Network Specification Based on Modbus Protocol", and it will be implemented from 2008-09-01.

目前DL/T 645-1997、CJ/T 188-2004和GB/T 19582-2008通信协议普遍采用标准Currently DL/T 645-1997, CJ/T 188-2004 and GB/T 19582-2008 communication protocols generally adopt the standard

RS485通讯接口作为其物理层传送方式,通讯波特率1200BPS-115200BPS,主从半双工方式。The RS485 communication interface is used as the physical layer transmission mode, the communication baud rate is 1200BPS-115200BPS, and the master-slave half-duplex mode.

根据《国务院关于印发节能减排综合性工作方案的通知》,逐步建立起全国联网的According to the "Notice of the State Council on Printing and Distributing the Comprehensive Work Plan for Energy Conservation and Emission Reduction", gradually establish a nationwide network

国家机关办公建筑和大型公共建筑能耗监测平台,对全国重点城市重点建筑能耗(电、水、The energy consumption monitoring platform of office buildings of state organs and large public buildings, the energy consumption of key buildings in key cities across the country (electricity, water,

燃气、热量)进行实时监测,这就需要利用能耗数据采集器对能耗计量装置进行数据采集,Gas, heat) for real-time monitoring, which requires the use of energy consumption data collectors to collect data on energy consumption metering devices,

然后将采集到的能耗数据通过TCP网络上传到数据中心(或数据中转站),而计量装置普遍Then upload the collected energy consumption data to the data center (or data transfer station) through the TCP network, and the metering device generally

采用DL/T 645-1997、CJ/T 188-2004和GB/T 19582-2008通信协议,同时,能耗数据采集器Adopt DL/T 645-1997, CJ/T 188-2004 and GB/T 19582-2008 communication protocols, at the same time, the energy consumption data collector

与计量装置之间使用符合行业标准的物理接口(RS485接口),这就涉及到RS485总线上的以上三种协议与TCP网络协议之间的转换,所以,本发明提出了一种RS485总线上的多协议与TCP网络协议之间的转换方法。A physical interface (RS485 interface) conforming to the industry standard is used between the metering device, which involves the conversion between the above three protocols on the RS485 bus and the TCP network protocol. Therefore, the present invention proposes a protocol on the RS485 bus. The conversion method between multi-protocol and TCP network protocol.

发明内容Contents of the invention

本发明的目的在于提出一种RS485总线上的多协议与TCP网络协议之间的转换The purpose of the invention is to propose a conversion between multi-protocol and TCP network protocol on the RS485 bus

方法,实现DL/T645-1997、CJ/T188-2004和GB/T19582-2008通信协议与TCP网络协议之间的转换。本协议转换模型主要采用基于协议的主站模型。The method realizes the conversion between DL/T645-1997, CJ/T188-2004 and GB/T19582-2008 communication protocols and TCP network protocols. This protocol conversion model mainly adopts the master station model based on the protocol.

为了实现上述目的,本发明的构思如下:In order to achieve the above object, the design of the present invention is as follows:

生成系统配置文件Generate system configuration files

在基于现场总线的主站-从站通信系统中,一个通信主站设备通过现场总线连接In a fieldbus-based master-slave communication system, a communication master device is connected via a fieldbus

有多个通信从站设备,整个主站-从站通信系统中,只有通信主站设备具有主动发起通信的能力,通信从站设备接收通信主站设备的信息并与通信主站设备进行信息交互。而通信主站设备要实现与通信从站设备之间的通信,通信主站设备需要知道通信从站设备的地址、通信协议等信息,因此,首先要由通信主站设备对整个系统进行一个系统配置,让通信主站设备知道连接到总线上的通信从站设备的相关信息,便于通信主站设备对整个系统进行管理。There are multiple communication slave devices. In the entire master-slave communication system, only the communication master device has the ability to actively initiate communication. The communication slave device receives information from the communication master device and exchanges information with the communication master device. . However, if the communication master device needs to realize the communication with the communication slave device, the communication master device needs to know the address, communication protocol and other information of the communication slave device. Configuration, let the communication master device know the relevant information of the communication slave device connected to the bus, which is convenient for the communication master device to manage the whole system.

构建通信从站设备信息表Build communication slave device information table

由于通信主站设备与通信从站设备之间的通信是由处理器软件控制实现的,通信主站设备要与通信从站设备进行通信,首先需要通过程序读取系统的配置信息,获得通信从站设备的地址、通信协议等相关信息,然后才能发起通信。Since the communication between the communication master device and the communication slave device is controlled by the processor software, if the communication master device wants to communicate with the communication slave device, it first needs to read the configuration information of the system through the program to obtain the communication slave device. The address, communication protocol and other relevant information of the station equipment can be initiated before communication.

如果通信主站设备每次向通信从站设备主动发起通信都需要去读取系统的配置信息,系统的效率就会很低,为了提高系统的运行效率,可以根据读取的系统配置信息,建立一个通信从站设备信息表,该信息表是一个结构体数组,数组的每一个节点记录的是一个通信从站设备的信息,该信息包括通信从站设备编号、通信从站设备地址、通信从站设备所使用的协议类型、通信从站设备所连接总线等。If the communication master device needs to read the system configuration information every time it initiates communication with the communication slave device, the efficiency of the system will be very low. In order to improve the operating efficiency of the system, according to the read system configuration information, establish A communication slave station device information table, the information table is a structure array, each node of the array records the information of a communication slave station device, the information includes the communication slave station device number, communication slave station device address, communication slave station The protocol type used by the station device, the bus connected to the communication slave device, etc.

初始化RS485接口和TCP网络Initialize RS485 interface and TCP network

由于RS485总线上的通信要求通信主站设备和通信从站设备接收和发送数据的速率相同,而TCP网络上的通信需要知道目的主机的IP地址等信息,所以在通信主站设备上,需要通过读取的系统配置信息对RS485接口和TCP网络进行初始化。Since the communication on the RS485 bus requires the communication master station equipment and the communication slave station equipment to receive and send data at the same rate, and the communication on the TCP network needs to know the IP address and other information of the destination host, so on the communication master station equipment, it is necessary to pass The read system configuration information initializes the RS485 interface and the TCP network.

定时轮询RS485总线上的各通信从站设备及协议转换Periodic polling of each communication slave device on the RS485 bus and protocol conversion

通信主站设备根据通信从站设备信息表,定时轮询各通信从站设备,通信从站设备根据通信主站设备发出的数据包做出响应,通信主站设备接收通信从站设备的应答数据包,然后,通信主站设备根据通信从设备信息表解析协议数据,将解析得到的数据以一定的XML格式(以文本形式)打包成TCP/IP数据包进行远传,从而实现RS485总线上的多协议与TCP网络协议之间的协议转换。The communication master station equipment regularly polls each communication slave station device according to the communication slave station device information table, the communication slave station device responds according to the data packet sent by the communication master station device, and the communication master station device receives the response data from the communication slave station device Then, the communication master station equipment analyzes the protocol data according to the information table of the communication slave equipment, and packs the analyzed data into TCP/IP data packets in a certain XML format (in text form) for remote transmission, so as to realize the communication on the RS485 bus Protocol conversion between multi-protocol and TCP network protocol.

根据上述发明构思,本发明采用下述技术方案:According to above-mentioned inventive concept, the present invention adopts following technical scheme:

一种RS485总线上的多协议与TCP网络协议之间的转换方法,其特征在于:本方法下行通信采用RS485总线通过RS485接口与微处理器连接,上行通信采用微处理器通过以太网接口接入互联网,微处理器还连接有NandFlash、SDRAM和SD卡,构建起了协议转换的硬件平台,并采用本发明提供的通信从站设备信息表定时轮询RS485总线上的各从站设备,并对接收的协议数据包进行解析,将解析得到的数据以一定的XML格式(以文本形式)打包成TCP/IP数据包进行远传,实现RS485总线上的多协议与TCP网络协议之间的转换。A conversion method between multi-protocol and TCP network protocol on the RS485 bus, characterized in that: the downlink communication of the method adopts the RS485 bus to connect with the microprocessor through the RS485 interface, and the uplink communication adopts the microprocessor to access through the Ethernet interface Internet, microprocessor is also connected with NandFlash, SDRAM and SD card, has built the hardware platform of protocol conversion, and adopts the communication slave station equipment information table that the present invention provides to regularly poll each slave station equipment on the RS485 bus, and to The received protocol data packets are analyzed, and the analyzed data are packaged into TCP/IP data packets in a certain XML format (in text form) for remote transmission, so as to realize the conversion between the multi-protocol on the RS485 bus and the TCP network protocol.

上述的协议转换的具体步骤如下:The specific steps of the above-mentioned protocol conversion are as follows:

(1)微处理器初始化;(1) Microprocessor initialization;

(2)操作系统初始化;(2) Operating system initialization;

(3)通过以太网接口生成系统配置文件;(3) Generate system configuration files through the Ethernet interface;

(4)根据步骤(3)的配置文件构建一张通信从站设备信息表;(4) Construct a communication slave station device information table according to the configuration file in step (3);

(5)根据步骤(3)的配置文件分别初始化RS485接口和TCP网络;(5) Initialize the RS485 interface and TCP network respectively according to the configuration file in step (3);

(6)根据步骤(4)的通信从设备信息表,通过RS485总线定时轮询RS485总线上的各从站设备,并对接收的协议数据进行解析,最后将解析得到的数据以一定的XML格式(以文本形式)打包成TCP/IP数据包进行远传,从而实现RS485总线上的多协议与TCP网络协议之间的转换。(6) According to the communication slave device information table in step (4), periodically poll each slave station device on the RS485 bus through the RS485 bus, and analyze the received protocol data, and finally convert the parsed data into a certain XML format (in text form) packaged into TCP/IP data packets for remote transmission, so as to realize the conversion between the multi-protocol on the RS485 bus and the TCP network protocol.

所述步骤(3)中的生成系统配置文件的具体方法:通过嵌入式Web的形式将连接到通信主站设备的各通信从站设备的设备编号、设备地址、协议类型等信息写入到系统中的一个XML文件中,从而生成一个系统配置文件。The specific method of generating the system configuration file in the step (3): write the device number, device address, protocol type and other information of each communication slave device connected to the communication master device into the system through the form of embedded Web In an XML file in , a system configuration file is generated.

所述步骤(4)中的通信从站设备信息表是一个结构体类型的链表(或数组),链表(或数组)的每一个节点记录了一个通信从站设备的相关信息,这些信息包括通信从站设备所连接的RS485端口、通信从站设备类型、通信从站设备所使用协议和通信从站设备的设备号。The communication slave station device information table in the step (4) is a linked list (or array) of structure type, and each node of the linked list (or array) records the relevant information of a communication slave station device, which includes communication The RS485 port to which the slave device is connected, the type of the communication slave device, the protocol used by the communication slave device, and the device number of the communication slave device.

所述步骤(6)中RS485总线上的多协议与TCP网络协议之间的转换的具体方法为:The specific method of conversion between the multi-protocol on the RS485 bus and the TCP network protocol in the step (6) is:

1)根据系统配置文件,设定定时器;1) Set the timer according to the system configuration file;

2)定时时间到后,通信主站设备根据通信从站设备信息表中记录的RS485总线上连接通信从站设备的相关信息,依次轮询各个通信从站设备;2) After the timing time is up, the communication master device polls each communication slave device in turn according to the relevant information of the communication slave device connected to the RS485 bus recorded in the communication slave device information table;

3)接收通信从站设备的协议数据,根据信息表中的设备信息解析协议数据;3) Receive the protocol data of the communication slave device, and analyze the protocol data according to the device information in the information table;

4) 将解析得到的数据以一定的XML格式(以文本形式)打包成TCP/IP数据包4) Pack the parsed data into a TCP/IP packet in a certain XML format (in text form)

进行远传,从而实现RS485总线上的多协议与TCP网络协议之间的转换。Perform remote transmission to realize the conversion between multi-protocol and TCP network protocol on the RS485 bus.

上述的系统配置文件包含RS485总线上的通信从站设备的设备编号、设备地址、协议类型以及以太网接口的数据远传主机的IP地址;所述的通信从站设备信息表是根据系统配置文件生成的,通信从站设备信息表中的信息与RS485总线上连接的通信从站设备一一对应。The above-mentioned system configuration file includes the device number, device address, protocol type and the IP address of the data remote transmission host of the Ethernet interface on the communication slave station device on the RS485 bus; the communication slave station device information table is based on the system configuration file The generated information in the communication slave station device information table corresponds to the communication slave station devices connected to the RS485 bus.

根据上述的协议转换方法中,在同一个RS485总线上允许传输多种协议的数据:DL/T645-1997、CJ/T188-2004和GB/T19582-2008通信协议。According to the above-mentioned protocol conversion method, data of multiple protocols are allowed to be transmitted on the same RS485 bus: DL/T645-1997, CJ/T188-2004 and GB/T19582-2008 communication protocols.

在上述的协议转换方法中,通过通信从站设备信息表,通信主站设备可对各通信从站设备进行统一管理;通信主站设备根据协议数据的地址可判断出发送该协议数据的设备编号,再通过查阅通信从站设备信息表,可获得该协议数据所使用的协议类型。In the above-mentioned protocol conversion method, through the communication slave station equipment information table, the communication master station device can perform unified management on each communication slave station device; the communication master station device can determine the device number that sends the protocol data according to the address of the protocol data , and then by consulting the communication slave station equipment information table, the protocol type used by the protocol data can be obtained.

本发明与现有技术相比较,具有如下显而易见的突出实质性特点和显著优点:本Compared with the prior art, the present invention has the following obvious outstanding substantive features and significant advantages:

发明在构建RS485总线上的DL/T645-1997、CJ/T188-2004和GB/T19582-2008与TCP网络协议转换的硬件平台上,根据系统配置文件构建了一张通信从站设备信息表,然后采用该通信从站设备信息表定时轮询RS485总线上的各从站设备,并对接收的协议数据包进行解析,最后将解析得到的数据以一定的XML格式(以文本形式)打包成TCP/IP数据包进行远传,从而实现DL/T645-1997、CJ/T188-2004和GB/T19582-2008通信协议与TCP网络协议之间的转换。The invention builds a hardware platform for converting DL/T645-1997, CJ/T188-2004, GB/T19582-2008 and TCP network protocol on the RS485 bus, builds a communication slave station equipment information table according to the system configuration file, and then Use the communication slave station device information table to periodically poll each slave station device on the RS485 bus, and analyze the received protocol data packet, and finally pack the parsed data into a TCP/ IP data packets are transmitted remotely to realize the conversion between DL/T645-1997, CJ/T188-2004 and GB/T19582-2008 communication protocols and TCP network protocols.

附图说明Description of drawings

图1是本发明实施例的硬件框图。Fig. 1 is a hardware block diagram of an embodiment of the present invention.

图2是本发明实施例的主程序框图。Fig. 2 is a main program block diagram of the embodiment of the present invention.

图3是本发明实施例的通信从站设备信息表。Fig. 3 is a communication slave station device information table according to the embodiment of the present invention.

图4是本发明实施例的协议转换程序框图。Fig. 4 is a program block diagram of protocol conversion in the embodiment of the present invention.

具体实施方式Detailed ways

本发明的优选实施例结合附图详述如下:Preferred embodiments of the present invention are described in detail as follows in conjunction with accompanying drawings:

实施例一:Embodiment one:

参见图1,本RS485总线上的多协议与TCP网络协议之间的转换方法下行通信采Referring to Fig. 1, the conversion method between the multi-protocol on the RS485 bus and the TCP network protocol downlink communication adopts

用RS485总线通过RS485接口与微处理器连接,上行通信采用微处理器通过以太网接口接入互联网,微处理器还连接有NandFlash、SDRAM和SD卡,构建起了协议转换的硬件平台,并采用下述的通信从站设备信息表,实现DL/T645-1997、CJ/T188-2004和GB/T19582-2008通信协议与TCP网络协议之间的转换:通过以太网接口在系统中生成系统配置文件,然后根据该配置文件构建一张通信从站设备信息表,最后采用该通信从站设备信息表定时轮询RS485总线上的各从站设备,并对接收的协议数据包进行解析,将解析得到的数据以一定的XML格式(以文本形式)打包成TCP/IP数据包进行远传。The RS485 bus is connected to the microprocessor through the RS485 interface, and the upstream communication uses the microprocessor to connect to the Internet through the Ethernet interface. The following communication slave station equipment information table realizes the conversion between DL/T645-1997, CJ/T188-2004 and GB/T19582-2008 communication protocols and TCP network protocols: Generate system configuration files in the system through the Ethernet interface , and then construct a communication slave station device information table according to the configuration file, and finally use the communication slave station device information table to regularly poll each slave station device on the RS485 bus, and analyze the received protocol data packet, and get The data is packaged into TCP/IP packets in a certain XML format (in text form) for remote transmission.

实施例二:Embodiment two:

本实施例与实施例一基本相同,特别之处如下:This embodiment is basically the same as Embodiment 1, and the special features are as follows:

所述的系统配置文件包含RS485总线上的通信从站设备的设备编号、设备地址、Described system configuration file comprises the equipment serial number of the communication slave station equipment on the RS485 bus line, equipment address,

协议类型以及以太网接口的数据远传主机的IP地址;所述的通信从站设备信息表是根据系统配置文件生成的,通信从站设备信息表中的信息与RS485总线上连接的通信从站设备一一对应。在同一个RS485总线上允许传输多种协议的数据:DL/T645-1997、CJ/T188-2004和GB/T19582-2008通信协议。所述的通信从站设备信息表,通过该表,通信主站设备可对各通信从站设备进行统一管理;通信主站设备根据协议数据的地址可判断出发送该协议数据的设备编号,再通过查阅通信从站设备信息表,可获得该协议数据所使用的协议类型。Protocol type and the IP address of the data far-transmission host computer of Ethernet interface; The described communication slave station device information table is generated according to the system configuration file, and the information in the communication slave station device information table is connected with the communication slave station connected on the RS485 bus One-to-one correspondence between devices. On the same RS485 bus, it is allowed to transmit data of multiple protocols: DL/T645-1997, CJ/T188-2004 and GB/T19582-2008 communication protocols. The communication slave station equipment information table, through this table, the communication master station equipment can carry out unified management to each communication slave station equipment; The communication master station equipment can judge the equipment number that sends the protocol data according to the address of the protocol data, and then The protocol type used by the protocol data can be obtained by consulting the communication slave station device information table.

实施例三:Embodiment three:

参见图2,本RS485总线上的多协议与TCP网络协议之间的转换方法具体操作步骤:Referring to Fig. 2, the conversion method between the multi-protocol and the TCP network protocol on the RS485 bus concrete operation steps:

一、微处理器初始化;1. Microprocessor initialization;

二、操作系统初始化;2. Operating system initialization;

三、通过以太网接口生成系统配置文件;3. Generate system configuration files through the Ethernet interface;

为了让通信主站设备设置知道通信从站设备的地址、通信协议以及进行TCP网络In order to let the communication master device set know the address of the communication slave device, the communication protocol and the TCP network

传输时目的主机的IP地址等信息,需要通过通信主站设备对整个系统做一个系统配置。此处,可以通过嵌入式Web的形式将系统的配置信息(通信从站设备编号、通信从站设备地址、通信从站设备所使用的协议类型、通信从站设备所连接总线和TCP通信时目的主机IP等)写入到一个XML文件中。其中,XML文件的格式为:When transferring information such as the IP address of the destination host, it is necessary to configure the entire system through the communication master station equipment. Here, the system configuration information (communication slave station device number, communication slave station device address, protocol type used by the communication slave station device, bus connected to the communication slave station device, and TCP communication purpose host IP, etc.) into an XML file. Among them, the format of the XML file is:

<?xml version="1.0" encoding="utf-8" ?><?xml version="1.0" encoding="utf-8" ?>

<config><config>

<common><common>

<gateway_id>08</gateway_id ><gateway_id>08</gateway_id>

<socket port=”5000”>59.79.2.35</socket><socket port=”5000”>59.79.2.35</socket>

</common></common>

<RS485_0><RS485_0>

<meter id="0001" type=”10” protocol=”1”>01020304050607</meter><meter id="0001" type="10" protocol="1">01020304050607</meter>

<meter id="0002" type=”30” protocol=”2”>01020304050608</meter><meter id="0002" type="30" protocol="2">01020304050608</meter>

</ RS485_0></RS485_0>

<RS485_1><RS485_1>

<meter id="0003" type=”40” protocol=”3”>01020304050609</meter><meter id="0003" type="40" protocol="3">01020304050609</meter>

</ RS485_1></RS485_1>

</config></config>

其中,“59.79.2.35”代表数据中心(或数据中转站)的IP地址,id代表通信从站设备编号,type代表通信从站设备类型,protocol代表通信从站设备所使用的通信协议,“01020304050607”代表通信从站设备的地址。Among them, "59.79.2.35" represents the IP address of the data center (or data transfer station), id represents the communication slave device number, type represents the communication slave device type, protocol represents the communication protocol used by the communication slave device, "01020304050607 "Represents the address of the communication slave device.

四、构建通信从设备信息表4. Build communication slave device information table

由于通信主站设备与通信从站设备之间的通信是由处理器软件控制实现的,通信Since the communication between the communication master device and the communication slave device is realized by the control of the processor software, the communication

主站设备要与通信从站设备进行通信,首先需要通过程序读取系统的配置信息,获得通信从In order for the master device to communicate with the communication slave device, it first needs to read the configuration information of the system through the program to obtain the communication slave device.

站设备的地址、通信协议等相关信息,然后,根据读取的系统配置信息,建立一个通信从站Station device address, communication protocol and other related information, and then, according to the read system configuration information, establish a communication slave station

设备信息表,该信息表是一个结构体数组:struct meter Dev[SIZE](SIZE为实际挂接在RS485总线上的通信从站设备的数量),数组的每一个节点记录的是一个通信从站设备的信息,该信息包括通信从站设备编号、通信从站设备地址、通信从站设备所使用的协议类型、通信从站设备所连接总线等,参见图3。其中,该结构体为:Device information table, which is a structure array: struct meter Dev[SIZE] (SIZE is the number of communication slave devices actually connected to the RS485 bus), each node of the array records a communication slave station The information of the device, the information includes the communication slave device number, the communication slave device address, the protocol type used by the communication slave device, the bus connected to the communication slave device, etc., see Figure 3. Among them, the structure is:

struct meter{struct meter {

char num[5];//从站设备编号char num[5];//Slave device number

char port;//从站设备所挂接的RS485总线char port;//RS485 bus connected to the slave device

char protocol;//从站设备所使用的协议类型char protocol;//The protocol type used by the slave device

char metertype;//从站设备类型char metertype;//Slave station device type

unsigned char addr[7];//从站设备地址unsigned char addr[7];//slave device address

};};

其中,protocol为从站设备所使用的协议类型:Among them, protocol is the protocol type used by the slave device:

0x01: DL/T645-1997协议0x01: DL/T645-1997 protocol

0x02: CJ/T188-2004协议0x02: CJ/T188-2004 protocol

0x03: GB/T19582-2008协议0x03: GB/T19582-2008 protocol

五、根据读取的系统配置信息,分别初始化RS485接口和TCP网络;5. Initialize the RS485 interface and TCP network respectively according to the read system configuration information;

六、定时轮询各通信从站设备6. Periodically poll each communication slave station equipment

通信主站设备查询通信从站设备信息表,确定各通信从站设备所使用的通信协议和地址等相关信息,然后定时轮询各通信从站设备,各通信从站设备根据通信主站设备发出的请求数据包做出响应,通信主站设备接收通信从站设备的应答数据包,具体的通信过程如图 4所示。The communication master station device queries the communication slave station device information table, determines the communication protocol and address and other related information used by each communication slave station device, and then regularly polls each communication slave station device, and each communication slave station device sends out the information according to the communication master station device. The request data packet responds, and the communication master device receives the response data packet from the communication slave device. The specific communication process is shown in Figure 4.

七、协议转换7. Protocol Conversion

通信主站设备根据通信从设备所使用的通信协议,解析通信从站设备的协议数据包,从数据包中提取出用电量、用水量或热冷量等信息,然后,通信主站设备将从站设备地址、能耗类型和用电量(或用水量、热冷量)等信息以一定的XML格式(以文本形式)打包成TCP/IP数据包进行远传,从而实现RS485总线上的多协议(DL/T645-1997协议、CJ/T188-2004协议和GB/T19582-2008协议)与TCP网络协议之间的转换。对于XML格式,可参考《国家机关办公建筑和大型公共建筑能耗监测系统分项能耗数据传输技术导则》,具体的XML格式为:According to the communication protocol used by the communication slave device, the communication master station device analyzes the protocol data packet of the communication slave station device, and extracts information such as power consumption, water consumption or heating and cooling capacity from the data packet, and then the communication master station device will Information such as slave station device address, energy consumption type and power consumption (or water consumption, heating and cooling capacity) is packaged into TCP/IP data packets in a certain XML format (in text form) for remote transmission, so as to realize communication on the RS485 bus Conversion between multi-protocol (DL/T645-1997 protocol, CJ/T188-2004 protocol and GB/T19582-2008 protocol) and TCP network protocol. For the XML format, please refer to the "Technical Guidelines for Transmission of Sub-item Energy Consumption Data Transmission of the Energy Consumption Monitoring System of State Organs' Office Buildings and Large Public Buildings". The specific XML format is:

<?xml version="1.0" encoding="utf-8" ?><?xml version="1.0" encoding="utf-8" ?>

<root><root>

<!-- 通用部分 --><!-- General part -->

<!--<!--

building_id:楼栋编号building_id: building number

gateway_id:主站设备编号gateway_id: master device number

type:远传数据包的类型type: the type of remote data packet

-->-->

<common><common>

<building_id>XXXXXX</building_id ><building_id>XXXXXX</building_id>

<gateway_id>XXX</gateway_id ><gateway_id>XXX</gateway_id>

<type>report</type><type>report</type>

</common></common>

<!-- 数据远传 --><!-- Data remote transmission -->

<!--<!--

元素有5种类型There are 5 types of elements

sequence元素:采集器向服务器发送数据的序号sequence element: the serial number of the data sent by the collector to the server

parser元素:向服务器发送的数据是否经采集器解析过parser element: whether the data sent to the server has been parsed by the collector

time元素:数据采集时间time element: data collection time

meter元素:从站设备的设备号,具有id属性meter element: the device number of the slave device, with an id attribute

function元素:每个从站设备的具体功能,具有下列3种属性,function element: the specific function of each slave device, with the following three attributes,

id属性:从站设备的功能编号(供多功能电能表使用)id attribute: the function number of the slave station device (for use by the multi-function electric energy meter)

coding属性:能耗数据分类/分项编码coding attribute: energy consumption data classification/sub-item coding

error属性:该功能出现错误的状态码,0表示没有错误error attribute: the error status code of this function, 0 means no error

-->-->

<data operation=" reply "><data operation="reply">

<sequence>XXXXXXXX</sequence><sequence>XXXXXXXX</sequence>

<parser>yes/no</parser><parser>yes/no</parser>

<time> YYYYMMDDHHMMSS </time><time>YYYYMMDDHHMMSS</time>

<meter id="1"><meter id="1">

<function id="1" coding="XXX" error="XXX">数据1</function><function id="1" coding="XXX" error="XXX">Data 1</function>

</meter></meter>

<meter id="2"><meter id="2">

<function id="1" coding="XXX" error="XXX">数据1</function><function id="1" coding="XXX" error="XXX">Data 1</function>

</meter></meter>

</data></data>

</root></root>

Claims (6)

1. the conversion method between multi-protocols and TCP procotols in a kind of RS485 buses, it is characterised in that:Downlink communication It is connect with microprocessor by RS485 interfaces using RS485 buses, uplink communication is connect using microprocessor by Ethernet interface Enter internet, microprocessor is also associated with NandFlash, SDRAM and SD card, has built the hardware platform of protocol conversion, tool Body implementation steps are as follows:
(1) microprocesser initialization;
(2) operating system initialization;
(3) system configuration file is generated by Ethernet interface;
(4) a communication slave station equipment information table is built according to the configuration file of step (3);
(5) RS485 interfaces and TCP networks are initialized according to the configuration file of step (3) respectively;
(6) each slave station in RS485 bus timing poll RS485 buses is passed through from facility information table according to the communication of step (4) Equipment, and the protocol data of reception is parsed, the data for finally obtaining parsing are with certain XML format --- with text Form is packaged into TCP/IP data packets and carries out teletransmission, to realize between the multi-protocols in RS485 buses and TCP procotols Conversion;
1) according to system configuration file, timer is set;
2) after timing arrives, communication main station equipment is connected according in the RS485 buses recorded in communication slave station equipment information table The relevant information of slave station equipment is communicated, successively each communication slave station equipment of poll;
3) protocol data for receiving communication slave station equipment, according to the facility information analysis protocol data in information table.
2. the conversion method between multi-protocols and TCP procotols in RS485 buses as described in claim 1, feature It is:The specific method of generation system configuration file in the step (3):It will be connected to by the form of embedded Web logical The information such as device numbering, device address, the protocol type of each communication slave station equipment of letter master device are written to one in system In a XML file, to generate a system configuration file.
3. the conversion method between multi-protocols and TCP procotols in RS485 buses as described in claim 1, feature It is:Communication slave station equipment information table in the step (4) is the chained list or array of a structure type, the chained list or number The relevant information of one communication slave station equipment of each nodes records of group, these information include that communication slave station equipment is connected The ports RS485, communication slave station equipment type, the used agreement of communication slave station equipment and communication slave station equipment device number.
4. the conversion method between multi-protocols and TCP procotols in RS485 buses as described in claim 1, feature It is:Device numbering of the system configuration file comprising the communication slave station equipment in RS485 buses, device address, agreement The IP address of the data remote host of type and Ethernet interface;The communication slave station equipment information table is matched according to system File generated is set, it is a pair of to communicate the communication slave station equipment one connected in information and RS485 buses in slave station equipment information table It answers.
5. the conversion method between multi-protocols and TCP procotols in RS485 buses as described in claim 1, feature It is:Allow the data for transmitting various protocols in the same RS485 buses:DL/T645-1997, CJ/T188-2004 and GB/ T19582-2008 communication protocols.
6. the conversion method between multi-protocols and TCP procotols in RS485 buses as described in claim 1, feature It is:The communication slave station equipment information table, by the table, communication main station equipment can carry out each communication slave station equipment unification Management;Communication main station equipment can determine whether out the device numbering of transmission protocol data according to the address of protocol data, then pass through access Slave station equipment information table is communicated, protocol type used in protocol data is can get.
CN201510159994.6A 2015-04-07 2015-04-07 A kind of conversion method between multi-protocols and TCP procotols in RS485 buses Active CN104796415B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510159994.6A CN104796415B (en) 2015-04-07 2015-04-07 A kind of conversion method between multi-protocols and TCP procotols in RS485 buses

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510159994.6A CN104796415B (en) 2015-04-07 2015-04-07 A kind of conversion method between multi-protocols and TCP procotols in RS485 buses

Publications (2)

Publication Number Publication Date
CN104796415A CN104796415A (en) 2015-07-22
CN104796415B true CN104796415B (en) 2018-10-23

Family

ID=53560927

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510159994.6A Active CN104796415B (en) 2015-04-07 2015-04-07 A kind of conversion method between multi-protocols and TCP procotols in RS485 buses

Country Status (1)

Country Link
CN (1) CN104796415B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109374841A (en) * 2018-12-14 2019-02-22 安徽芯核防务装备技术股份有限公司 A kind of method and apparatus of the interior inflammable volatilization gas concentration of monitoring of bus

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105182827A (en) * 2015-09-17 2015-12-23 山东钢铁股份有限公司 Embedded-information-terminal-based application system in HMI
CN105491017B (en) * 2015-11-23 2018-05-15 泰华智慧产业集团股份有限公司 The more equipment multi-protocol analysis method and system of RS485 buses
CN105959288A (en) * 2016-05-27 2016-09-21 姹や寒 Network protocol conversion method for power grid system and intercommunication method of power grid system
CN110601892B (en) * 2019-09-18 2022-04-29 南方电网科学研究院有限责任公司 Main module access method, device and equipment based on object-oriented protocol
CN111143268B (en) * 2019-12-31 2021-08-31 苏州联视泰电子信息技术有限公司 RS-485 bus-based communication method for distributed data acquisition and transmission system
CN111800394B (en) * 2020-06-16 2023-03-07 深圳市三旺通信股份有限公司 TRDP and Modbus-based protocol conversion gateway method
CN111935196B (en) * 2020-10-13 2021-03-23 之江实验室 Protocol conversion method of Modbus and dnp3 based on EdgeX Foundation
CN113438144A (en) * 2021-06-30 2021-09-24 珠海格力电器股份有限公司 Ethernet bus data acquisition system, method, storage medium and computer equipment
CN114301995B (en) * 2021-12-30 2023-07-18 上海交通大学 System and method for conversion, switching and intercommunication fusion of real-time industrial Ethernet protocol

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN2569460Y (en) * 2002-09-12 2003-08-27 刘曙生 Industrial ether net and R232/RS485/can converting card based on DSP
CN1482782A (en) * 2003-06-20 2004-03-17 上海大学 Protocol Conversion Method and Device Between MODBUS/TCP Industrial Ethernet and DeviceNet Fieldbus
CN2705957Y (en) * 2004-06-07 2005-06-22 上海电器科学研究所(集团)有限公司 On-site bus communication protocol switching interface module
CN1645852A (en) * 2004-12-15 2005-07-27 上海大学 Agreement converting method and device between MODBUS/TCP industrial Ethernet and PROFIBUS-DP bus on-the-spot
CN1697448A (en) * 2005-04-21 2005-11-16 上海大学 Multi-protocol conversion method and device between MODBUS/TCP industrial Ethernet, equipment network field bus and Profibus DP field bus
CN201118612Y (en) * 2007-11-23 2008-09-17 江苏斯菲尔电气有限公司 Network communication controller with multiple uplink interface communication mode
CN101388889A (en) * 2008-10-23 2009-03-18 上海大学 A conversion method between multi-protocol buses
CN101483663A (en) * 2008-01-10 2009-07-15 宝山钢铁股份有限公司 Automatic meter reading system and automatic meter reading method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7062718B2 (en) * 2001-08-14 2006-06-13 National Instruments Corporation Configuration diagram which graphically displays program relationship

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN2569460Y (en) * 2002-09-12 2003-08-27 刘曙生 Industrial ether net and R232/RS485/can converting card based on DSP
CN1482782A (en) * 2003-06-20 2004-03-17 上海大学 Protocol Conversion Method and Device Between MODBUS/TCP Industrial Ethernet and DeviceNet Fieldbus
CN2705957Y (en) * 2004-06-07 2005-06-22 上海电器科学研究所(集团)有限公司 On-site bus communication protocol switching interface module
CN1645852A (en) * 2004-12-15 2005-07-27 上海大学 Agreement converting method and device between MODBUS/TCP industrial Ethernet and PROFIBUS-DP bus on-the-spot
CN1697448A (en) * 2005-04-21 2005-11-16 上海大学 Multi-protocol conversion method and device between MODBUS/TCP industrial Ethernet, equipment network field bus and Profibus DP field bus
CN201118612Y (en) * 2007-11-23 2008-09-17 江苏斯菲尔电气有限公司 Network communication controller with multiple uplink interface communication mode
CN101483663A (en) * 2008-01-10 2009-07-15 宝山钢铁股份有限公司 Automatic meter reading system and automatic meter reading method
CN101388889A (en) * 2008-10-23 2009-03-18 上海大学 A conversion method between multi-protocol buses

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
《Modbus协议的RS485总线通讯机的设计及应用》;王书根等;《总线与网络》;20111231;全文 *
《基于RS-485主从通信协议的改进》;周建章等;《测试测量技术》;20111231;全文 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109374841A (en) * 2018-12-14 2019-02-22 安徽芯核防务装备技术股份有限公司 A kind of method and apparatus of the interior inflammable volatilization gas concentration of monitoring of bus

Also Published As

Publication number Publication date
CN104796415A (en) 2015-07-22

Similar Documents

Publication Publication Date Title
CN104796415B (en) A kind of conversion method between multi-protocols and TCP procotols in RS485 buses
CN103365286A (en) Integrated communication control system for intelligent building
CN110213677A (en) Intelligent low-power consumption multi-functional energy table design method based on LoRa
CN104580245B (en) A kind of 104 packet parsing system of distribution terminal and its analytic method
CN106131028B (en) A kind of data transmission method of Free-port communication gateway
CN204465578U (en) Comprehensive information collection gateway
CN102427417A (en) System and method for remotely controlling access equipment of Internet of things
CN109688102A (en) Intelligent energy gateway-based multi-energy acquisition system and multi-energy acquisition method thereof
CN114023053B (en) Terminal energy data acquisition system and method based on HPLC and Bluetooth
CN206378987U (en) Electric power data acquisition system based on Beidou communication technology
CN102438017B (en) Routing function-based conversion apparatus of Modbus protocol and BACnet Ethernet protocol and conversion method thereof
CN107547475A (en) A kind of data processing equipment and its system for supporting more communication protocol conversions
CN106297258A (en) Low voltage electric network kilowatt meter reading-out system based on HomePlug AV
Hui et al. Design and application of communication gateway of EPA and MODBUS on electric power system
CN107171916B (en) Special 4G wireless intelligent network bridge for remote monitoring of industrial metering pump
CN206775651U (en) A kind of intelligent converter based on power line carrier
CN103023895B (en) The data transfer device of Zigbee protocol and GOOSE agreement during a kind of small power station IED nets
CN204632087U (en) Electric energy information collection and monitoring system based on Internet of things
Di Leo et al. Towards visual smart metering exploiting wM-Bus and DLMS/COSEM
CN211294145U (en) Module based on low-power-consumption multi-communication-mode integration
CN109120063A (en) A kind of plug &amp; play sensor monitoring method and its system and acquisition unit
TWM608116U (en) Signal transmission device
CN217741733U (en) Internet of things gateway equipment and Internet of things monitoring system
CN106789172B (en) A distribution network communication system
CN201464583U (en) On-line Monitoring System of Power Quality Based on Transparent Forwarding Technology

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
EXSB Decision made by sipo to initiate substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant