CN110417764B - Method and apparatus for transmitting and receiving data, data transmission apparatus and storage medium - Google Patents
Method and apparatus for transmitting and receiving data, data transmission apparatus and storage medium Download PDFInfo
- Publication number
- CN110417764B CN110417764B CN201910654214.3A CN201910654214A CN110417764B CN 110417764 B CN110417764 B CN 110417764B CN 201910654214 A CN201910654214 A CN 201910654214A CN 110417764 B CN110417764 B CN 110417764B
- Authority
- CN
- China
- Prior art keywords
- data
- field
- registers
- modbus
- byte
- 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
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
- H04L67/1074—Peer-to-peer [P2P] networks for supporting data block transmission mechanisms
- H04L67/1078—Resource delivery mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/12—Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/163—In-band adaptation of TCP data exchange; In-band control procedures
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/22—Parsing or analysis of headers
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Health & Medical Sciences (AREA)
- Computing Systems (AREA)
- General Health & Medical Sciences (AREA)
- Medical Informatics (AREA)
- Communication Control (AREA)
Abstract
The embodiment of the invention discloses a method and a device for sending data and a method and a device for receiving data. The method is applicable to an environmental and equipment monitoring system (BAS), and comprises: receiving a Modbus reading message containing register number from a rail transit integrated monitoring system (ISCS); generating a Modbus reply message containing a first field, a second field and a data field, writing length information from a current byte to a last byte determined based on the number of registers in the first field, and writing data determined based on the number of registers in the data field, wherein when the number of registers is greater than the maximum number of registers supported by a Modbus protocol, a predetermined identifier is written in the second field; sending the reply message to the ISCS; wherein when the ISCS detects the predetermined identification in the second field, data is read from the data field based on the length information. A large amount of communication between the BAS and the ISCS can be achieved.
Description
Technical Field
The invention relates to the technical field of rail transit, in particular to a method and a device for sending data and a method and a device for receiving data.
Background
The definition of the environment and equipment monitoring System (BAS) is as follows: the system can be used for centralized monitoring, controlling and managing the environmental and air conditions, ventilation, water supply and drainage, illumination, passenger guidance, escalators, elevators, shielded doors, flood gates and other building equipment and systems in subway buildings. The BAS adopts technologies such as computer network, automatic control, communication, distributed intelligence and the like to realize a control management mode of a subway environment and an equipment system, and performs comprehensive operation management and control on electromechanical equipment such as air conditioning ventilation, water supply and drainage, illumination, an electric/escalator, a safety door and the like in a subway station and an inter-zone tunnel.
The Integrated Supervisory Control System (ISCS) for rail transit can realize the basic functions of real-time centralized monitoring and Control of broadcasting information and clock information of power equipment, fire alarm information and equipment thereof, station environmental Control equipment, section environmental Control equipment, environmental parameters, shielded door equipment, flood gate prevention equipment, escalator equipment, lighting equipment, access Control equipment, automatic ticket selling and checking equipment, broadcasting and closed-circuit television equipment and passenger information display systems, and can also realize the advanced functions of coordination and interaction among various related System equipment under the night non-operation condition, the daytime normal operation condition, the emergency condition and the important equipment failure condition.
Currently, communication between the ISCS and the BAS is usually achieved based on the Modbus TCP standard protocol. The Modbus TCP standard protocol uses a TCP/IP mechanism and Ethernet to transfer data between the ISCS and the BAS.
In the current Modbus TCP standard protocol, one byte (byte) is used to indicate the number of registers in a message. However, one byte can only satisfy the communication of 125 registers at most, and cannot realize one-time large-quantity transmission, and cannot satisfy the large-quantity communication requirement between the BAS and the ISCS.
Disclosure of Invention
The embodiment of the invention provides a method and a device for sending data and a method and a device for receiving data, so as to realize large-quantity communication between BAS and ISCS.
The technical scheme of the embodiment of the invention is as follows:
a method of transmitting data, the method being adapted for a BAS, the method comprising:
receiving a Modbus reading message containing the number of registers from the ISCS;
generating a Modbus reply message containing a first field, a second field and a data field, writing length information from a current byte to a last byte determined based on the number of registers in the first field, and writing data determined based on the number of registers in the data field, wherein when the number of registers is greater than the maximum number of registers supported by a Modbus protocol, a predetermined identifier is written in the second field;
sending the reply message to the ISCS;
wherein when the ISCS detects the predetermined identification in the second field, data is read from the data field based on the length information.
It can be seen that, unlike the prior art that the number of bytes corresponding to the number of registers is strictly written in the second field, in the embodiment of the present invention, when the number of registers is greater than the maximum number of registers supported by the Modbus protocol, the number of bytes corresponding to the number of registers is not written in the second field, but a predetermined flag is written in the second field, so that when the predetermined flag is detected in the second field by the ISCS, data is read from the data field based on the length information, and mass data transmission is realized.
In one embodiment, when the number of registers is less than or equal to the maximum number of registers supported by a Modbus protocol, writing the number of bytes corresponding to the number of registers in the second field;
wherein when the ISCS does not detect the predetermined identification in the second field, data is read from the data field based on the number of bytes.
Therefore, when the number of registers is less than or equal to the maximum number of registers supported by the Modbus protocol, the BAS still writes the number of bytes corresponding to the number of registers in the second field, and the ISCS still reads data based on the number of bytes in the second field, thereby being well compatible with the existing Modbus TCP standard protocol.
In one embodiment, the Modbus read message further includes a start address;
the writing data determined based on the number of registers in a data field includes:
reading data by taking the starting address as a reading starting position and the register number as a reading register number;
writing the read data in the data field.
Therefore, the Modbus read message can also contain a starting address, and is well compatible with the existing Modbus TCP standard protocol.
An apparatus for transmitting data, the apparatus being disposed in a BAS, the apparatus comprising:
the receiving module is used for receiving a Modbus reading message containing the number of registers from the ISCS;
the generating module is used for generating a Modbus reply message containing a first field, a second field and a data field, writing length information from a current byte to a last byte determined based on the number of registers in the first field, and writing data determined based on the number of registers in the data field, wherein when the number of registers is greater than the maximum number of registers supported by a Modbus protocol, a predetermined identifier is written in the second field;
a sending module, configured to send the reply packet to the ISCS;
wherein when the ISCS system detects the predetermined identification in the second field, data is read from the data field based on the length information.
It can be seen that, unlike the prior art that the number of bytes corresponding to the number of registers is strictly written in the second field, in the embodiment of the present invention, when the number of registers is greater than the maximum number of registers supported by the Modbus protocol, the number of bytes corresponding to the number of registers is not written in the second field, but a predetermined flag is written in the second field, so that when the predetermined flag is detected in the second field by the ISCS, data is read from the data field based on the length information, and mass data transmission is realized.
In one embodiment, the generating module is further configured to write a number of bytes corresponding to the number of registers in the second field when the number of registers is less than or equal to a maximum number of registers supported by a Modbus protocol;
wherein when the ISCS does not detect the predetermined identification in the second field, data is read from the data field based on the number of bytes.
Therefore, when the number of registers is less than or equal to the maximum number of registers supported by the Modbus protocol, the number of bytes corresponding to the number of registers is still written in the second field, and the ISCS still reads data based on the number of bytes in the second field, so that the existing Modbus TCP standard protocol is well compatible.
In one embodiment, the Modbus read message further includes a start address;
the generating module is used for reading data by taking the starting address as a reading starting position and the register number as a reading register number; writing the read data in the data field.
Therefore, the Modbus read message can also contain a starting address, and is well compatible with the existing Modbus TCP standard protocol.
A method of receiving data, the method being applicable to a BAS, the method comprising:
receiving a Modbus write message containing a first field, a second field and a data field from an ISCS (inter-Communication System), wherein the first field contains a register number, the data field contains data, the second field contains a preset identification when the register number is larger than the maximum register number supported by a Modbus protocol, and the second field contains the byte number corresponding to the register number when the register number is smaller than or equal to the maximum register number supported by the Modbus protocol;
data is retrieved from the data field based on the number of registers extracted from the first field.
It can be seen that, unlike the prior art that the number of bytes corresponding to the number of registers is strictly written in the second field, in the embodiment of the present invention, when the number of registers is greater than the maximum number of registers supported by the Modbus protocol, the number of bytes corresponding to the number of registers is not written in the second field, but a predetermined flag is written in the second field, so that the limitation of the byte number field of one byte size on the written data is well avoided. Moreover, the BAS does not acquire data based on the second field, but acquires data based on the number of registers in the first field, and mass data transfer can be realized.
In one embodiment, the Modbus write message further includes a start address; the method further comprises the following steps:
and writing the data acquired from the data field by taking the starting address as a writing starting position and the register number as a writing register number.
Therefore, the Modbus write message can also contain a starting address, and is well compatible with the existing Modbus TCP standard protocol.
An apparatus to receive data, the apparatus disposed at a BAS, the apparatus comprising:
the Modbus write message comprises a first field, a second field and a data field, wherein the first field comprises the number of registers, the data field comprises data, the second field comprises a preset identifier when the number of the registers is larger than the maximum number of the registers supported by the Modbus protocol, and the second field comprises the number of bytes corresponding to the number of the registers when the number of the registers is smaller than or equal to the maximum number of the registers supported by the Modbus protocol;
and the acquisition module is used for acquiring data from the data field based on the number of the registers extracted from the first field.
It can be seen that, unlike the prior art that the number of bytes corresponding to the number of registers is strictly written in the second field, in the embodiment of the present invention, when the number of registers is greater than the maximum number of registers supported by the Modbus protocol, the number of bytes corresponding to the number of registers is not written in the second field, but a predetermined flag is written in the second field, so that the limitation of the byte number field of one byte size on the written data is well avoided. Moreover, the BAS does not acquire data based on the second field, but acquires data based on the number of registers in the first field, and mass data transfer can be realized.
In one embodiment, the Modbus write message further includes a start address; the device also includes:
and the writing module is used for writing the data acquired from the data field by taking the starting address as a writing starting position and the register number as a writing register number.
Therefore, the Modbus write message can also contain a starting address, and is well compatible with the existing Modbus TCP standard protocol.
A data transmission device comprising a processor and a memory;
the memory has stored therein an application executable by the processor for causing the processor to perform a method of transmitting data as described in any one of the above, or a method of receiving data as described in any one of the above.
The computer readable storage medium has stored therein computer readable instructions for performing the method of transmitting data as described in any one of the above, or the method of receiving data as described in any one of the above.
A computer program product, stored on a computer-readable storage medium, comprising computer program instructions that, when executed, enable at least one processor to perform a method of transmitting data as defined in any one of the above, or a method of receiving data as defined in any one of the above.
Drawings
Fig. 1 is a flowchart illustrating a method for reading data in a BAS by an ISCS according to an embodiment of the present invention.
Fig. 2 is a block diagram of an apparatus for transmitting data from the BAS to the ISCS according to the embodiment of the present invention.
FIG. 3 is a flowchart illustrating a method for writing data to the BAS by the ISCS according to an embodiment of the present invention.
Fig. 4 is a block diagram of an apparatus for receiving data from an ISCS by the BAS according to an embodiment of the present invention.
Fig. 5 is a block diagram of an apparatus for transmitting data between a BAS and an ISCS according to an embodiment of the present invention.
Wherein the reference numbers are as follows:
reference numerals | Means of |
101~103 | Step (ii) of |
200 | Apparatus for transmitting |
201 | |
202 | |
203 | |
301~303 | Step (ii) of |
400 | Apparatus for receiving |
401 | |
402 | |
403 | Write-in |
500 | |
501 | Processor with a memory having a plurality of |
502 | Memory device |
Detailed Description
In order to make the technical scheme and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the detailed description and specific examples, while indicating the scope of the invention, are intended for purposes of illustration only and are not intended to limit the scope of the invention.
For simplicity and clarity of description, the invention will be described below by describing several representative embodiments. Numerous details of the embodiments are set forth to provide an understanding of the principles of the invention. It will be apparent, however, that the invention may be practiced without these specific details. Some embodiments are not described in detail, but rather are merely provided as frameworks, in order to avoid unnecessarily obscuring aspects of the invention. Hereinafter, "including" means "including but not limited to", "according to … …" means "at least according to … …, but not limited to … … only". In view of the language convention of chinese, the following description, when it does not specifically state the number of a component, means that the component may be one or more, or may be understood as at least one.
The applicant intensively studies the basic principle of the Modbus TCP protocol, and finds that in the Modbus TCP standard protocol, one byte (byte) is used to indicate the number of registers in a message. One byte can only meet the communication of 125 registers at most, and the communication volume between the BAS and the ISCS is often larger than 125 registers, so that the existing Modbus TCP standard protocol cannot meet the requirement of large-volume communication between the BAS and the ISCS.
In order to solve the technical problem of large-quantity communication between the BAS and the ISCS, the applicant partially deforms the Modbus TCP standard protocol, so that the communication quantity limit of 125 registers is broken through, and the large-quantity communication requirement between the BAS and the ISCS is met.
Communication between the BAS and the ISCS includes the following two application scenarios:
(1) the ISCS reads data from the BAS; (2) the ISCS writes data to the BAS.
Based on the embodiment of the invention, aiming at the two application scenes, a large amount of communication between the BAS and the ISCS can be respectively realized.
First, an application scenario in which the ISCS reads data from the BAS is described.
Fig. 1 is a flowchart illustrating a method for reading data in a BAS by an ISCS according to an embodiment of the present invention. The method is suitable for the BAS system, such as a master Programmable Logic Controller (PLC) or a slave PLC which can be applied to the BAS system.
As shown in fig. 1, the method includes:
step 101: and receiving a Modbus reading message containing the number of registers from the ISCS.
Here, the BAS receives a Modbus read message from the ISCS. The Modbus reading message has the same format as the reading message in the Modbus standard protocol. That is to say, compared with the read message in the Modbus standard protocol, the Modbus read message according to the embodiment of the present invention may be read only by writing the register number to be read into the Modbus read message without modifying the format.
Table 1 is a content description table of the Modbus read packet.
TABLE 1
As shown in table 1, the Modbus read packet has a length of 6 words (12 bytes), and includes a header (Map headers), a Function Code (Function Code), a Data (Data) portion, and a verification portion. Wherein:
the header includes a Transaction identifier Hi (Transaction identifier Hi) having a Length of one byte, a Transaction identifier Lo (Transaction identifier Lo) having a Length of one byte, a Protocol identifier (Protocol identifier) having a Length of two bytes, a Length (Length) field having a Length of two bytes, and a device Unit number (Unit identifier) field having a Length of one byte. The length field has length information from the current byte to the last byte described therein.
The function code is 1 byte in length and is used to identify a read operation for a register.
The data part includes a start address (Starting address) field and a Number of registers (registers) field. The initial address field comprises an initial address which is the initial point of the reading operation; the register number field contains the data amount of the read operation, i.e., the number of registers desired to be read.
As can be seen, in the Modbus read message shown in table 1, the register number field of the data portion contains the register number.
Step 102: generating a Modbus reply message containing a first field, a second field and a data field, writing length information from a current byte to a last byte determined based on the number of registers in the first field, and writing data determined based on the number of registers in the data field, wherein when the number of registers is greater than the maximum number of registers supported by the Modbus protocol, a predetermined identification is written in the second field.
In the response message of the Modbus standard protocol, the number of registers in the message is represented by one byte in the byte number field of the data portion, and thus has a disadvantage that the communication of only 125 registers at most can be satisfied.
Here, the first field in the Modbus read message according to the embodiment of the present invention corresponds to the length field in the header of the reply message of the Modbus standard protocol; the second field in the Modbus read message according to the embodiment of the present invention corresponds to a byte Number (bytes) field in the data portion in the reply message of the Modbus standard protocol.
Compared with the reply message in the Modbus standard protocol, the Modbus reply message provided by the embodiment of the invention has the improvement. The improvement comprises: in the Modbus reply message of the embodiment of the present invention, when the Number of registers is greater than the maximum Number of registers supported by the Modbus protocol (i.e., 125 supported by the prior art), a predetermined flag is written in the byte count (Number of bytes) field of the data portion. Preferably, the predetermined flag may be implemented as 0x 00.
Table 2 is a content description table of the Modbus reply packet.
TABLE 2
As shown in table 2, the Modbus reply message includes a header (Map headers), a Function Code (Function Code), a Data (Data) portion, and a verification portion. Wherein:
the header includes a Transaction identifier Hi (Transaction identifier Hi) having a Length of one byte, a Transaction identifier Lo (Transaction identifier Lo) having a Length of one byte, a Protocol identifier (Protocol identifier) having a Length of two bytes, a Length (Length) field having a Length of two bytes, and a device Unit number (Unit identifier) field having a Length of one byte. The length field describes length information from the current byte to the last byte, which is determined based on the number of registers in the Modbus read message, for example, assuming that the number of registers in the Modbus read message is N, the length information is 2 × N +3 (bytes), where "2 × N" is the data byte amount corresponding to the number of registers; "3" is the sum of the device unit number field, the function code, and the number of bytes in the byte number field.
The function code is 1 byte in length and is used to identify a read operation for a register.
The data portion includes a byte Number (bytes) field and a data field. Data determined based on the number of registers included in the Modbus read message is written in the data field. When the number of registers contained in the Modbus read message is greater than the maximum number of registers supported by the Modbus protocol (i.e., 125 supported by the prior art), a predetermined flag is written in the byte count field.
Wherein writing data determined based on the number of registers in the data field comprises: reading data by taking the initial address as a reading initial position and the number of registers as the number of reading registers; the read data is written in the data field.
The reply messages in the Modbus standard protocol have a structure similar to that described in table 2. However, in the reply message in the Modbus standard protocol, the byte number corresponding to the number of registers is strictly written in the byte number field, so that only 255 registers can be written at most, i.e. communication of 125 registers at most is supported. However, in the Modbus reply message of the present application, when the number of registers is greater than the maximum number of registers supported by the Modbus protocol (i.e., 125 supported by the prior art), the number of bytes corresponding to the number of registers is not written in the byte number field, but a predetermined flag is written in the byte number field, so that the limitation of the byte number field of one byte size on the write data is well circumvented.
Step 103: and sending a reply message to the ISCS, wherein when the ISCS detects the predetermined identification in the second field, the data is read from the data field based on the length information.
The BAS sends a reply message to the ISCS after generating the Modbus reply message in step 102. And after receiving the reply message, the ISCS reads data from the data field based on the length information when the predetermined identification is detected in the second field. For example, when the length information is M, it may be determined that the corresponding register size is (M-3)/2. Then, the data of (M-3)/2 registers is read from the data field of the reply message.
Therefore, in the embodiment of the present invention, the ISCS may determine, through the predetermined identifier, that the number of registers is greater than the maximum number of registers supported by the Modbus protocol, and determine the number of registers not based on the byte number field, but based on the length information stored in the second field, thereby satisfying a large amount of communication requirements between the BAS and the ISCS.
In one embodiment, when the number of registers is less than or equal to the maximum number of registers supported by the Modbus protocol, the BAS writes the number of bytes corresponding to the number of registers in the second field in step 102. When the ISCS does not detect the predetermined identification in the second field, reading data from the data field based on the number of bytes
It can be seen that, when the ISCS does not detect the predetermined identifier in the second field, the ISCS can determine that the number of registers is less than or equal to the maximum number of registers supported by the Modbus protocol, and at this time, the ISCS still reads data from the data field based on the number of bytes in the byte number field, so as to be well compatible with the existing Modbus TCP standard protocol.
The following describes an exemplary embodiment of the present invention, taking the example that a front-end server in the ISCS reads data from a master PLC in the BAS.
The front-end processor server sends Modbus reading messages shown in a table 1 to the master PLC. The read packet has 12 bytes, specifically: the 1 st word (one word comprises two bytes) is a message identification number and comprises a transaction identification high bit of the first byte and a transaction identification low bit of the second byte; the third byte and the fourth byte are protocol identifiers, and the content is 0X 0000; the fifth byte and the sixth byte contain the byte number from the current position to the end of the message; the seventh byte is the device unit number; the eighth byte is a read command identification (specifically 0X 03); the ninth byte and the tenth byte are initial addresses for the front-end server to read the main-end PLC data; the eleventh byte and the twelfth byte are the number of registers for reading data in the master PLC by the front-end server.
The master PLC receives a Modbus reading message sent by the front-end processor server, receives the first 6 bytes of data of the Modbus reading message, and stores the first 6 bytes of data into a data receiving block. And the master PLC receives the message with the subsequent length to the subsequent position in the received data block according to the content (the number of bytes from the current position to the end of the message) of the fifth byte and the sixth byte.
The master PLC judges the range of the communication data area planned by the master PLC according to the starting addresses in the ninth byte and the tenth byte in the received data block and the register numbers (namely the length of the read data) in the eleventh byte and the twelfth byte, wherein:
(1) and when the master PLC finds that the read data length exceeds the range of the communication data area planned by the master PLC, the master PLC generates a communication command error message and returns the communication command error message to the front-end processor server.
(2) When the master PLC finds that the read data length does not exceed the range of a communication data area planned by the master PLC, the master PLC copies the contents of a first byte, a second byte, a third byte and a fourth byte in a received data block to corresponding positions of a Modbus reply message, fills length information from a current byte to a last byte determined based on the number of registers in the Modbus read message into the fifth byte and the sixth byte of the Modbus reply message (for example, if the number of the registers in the Modbus read message is N, the length information is 2 xN +3 (bytes)), fills a device unit number into the seventh byte of the Modbus reply message, and fills a function code into the eighth byte; wherein: if the data length of the master PLC read by the front-end processor server is less than or equal to 125 registers, filling the ninth byte of the Modbus reply message with the byte number corresponding to the register number (for example, if the register number in the Modbus read message is M, the byte number is 2 × M); if the data length of the master PLC read by the front-end processor server is larger than 125 registers, filling a preset mark (for example, 0X00) in the ninth byte of the Modbus reply message, sequentially writing data with the corresponding data length starting from the initial address, which are copied from the communication data area planned by the BAS, in the subsequent content of the Modbus reply message, and sending the Modbus reply message to the front-end processor server.
When the front-end processor server receives the communication command error message, an alarm communication error is reported on a human-machine interaction interface (HMI). When the front-end processor server receives the Modbus reply message, if a preset mark can be detected in the ninth byte of the Modbus reply message, reading data based on the length information in the fifth byte and the sixth byte of the Modbus reply message and storing the data in the database, and if the preset mark cannot be detected in the ninth byte of the Modbus reply message, reading the data based on the byte number in the ninth byte of the Modbus reply message and storing the data in the database.
The above example of the ISCS reading data from the BAS is described as an example of the front-end server reading data from the master PLC, and it can be appreciated by those skilled in the art that this description is only exemplary and is not intended to limit the scope of the embodiments of the present invention.
The embodiment of the invention also provides a device for sending data to the ISCS by the BAS.
Fig. 2 is a block diagram of an apparatus for transmitting data from the BAS to the ISCS according to the embodiment of the present invention. The device is deployed in a BAS, such as may be deployed to an ethernet communications module of a master PLC or to an ethernet communications module of a slave PLC.
As shown in fig. 2, the apparatus 200 includes:
a receiving module 201, configured to receive a Modbus read packet including the number of registers from the ISCS;
the generating module 202 is configured to generate a Modbus reply packet including a first field, a second field, and a data field, write length information from a current byte to a last byte, which is determined based on the number of registers, in the first field, write data, which is determined based on the number of registers, in the data field, where when the number of registers is greater than a maximum number of registers supported by a Modbus protocol, a predetermined identifier is written in the second field;
a sending module 203, configured to send a reply message to the ISCS;
wherein when the ISCS detects the predetermined identification in the second field, data is read from the data field based on the length information.
In one embodiment, the generating module 202 is further configured to, when the number of registers is less than or equal to the maximum number of registers supported by the Modbus protocol, write a number of bytes corresponding to the number of registers in the second field; wherein when the ISCS does not detect the predetermined identification in the second field, data is read from the data field based on the number of bytes.
In one embodiment, the Modbus read message further includes a start address; a generating module 202, configured to read data by using the start address as a read start position and the number of registers as a read register number; the read data is written in the data field.
An application scenario for writing data to the BAS by the ISCS is described below.
FIG. 3 is a flowchart illustrating a method for writing data to the BAS by the ISCS according to an embodiment of the present invention. The method is suitable for the BAS, and can be applied to a main end PLC in a BAS system.
As shown in fig. 3, the method includes:
arrangement 301: and receiving a Modbus write message containing a first field, a second field and a data field from the ISCS, wherein the first field contains the number of registers, the data field contains data, the second field contains a preset identifier when the number of registers is greater than the maximum number of registers supported by the Modbus protocol, and the second field contains the number of bytes corresponding to the number of registers when the number of registers is less than or equal to the maximum number of registers supported by the Modbus protocol.
Here, the BAS receives a Modbus write message from the ISCS.
In the Write message of the Modbus standard protocol, in the Write byte number (Write bytes number) field of the data part, the number of registers in the message is represented by one byte, and the communication of only 125 registers can be satisfied at most.
Here, the first field in the Modbus Write message according to the embodiment of the present invention corresponds to a Write register number (Write register number) field in the data portion in the Write message of the Modbus standard protocol; the second field in the Modbus Write message of the embodiments of the present invention corresponds to the Write byte number (Write bytes number) field in the data portion of the Write message of the Modbus standard protocol.
Compared with the write-in message in the Modbus standard protocol, the Modbus write-in message provided by the embodiment of the invention has the advantages of improvement. The improvement comprises: in the write message of the embodiment of the present invention, when the Number of registers is greater than the maximum Number of registers supported by the Modbus protocol (i.e., 125 supported by the related art), a predetermined flag is written in the Number of bytes (Number of bytes) field of the data part. Preferably, the predetermined flag may be implemented as 0x 00.
Table 3 is a content description table of the Modbus write message.
TABLE 3
As shown in table 3, the Modbus write message includes a header (Map headers), a Function Code (Function Code), a Data (Data) portion, and a verification portion. Wherein:
the header includes a Transaction identifier Hi (Transaction identifier Hi) having a Length of one byte, a Transaction identifier Lo (Transaction identifier Lo) having a Length of one byte, a Protocol identifier (Protocol identifier) having a Length of two bytes, a Length (Length) field having a Length of two bytes, and a device Unit number (Unit identifier) field having a Length of one byte.
The function code is 1 byte in length and is used to identify a write operation to a register.
The data portion includes a start address (Starting address) field, a Write register number (Write register number) field, and a Write bytes number (Write bytes number) field. The initial address field comprises an initial address which is the initial point of the write operation; the write register number field contains the number of registers for the write operation. When the number of registers is greater than the maximum number of registers supported by the Modbus protocol (i.e., 125 supported by the prior art), a predetermined flag is written in the write byte number field of the data portion. Preferably, the predetermined flag may be implemented as 0x 00. When the number of registers is less than or equal to the maximum number of registers supported by the Modbus protocol (i.e., 125 supported by the prior art), the number of bytes corresponding to the number of registers is written in the write byte number field of the data portion.
The write messages in the Modbus standard protocol have a structure similar to that described in table 3. However, in the write message in the Modbus standard protocol, the number of bytes corresponding to the number of registers is strictly written in the write byte number field of the data portion, so that only 255 registers can be written at most, i.e. communication of 125 registers at most is supported. However, in the Modbus write message of the present application, when the number of registers is greater than the maximum number of registers supported by the Modbus protocol (i.e., 125 supported by the prior art), the number of bytes corresponding to the number of registers is not written in the write byte number field, but a predetermined flag is written, so that the restriction of the one-byte-size byte number field on the write data is well circumvented.
Step 302: data is retrieved from the data field based on the number of registers extracted from the first field.
Here, the BAS system retrieves data from the data field directly based on the number of registers extracted from the first field. That is, data is retrieved from the data field based on the number of registers in the write register number field of Table 3.
It can be seen that, unlike the Modbus standard protocol in which data is obtained from a data field based on the number of bytes in a write byte number field, the embodiment of the present invention is based on the number of registers extracted from the first field, thereby enabling a large amount of communication between the BAS and the ISCS.
In one embodiment, the method further comprises: the BAS system writes the data obtained from the data field with the start address as the write start location and the number of registers as the number of write registers.
In one embodiment, the method further comprises: and after the BAS system writes data, sending a Modbus write response message to the ISCS system.
The Modbus write response message has the same format as the write response message in the Modbus standard protocol. That is to say, compared with the write response packet in the Modbus standard protocol, the format of the Modbus write response packet according to the embodiment of the present invention may not be modified, and only the number of the written registers needs to be filled in the Modbus write response packet.
Table 4 is a content description table of the Modbus write response packet.
TABLE 4
As shown in table 4, the Modbus write response message has a length of 6 words (12 bytes), and includes a header (Map headers), a Function Code (Function Code), a Data (Data) portion, and a verification portion. Wherein:
the header includes a Transaction identifier Hi (Transaction identifier Hi) having a Length of one byte, a Transaction identifier Lo (Transaction identifier Lo) having a Length of one byte, a Protocol identifier (Protocol identifier) having a Length of two bytes, a Length (Length) field having a Length of two bytes, and a device Unit number (Unit identifier) field having a Length of one byte.
The function code is 1 byte in length and is used to identify a write operation to a register.
The data part includes a start address (Starting address) field and a Number of registers (registers) field. The initial address field comprises an initial address which is the initial point of the write operation; the register number field contains the data amount of the write operation, i.e., the number of registers that have been written.
The following describes an exemplary embodiment of the present invention, taking the example of writing data to the master PLC in the BAS by the redundant server in the ISCS.
And the redundant machine server sends a Modbus write-in message shown in a table 3 to the master PLC. The first word (one word comprises two bytes) of the Modbus write message is a message identification number and comprises a transaction identification high bit of the first byte and a transaction identification low bit of the second byte; the third byte and the fourth byte are protocol identifiers, and the content is 0X 0000; the fifth byte message and the sixth byte message contain the byte number from the current position to the end of the message; the seventh byte is the device unit number; the eighth byte is a write command identification (specifically, 0X 16); the ninth byte and the tenth byte are initial addresses of data written into the main end PLC by the redundant machine server; the eleventh byte and the twelfth byte are the number of registers written into the main end PLC by the redundant machine server; when the number of registers written into the main PLC by the redundant machine server is less than or equal to 125, the thirteenth byte is the number of bytes corresponding to the number of registers written into the main PLC by the redundant machine server, for example, if the number of registers written into the main PLC by the redundant machine server is N, the thirteenth byte is written into 2 × N (bytes); when the number of registers written into the main PLC by the redundant machine server is more than 125, the thirteenth byte is a predetermined identifier (for example, 0X 00); the fourteenth byte starts to write the specific data content of the master PLC to the redundant machine server.
The master PLC receives a Modbus write-in message sent by the redundancy machine server, receives the first 6 bytes of data of the Modbus write-in message, and stores the first 6 bytes of data into a received data block. Then, the master PLC receives the message of the subsequent length to the subsequent position in the received data block according to the contents of the fifth byte and the sixth byte (the number of bytes from the current position to the end of the message).
The master PLC judges the range of the communication data area planned by the master PLC according to the starting addresses in the ninth byte and the tenth byte in the received data block and the register numbers (namely the write data length) in the eleventh byte and the twelfth byte, wherein:
(1) and when the master PLC finds that the length of the written data exceeds the range of the communication data area planned by the master PLC, the master PLC generates a communication command error message and returns the communication command error message to the redundant machine server.
(2) And when the master PLC finds that the length of the written data does not exceed the range of the communication data area planned by the master PLC, the master PLC stores all data after receiving the fourteenth byte in the data area into the communication data area planned by the master PLC according to the initial address in the write command. And the master PLC copies the contents of the first byte, the second byte, the third byte and the fourth byte in the received data block to corresponding positions of a Modbus write response message, fills 0x06 in the sixth byte of the Modbus write response message, fills 0x01 in the seventh byte, fills 0x16 in the eighth byte, and fills the initial address and the data length in the Modbus write message in the ninth byte to the twelfth byte respectively, and then sends the Modbus write response message to the redundancy machine server to indicate that the write is successful.
While the above describes the writing of data to the BAS by the ISCS by taking the example of writing data to the primary PLC by the redundant server, those skilled in the art will appreciate that this description is merely exemplary and is not intended to limit the scope of the embodiments of the present invention.
The embodiment of the invention also provides a device for receiving data from the ISCS by the BAS.
Fig. 4 is a block diagram of an apparatus for receiving data from an ISCS by the BAS according to an embodiment of the present invention. The device is deployed in a BAS, such as may be deployed to an ethernet communications module of a master PLC or to an ethernet communications module of a slave PLC.
As shown in fig. 4, the apparatus 400 includes:
a receiving module 401, configured to receive a Modbus write message including a first field, a second field, and a data field from an ISCS, where the first field includes a register number, and the data field includes data, where the second field includes a predetermined identifier when the register number is greater than a maximum register number supported by a Modbus protocol, and the second field includes a byte number corresponding to the register number when the register number is less than or equal to the maximum register number supported by the Modbus protocol;
an obtaining module 402, configured to obtain data from the data field based on the number of registers extracted from the first field.
In one embodiment, the Modbus write message further includes a start address; the apparatus 400 further comprises:
the write module 403 is configured to write the data obtained from the data field with the start address as a write start location and the number of registers as a write register number.
In the above description, specific formats and uses of the Modbus read message, the Modbus reply message, the Modbus write message, and the Modbus write response message according to the embodiment of the present invention are described in detail. It is stated that: the Modbus reading message, the Modbus reply message, the Modbus writing message and the Modbus writing response message of the embodiment of the invention are not necessarily completely consistent with the Modbus standard protocol, but are optimized and improved for the application of the Modbus standard protocol in the field of rail transit.
The embodiment of the invention also provides a data transmission device with a processor and a memory structure.
Fig. 5 is a block diagram of an apparatus for transmitting data between a BAS and an ISCS according to an embodiment of the present invention.
As shown in fig. 5, the apparatus 500 for transmitting data between the BAS and the ISCS includes a processor 501 and a memory 502;
the memory 502 stores an application program executable by the processor 501 for causing the processor 501 to perform a method of transmitting data or a method of receiving data as described in any one of the above.
The memory 502 may be embodied as various storage media such as an Electrically Erasable Programmable Read Only Memory (EEPROM), a Flash memory (Flash memory), and a Programmable Read Only Memory (PROM). The processor 501 may be implemented to include one or more central processors or one or more field programmable gate arrays that integrate one or more central processor cores. In particular, the central processor or central processor core may be implemented as a CPU or MCU.
It should be noted that not all steps and modules in the above flows and system structure diagrams are necessary, and some steps or modules may be omitted according to actual needs. The execution order of the steps is not fixed and can be adjusted as required. The system structure described in the above embodiments may be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by a plurality of physical entities, or some components in a plurality of independent devices may be implemented together.
The hardware modules in the various embodiments may be implemented mechanically or electronically. For example, a hardware module may include a specially designed permanent circuit or logic device (e.g., a special purpose processor such as an FPGA or ASIC) for performing specific operations. A hardware module may also include programmable logic devices or circuits (e.g., including a general-purpose processor or other programmable processor) that are temporarily configured by software to perform certain operations. The implementation of the hardware module in a mechanical manner, or in a dedicated permanent circuit, or in a temporarily configured circuit (e.g., configured by software), may be determined based on cost and time considerations.
The present invention also provides a machine-readable storage medium storing instructions for causing a machine to perform a method as described herein. Specifically, a system or an apparatus equipped with a storage medium on which a software program code that realizes the functions of any of the embodiments described above is stored may be provided, and a computer (or a CPU or MPU) of the system or the apparatus is caused to read out and execute the program code stored in the storage medium. Further, part or all of the actual operations may be performed by an operating system or the like operating on the computer by instructions based on the program code. The functions of any of the above-described embodiments may also be implemented by writing the program code read out from the storage medium to a memory provided in an expansion board inserted into the computer or to a memory provided in an expansion unit connected to the computer, and then causing a CPU or the like mounted on the expansion board or the expansion unit to perform part or all of the actual operations based on the instructions of the program code.
Examples of the storage medium for supplying the program code include floppy disks, hard disks, magneto-optical disks, optical disks (e.g., CD-ROMs, CD-R, CD-RWs, DVD-ROMs, DVD-RAMs, DVD-RWs, DVD + RWs), magnetic tapes, nonvolatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer or the cloud by a communication network.
A computer program product stored on a computer-readable storage medium according to an embodiment of the present invention includes computer program instructions, which when executed, enable at least one processor to perform the method for transmitting data or the method for receiving data according to any of the above embodiments.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (12)
1. A method of transmitting data, the method being adapted for use in an environmental and equipment monitoring system, the method comprising:
receiving a Modbus reading message (101) containing register number from a rail transit comprehensive monitoring system;
generating a Modbus reply message containing a first field, a second field and a data field, writing length information from a current byte to a last byte determined based on the number of registers in the first field, writing data determined based on the number of registers in the data field, wherein when the number of registers is greater than the maximum number of registers supported by a Modbus protocol, a predetermined identifier is written in the second field (102);
sending the reply message (103) to the rail transit comprehensive monitoring system;
wherein when the track traffic integrated monitoring system detects the predetermined identification in the second field, data is read from the data field based on the length information.
2. The method according to claim 1, wherein when the number of registers is equal to or less than a maximum number of registers supported by a Modbus protocol, a number of bytes corresponding to the number of registers is written in the second field;
wherein when the track traffic integrated monitoring system does not detect the predetermined identification in the second field, reading data from the data field based on the number of bytes.
3. The method for sending data according to claim 1, wherein the Modbus read message further includes a start address;
the writing data determined based on the number of registers in a data field includes:
reading data by taking the starting address as a reading starting position and the register number as a reading register number;
writing the read data in the data field.
4. Apparatus (200) for transmitting data, characterized in that the apparatus (200) is arranged in an environment and equipment monitoring system, the apparatus (200) comprising:
the receiving module (201) is used for receiving Modbus reading messages containing register numbers from the rail transit comprehensive monitoring system;
a generating module (202) for generating a Modbus reply message including a first field, a second field and a data field, wherein length information from a current byte to a last byte determined based on the number of registers is written in the first field, data determined based on the number of registers is written in the data field, and a predetermined identifier is written in the second field when the number of registers is greater than a maximum number of registers supported by a Modbus protocol;
a sending module (203) for sending the reply message to the rail transit integrated monitoring system;
wherein when the track traffic integrated monitoring system detects the predetermined identification in the second field, data is read from the data field based on the length information.
5. The apparatus (200) for transmitting data according to claim 4,
the generating module (202) is further configured to write the number of bytes corresponding to the number of registers in the second field when the number of registers is less than or equal to a maximum number of registers supported by a Modbus protocol;
wherein when the track traffic integrated monitoring system does not detect the predetermined identification in the second field, reading data from the data field based on the number of bytes.
6. The apparatus (200) for sending data according to claim 4, wherein the Modbus read message further includes a start address;
the generating module (202) is configured to read data by using the start address as a read start position and the number of registers as a read register number; writing the read data in the data field.
7. A method of receiving data, the method being applicable to an environmental and equipment monitoring system, the method comprising:
receiving a Modbus write message containing a first field, a second field and a data field from a rail transit integrated monitoring system, wherein the first field contains the number of registers, the data field contains data, the second field contains a preset identifier when the number of registers is larger than the maximum number of registers supported by a Modbus protocol, and the second field contains the number of bytes corresponding to the number of registers when the number of registers is smaller than or equal to the maximum number of registers supported by the Modbus protocol (301);
data is obtained from the data field based on the number of registers extracted from the first field (302).
8. The method of receiving data of claim 7, wherein the Modbus write message further includes a start address; the method further comprises the following steps:
the data retrieved from the data field is written 303 with the start address as a write start location and the number of registers as a write register number.
9. Apparatus (400) for receiving data, the apparatus (400) being arranged in an environment and equipment monitoring system, the apparatus (400) comprising:
the system comprises a receiving module (401) and a processing module, wherein the receiving module is used for receiving a Modbus write message containing a first field, a second field and a data field from a rail transit integrated monitoring system, the first field contains a register number, the data field contains data, the second field contains a preset identification when the register number is larger than the maximum register number supported by a Modbus protocol, and the second field contains the byte number corresponding to the register number when the register number is smaller than or equal to the maximum register number supported by the Modbus protocol;
an obtaining module (402) for obtaining data from the data field based on the number of registers extracted from the first field.
10. The apparatus (400) for receiving data according to claim 9, wherein the Modbus write message further includes a start address; the apparatus (400) further comprises:
a writing module (403) for writing the data obtained from the data field with the start address as a writing start position and the number of registers as a writing register number.
11. Data transmission apparatus (500) comprising a processor (501) and a memory (502);
the memory (502) has stored therein an application executable by the processor (501) for causing the processor (501) to perform the method of transmitting data according to any one of claims 1 to 3 or the method of receiving data according to any one of claims 7 to 8.
12. Computer-readable storage medium, in which computer-readable instructions are stored for performing the method of transmitting data according to any one of claims 1 to 3, or the method of receiving data according to any one of claims 7 to 8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910654214.3A CN110417764B (en) | 2019-07-19 | 2019-07-19 | Method and apparatus for transmitting and receiving data, data transmission apparatus and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910654214.3A CN110417764B (en) | 2019-07-19 | 2019-07-19 | Method and apparatus for transmitting and receiving data, data transmission apparatus and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110417764A CN110417764A (en) | 2019-11-05 |
CN110417764B true CN110417764B (en) | 2021-08-03 |
Family
ID=68362031
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910654214.3A Active CN110417764B (en) | 2019-07-19 | 2019-07-19 | Method and apparatus for transmitting and receiving data, data transmission apparatus and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110417764B (en) |
Families Citing this family (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111371878B (en) * | 2020-02-28 | 2023-04-14 | 北京和利时***集成有限公司 | Information publishing method, ISCS (Internet service System), PIS (particle information System) and device |
CN111800524B (en) * | 2020-07-10 | 2022-10-14 | 河北科瑞达仪器科技股份有限公司 | Method for analyzing original addresses of multi-channel data in Modbus message |
CN114078332B (en) * | 2020-08-13 | 2023-05-05 | 比亚迪股份有限公司 | Broadcast control method and system |
CN113242109B (en) * | 2021-04-14 | 2022-05-27 | 中国信息通信研究院 | Method, device and equipment for checking message data |
CN114025032B (en) * | 2022-01-06 | 2022-04-22 | 深圳市聚能优电科技有限公司 | Transmission protocol method, system, equipment and storage medium of EMS and BMS |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102916838A (en) * | 2012-10-25 | 2013-02-06 | 国电南瑞科技股份有限公司 | Realization method for comprehensive monitoring system and ATS (Automatic Train Supervision) system interface |
CN103929439A (en) * | 2014-05-07 | 2014-07-16 | 昆山华恒焊接股份有限公司 | Data transmission method and MODBUS server |
CN104486185A (en) * | 2014-12-12 | 2015-04-01 | 中广核工程有限公司 | Control system communication method and system for nuclear power plant |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7246193B2 (en) * | 2003-01-30 | 2007-07-17 | Rosemount, Inc. | Interface module for use with a Modbus device network and a Fieldbus device network |
-
2019
- 2019-07-19 CN CN201910654214.3A patent/CN110417764B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102916838A (en) * | 2012-10-25 | 2013-02-06 | 国电南瑞科技股份有限公司 | Realization method for comprehensive monitoring system and ATS (Automatic Train Supervision) system interface |
CN103929439A (en) * | 2014-05-07 | 2014-07-16 | 昆山华恒焊接股份有限公司 | Data transmission method and MODBUS server |
CN104486185A (en) * | 2014-12-12 | 2015-04-01 | 中广核工程有限公司 | Control system communication method and system for nuclear power plant |
Also Published As
Publication number | Publication date |
---|---|
CN110417764A (en) | 2019-11-05 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110417764B (en) | Method and apparatus for transmitting and receiving data, data transmission apparatus and storage medium | |
US10814893B2 (en) | Vehicle control system | |
US20200412813A1 (en) | Vehicle control system | |
US20190322298A1 (en) | Locomotive control system | |
US20190322299A1 (en) | Locomotive control system | |
US8666542B2 (en) | Multi-channel controller | |
CN105376166B (en) | Data processing method and interchanger based on rail locomotive interchanger | |
CN110225123A (en) | A kind of Vehicular data recording method and apparatus | |
JP4848132B2 (en) | Signal control system, signal device and program | |
US20190296937A1 (en) | Central Data Store in Vehicle Electrical System | |
CN109305192A (en) | The operation method of train grade control unit VCU-M, train network control system and VCU-M | |
CN108696309B (en) | Relay device and multi-connected control system | |
US20170097915A1 (en) | Avionics system of an aircraft comprising line replaceable units that can exchange messages between them and device for monitoring such an avionics system | |
CN113259273B (en) | Switch control method, switch, computer device, and storage medium | |
KR102127777B1 (en) | Operation plan wireless transmission system for railway vehicle | |
CN106909102B (en) | Controller board and control method for nuclear power plant reactor protection system | |
CN114644030A (en) | Automatic train monitoring system | |
BRPI0610713B1 (en) | PROVIDING TRAFFIC INFORMATION RELATED TO A CONGESTION STATE PREDICTION AND USE | |
CN116489167A (en) | Data synchronization method and system | |
CN107231279A (en) | A kind of message parsing method based on CAN communication | |
KR101847863B1 (en) | Apparatus and method of converting for railway safety data integrated transport | |
CN105592143B (en) | A kind of file loading method and device | |
CN114078332B (en) | Broadcast control method and system | |
Imputato et al. | Network emulation support in ns-3 through kernel bypass techniques | |
CN210822295U (en) | Vehicle-mounted safety maintenance communication platform based on LTE-R network |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |