Modbus protocol conversion method and device for Web application development interface
By setting up a public data area in shared memory and building a Web API interface, the problem of difficult data processing of Modbus protocol on the Web side is solved, efficient access and management of Modbus protocol data is achieved, development difficulty is reduced, and system flexibility and Maintainability, supports multiple programming languages and platforms.
Patent Information
- Application Number
- CN202411001923.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-10-25
AI Technical Summary
The existing Modbus protocol has difficulties in data processing on the Web side. The traditional method relies on the database, resulting in system inscalability and insufficient flexibility. The interface program and the business program are highly coupled, and the development is complex and inflexible.
By setting up a public data area in shared memory, using dictionary collections to classify and store Modbus protocol data, and building a Web API interface, we can achieve the separation of interface programs and business programs, reduce database dependence, and improve system flexibility and development efficiency.
It achieves efficient access and management of Modbus protocol data, reduces development difficulty, improves system flexibility and maintainability, supports multiple programming languages and platforms, and meets diverse application needs in the field of industrial automation.
Smart Images

Figure CN118842846A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to industrial control technology, and in particular to a Modbus protocol conversion method and device for a Web application development interface. Background Art
[0002] Modbus protocol is the most common industrial control protocol for power generation control systems to exchange data with external devices. Commonly used Modbus protocols for thermal control include Modbus RTU and Modbus TCP. Both Modbus RTU and Modbus TCP / IP support two-way communication between switch and analog quantities. External systems can obtain the current data of the analog and switch measurement points of the control system, and can also change the data of the switch and analog measurement points of the control system. However, whether the data is transmitted through Modbus RTU or Modbus TCP / IP protocol, it is Modbus protocol data, which cannot be directly processed by the web end.
[0003] When general enterprises use the Modbus protocol, the traditional methods used are as follows:
[0004] 1. The interface program runs independently and writes data to a relational database (low frequency) or a time series database (high frequency). Other data consumers obtain data from the database. At the same time, the interface program will periodically poll the database for data that needs to be written to the control system. If data changes are found, the data to be written to the control system will be updated immediately. This method must rely on the database for data interaction, which limits the scalability and flexibility of the system.
[0005] 2. The interface program and the business program run as one integrated program. The business program directly accesses the data area defined by the interface program for communication. This method is only suitable for small-scale programs with a single business because of the high degree of coupling between the interface and the business and lack of flexibility.
[0006] 3. The interface program runs independently and completes data synchronization with the business program through TCP or UDP communication interface based on shared memory, network, pipeline, etc. This method generally requires self-defined dedicated communication protocol, which is difficult to write and has poor stability. In addition, due to the private nature of the communication interface (poor openness and low standardization level), it is only applicable to the case where the interface program and the business program are the same unit. Although the Modbus protocol is widely used in the field of industrial automation, its implementation is relatively complex and has high technical requirements for developers. Summary of the invention
[0007] In view of the above problems, the present invention provides a Modbus protocol conversion method and device for a Web application development interface, which realizes the separation of interface program and business program, has no database dependence, reduces development difficulty, and improves system flexibility.
[0008] The technical solution is as follows: a Modbus protocol conversion method for a Web application development interface, comprising the following steps:
[0009] Configure the data area of the Modbus protocol, and set the sending and receiving of the switch quantity and analog quantity in the data to be processed by different data areas of the Modbus protocol;
[0010] Communicate via Modbus protocol and transmit Modbus protocol data on the Modbus side;
[0011] Set up a public data area in the shared memory to cache Modbus protocol data;
[0012] Creating a dictionary set in the public data area, the dictionary set corresponds to the data area setting of the Modbus protocol, and the dictionary set is configured to store the Modbus protocol data according to the classification of the data area of the Modbus protocol;
[0013] Use a Web development framework to build a Web API interface, wherein the Web API interfaces correspond to the dictionary sets of the public data areas respectively;
[0014] The Web API interface is configured to be accessed by a web terminal, and the web terminal accesses the corresponding dictionary collection through the Web API interface to achieve communication with the Modbus terminal.
[0015] Further, the data area of the Modbus protocol includes coils, discrete inputs, holding registers and input registers. The data area of the Modbus protocol is configured, and the sending and receiving of the switch quantity and analog quantity in the setting data are processed by different Modbus protocol data areas, which is specifically performed as follows:
[0016] The switch quantity sent from the web end to the Modbus end is placed in the discrete input;
[0017] The switch quantity sent from the Modbus end to the web end is placed in the coil;
[0018] The analog quantity sent from the web end to the Modbus end is placed in the input register;
[0019] The analog quantity sent from the Modbus end to the web end is placed in the holding register.
[0020] Further, the key of the dictionary set is an integer type, configured to represent the address of the Modbus data area, and the value is a Boolean type for switch quantity or a double-byte integer type for analog quantity, configured to represent the data at the corresponding address; the dictionary set includes:
[0021] A readable and writable collection of coils, the value is Boolean;
[0022] A read-only collection of discrete inputs, the value is Boolean;
[0023] A readable and writable set of holding registers, the value is a double-byte integer type;
[0024] A read-only set of input registers, whose values are double-byte integers.
[0025] Furthermore, the Web API interface includes: a switch output interface, a switch input interface, an analog output interface, and an analog input interface;
[0026] The switch output interface is configured to allow the Web end to read the switch quantity, the input of the switch output interface is an integer array representing the coil address to be read, and the output of the switch output interface is a structure, which at least includes an integer representing the reading result status, a Boolean array representing the reading result, and a string for transmitting a status message;
[0027] The switch quantity input interface is configured to allow the Web end to write the switch quantity to the Modbus end, the input of the switch quantity input interface is a structure containing two arrays, one array is the address of the discrete input quantity to be written, and the other array is the value of the Boolean quantity written, and the interface output of the switch quantity input interface is a structure, which at least includes an integer representing the status of the writing result and a character string for transmitting a status message;
[0028] The analog output interface is configured to read analog quantities for the Web end, the input of the analog output interface is an integer array representing the address of the holding register to be read, and the output of the analog output interface is a structure, which at least includes an integer representing the status of the reading result, a double-byte integer array representing the reading result, and a character string for transmitting a status message;
[0029] Furthermore, the analog input interface is configured to allow the Web end to write analog quantities to the Modbus end. The input of the analog input interface is a structure containing two arrays, one of which is the address to be written to the input register, and the other is the value of a double-byte integer representing the write. The output of the analog input interface is a structure, which includes at least an integer representing the write result status and a character string for transmitting a status message.
[0030] Furthermore, for analog quantities in Modbus protocol data, it also includes parsing from floating-point numbers to registers, and synthesis from registers to floating-point numbers.
[0031] Further, the data area of the Modbus protocol is configured, and the sending and receiving of the switch quantity and the analog quantity in the setting data are processed by different data areas of the Modbus protocol, which is specifically performed as follows:
[0032] The switch quantity sent from the web end to the Modbus end and the switch quantity sent from the Modbus end to the web end are placed in different partitions of the coil respectively;
[0033] The analog quantity sent from the web end to the Modbus end and the analog quantity sent from the Modbus end to the web end are respectively placed in different partitions of the holding register.
[0034] Further, the data area of the Modbus protocol is configured, and the sending and receiving of the switch quantity and the analog quantity in the setting data are processed by different data areas of the Modbus protocol, which is specifically performed as follows:
[0035] The holding register and the input register are partitioned, and the partitions of the holding register and the input register are used to store analog quantities and switch quantities;
[0036] Setting an analysis function from register to switch quantity and a synthesis function from switch quantity to register; the analysis function is configured to analyze the data in the register into a switch quantity array, and the synthesis function is configured to synthesize the switch quantity array into the data in the register;
[0037] The analog quantity sent from the web end to the Modbus end is placed in the input register, and multiple switch quantities sent from the web end to the Modbus end are packaged and stored in the input register;
[0038] The analog quantity sent from the Modbus end to the web end is placed in the holding register, and the multiple switch quantities sent from the Modbus end to the web end are packaged and stored in the holding register.
[0039] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the Modbus protocol conversion method for a Web application development interface as described above when executing the computer program.
[0040] A computer-readable storage medium stores a program, which, when executed by a processor, implements the Modbus protocol conversion method for a Web application development interface as described above.
[0041] A computer program product comprises a computer program / instruction, which implements the steps of the above method when executed by a processor.
[0042] The Modbus protocol conversion method for the Web application development interface of the present invention caches the Modbus protocol data of the Modbus end in the common data area by setting a common data area in the shared memory, and classifies, stores and manages the Modbus data area through a dictionary set, thereby improving the efficiency and accuracy of data access, so that a standard Web API interface can be used for communication, and a business program can communicate with the Modbus end through the Web API interface, thereby realizing the separation of an interface program and a business program;
[0043] By adopting the method of the present invention, the Modbus protocol, which is highly professional and difficult to implement stably and reliably, is converted into data that can be read by a standard, easy-to-program Web API interface, which reduces the difficulty of developing business programs and improves development efficiency. Developers do not need to have a deep understanding of the complex implementation of the Modbus protocol to achieve data interaction with industrial control systems. In addition, by adopting the method of the present invention, Web API is used to replace the Modbus protocol for data interaction, which reduces the dependence on a specific database. The interface program no longer needs to be bound to a specific database, and the database system can be flexibly selected according to actual needs, which improves the flexibility and maintainability of the system. In the present invention, support for multiple programming languages and platforms is achieved through a standard Web API interface. The business program on the Web side can access Modbus data more flexibly through different programming languages and platforms, meeting the diverse application needs in the field of industrial automation. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 The following is a schematic diagram of the steps of the Modbus protocol conversion method for the Web application development interface in Example 1;
[0045] Figure 2 A system block diagram for implementing the method in Example 2;
[0046] Figure 3FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0047] Embodiment 1:
[0048] See Figure 1 A Modbus protocol conversion method for a Web application development interface of the present invention comprises at least the following steps:
[0049] Step 1: Configure the data area of the Modbus protocol, and set the sending and receiving of the switch quantity and analog quantity in the data to be processed by different data areas of the Modbus protocol;
[0050] Step 2: Communicate via the Modbus protocol and transmit the Modbus protocol data on the Modbus end;
[0051] Step 3: Set up a public data area in the shared memory to cache Modbus protocol data. The shared memory can be read and written safely by multiple threads, and the public data area is configured to support multi-threaded safe reading and writing;
[0052] Step 4: Create a dictionary set in the public data area. The dictionary set corresponds to the data area setting of the Modbus protocol. The dictionary set is configured to store Modbus protocol data according to the data area classification of the Modbus protocol.
[0053] Step 5: Use the Web development framework to build a Web API interface, which corresponds to a dictionary set in the public data area;
[0054] Step 6: The Web API interface is configured for access by the web client, and the web client accesses the corresponding dictionary collection through the Web API interface to achieve communication with the Modbus client.
[0055] Embodiment 2:
[0056] See Figure 2 In one embodiment of the present invention, the method is applied to the communication from the control system on the Modbus side to the business system on the web side. In the embodiment, the control system on the Modbus side acts as the master station of the Modbus protocol to actively communicate, while the business system on the web side acts as the slave station of the Modbus protocol; of course, the identities of the master station and the slave station of the control system and the business system can also be exchanged.
[0057] The Modbus data area includes four types: coil, discrete input, input register, and holding register. Coil represents the switch output status of the device, such as relay status, indicator light status, etc. Each coil point is represented by a bit, and its value can only be 0 or 1, indicating off or on respectively. Discrete input represents the switch input status of the device, such as button status, sensor status, etc. Each discrete input point is represented by a bit, and its value can only be 0 or 1, indicating off or on respectively. Input register represents the analog input value of the device, such as temperature, pressure, flow, etc. Each input register is represented by two bytes and can represent a 16-bit signed integer or unsigned integer. Holding register represents the readable and writable data of the device, such as set values, control parameters, etc. Each holding register is represented by two bytes and can represent a 16-bit signed integer or unsigned integer. Since general floating-point numbers are four bytes, power plants or other industrial occasions generally use two registers to represent a floating-point number (analog quantity). When using a register to represent a floating-point number, the communicating parties need to agree on the multiplier and offset. No matter which method is used to represent the floating-point number, it does not affect the communication process itself. Therefore, the communication process and business data can be separated. The communication process does not perform data assembly and only cares about the content of the original data area.
[0058] In this embodiment, in step 1, the functions of each data area are more specifically agreed upon as follows:
[0059] The switch quantity sent by the business system on the web side to the control system on the Modbus side is placed in the discrete input;
[0060] The switch quantity sent by the control system on the Modbus side to the business system on the web side is placed in the coil;
[0061] The analog quantity sent by the business system on the web side to the control system on the Modbus side is placed in the input register;
[0062] The analog quantity sent by the control system on the Modbus side to the business system on the web side is placed in the holding register.
[0063] In step 2, communication is performed through the Modbus protocol to transmit the Modbus protocol data of the Modbus end. The Modbus protocol includes Modbus RTU and Modbus TCP / IP protocols. Modbus RTU (Remote Terminal Unit) is a serial communication protocol used in the field of industrial automation. Since it is implemented based on a serial port, it belongs to hard-wired communication and is widely used in power generation companies.
[0064] As a member of the Modbus protocol family, Modbus TCP / IP performs data transmission based on the TCP / IP protocol stack and is widely used in the field of industrial automation. As a commonly used communication protocol in the field of industrial automation, Modbus TCP / IP provides an efficient and flexible solution for data interaction between devices with its simplicity, reliability, and openness.
[0065] Both Modbus RTU and Modbus TCP / IP support two-way communication between switch quantity and analog quantity. The external system can obtain the current data of the analog quantity and switch quantity measurement points of the control system, and can also change the data of the switch quantity and analog quantity measurement points of the control system.
[0066] Modbus RTU and Modbus TCP / IP only differ in the communication channel implementation technology. Modbus RTU is based on the serial communication port while Modbus TCP / IP is based on the network interface. Modbus RTU requires a checksum while Modbus / TCP does not require a checksum but contains a protocol data unit. However, the data area definition and function code of the two are exactly the same.
[0067] However, no matter the data is transmitted through Modbus RTU or Modbus TCP / IP protocol, it is Modbus protocol data, which cannot be directly processed by the web end.
[0068] To this end, in step 3 of the embodiment, a public data area is set in the shared memory for caching Modbus protocol data, ensuring that the size of the shared memory area is sufficient to accommodate all data that need to be cached, and the public data area is configured to support multi-threaded safe reading and writing; the shared memory can be an external PC or server shared memory, and a suitable shared memory management mechanism is selected according to the development environment and requirements. For example, memory-mapped files (Memory-Mapped Files) can be used on the Windows platform, and POSIX shared memory can be used on the Linux platform. In this embodiment, Modbus data is cached by shared memory, and a multi-threaded safe reading and writing mechanism is used to ensure the real-time and reliability of the data, which can solve the problem of insufficient data real-time due to the database polling mechanism, and the problem of data reliability that may be caused by the private communication interface;
[0069] In step 4 of the embodiment, a dictionary set is created in the public data area, the dictionary set corresponds to the data area setting of the Modbus protocol, the key of the dictionary set is an integer digital type, configured to represent the address of the Modbus data area, and the value is a Boolean type for the switch quantity or a double-byte integer type for the analog quantity, representing the data at the corresponding address; in the embodiment, the dictionary set is divided into four categories, and the keys of the four categories are all integers, the first category is a readable and writable set representing the coil, and the value is a Boolean type; the second category is a read-only set representing the discrete quantity input, and the value is a Boolean type; the third category is a readable and writable set representing the holding register, and the value is a double-byte integer type; the fourth category is a read-only set representing the input register, and the value is a double-byte integer type, by setting the public data area in the shared memory, and configuring it to support multi-threaded safe reading and writing, the real-time and reliability of the Modbus protocol data are ensured. At the same time, the Modbus data area is classified, stored and managed by the dictionary set, which improves the efficiency and accuracy of data access.
[0070] In step 5 of the embodiment, a Web API interface is constructed using a Web development framework, and the Web development framework provided by various languages can be used to expand the implementation, and the Web API interface corresponds to a dictionary set of a public data area respectively;
[0071] In this embodiment, the Web API interface includes: a switch output interface, a switch input interface, an analog output interface, and an analog input interface;
[0072] The switch output interface is configured to allow the business system on the Web end to read the switch quantity. The input of the switch output interface is an integer array representing the coil address to be read. The output of the switch output interface is a structure, which at least includes an integer representing the status of the reading result, a Boolean array representing the reading result, and a string for transmitting a status message.
[0073] The switch quantity input interface is configured to allow the business system on the Web side to write switch quantities to the control system on the Modbus side. The input of the switch quantity input interface is a structure containing two arrays, one array is the address of the discrete input quantity to be written, and the other array is the value of the Boolean quantity to be written. The interface output of the switch quantity input interface is a structure, which includes at least an integer representing the status of the write result and a string conveying the status message;
[0074] The analog output interface is configured for the Web-side business system to read analog quantities. The input of the analog output interface is an integer array representing the address of the holding register to be read. The output of the analog output interface is a structure, which includes at least an integer representing the status of the reading result, a double-byte integer array representing the reading result, and a string for transmitting status messages.
[0075] The analog input interface is configured for the business system on the Web side to write analog quantities to the control system on the Modbus side. The input of the analog input interface is a structure containing two arrays, one of which is the address of the input register to be written, and the other is the value of the double-byte integer to be written. The output of the analog input interface is a structure, which includes at least an integer representing the status of the write result and a string that conveys the status message.
[0076] In the embodiment, in order to be compatible with common expressions in the industrial control field and facilitate understanding, the input and output are viewed from the perspective of the control system, and the above four interfaces are named in sequence:
[0077] 1) DO: switch output interface, obtain switch quantity from the control system
[0078] 2) DI: switch input interface, write switch quantity to control system
[0079] 3) AO: analog output interface, obtain analog quantity from the control system
[0080] 4) AI: analog input interface, write analog quantity to the control system
[0081] In step 6 of the embodiment, the Web API interface is configured to be accessed by the business system on the web side, and the business system on the web side accesses the corresponding dictionary collection through the Web API interface to achieve communication with the Modbus side.
[0082] Web API interfaces are usually implemented using Web development frameworks provided by various languages. The interface program processes HTTP requests and accesses the corresponding data area in the dictionary collection based on the parameters in the request (such as address, value, etc.). The interface program encapsulates the access results into HTTP responses and returns them to the business program.
[0083] The following is an explanation from the perspective of reading data and writing data:
[0084] Reading data:
[0085] The business program reads the data in the shared memory by calling the Web API interface.
[0086] For example, to read the switch quantity, the business program will call the DO (switch quantity output) interface and pass in the coil address array to be read. This can be achieved with the help of the data function code. The data function code includes: 01H read coil, 02H read discrete input, 03H read holding register, 04H read input register. When the read data function code arrives, the interface program will obtain the corresponding data from the coil readable and writable set in the dictionary set according to the passed address, and return it to the business program as a response.
[0087] Write data:
[0088] The business program writes data in the shared memory by calling the Web API interface.
[0089] For example, to write a switch quantity to the control system, the business program will call the DI (switch quantity input) interface and pass in the address of the discrete input quantity to be written and the corresponding Boolean value array. This can be achieved with the help of data function codes. The data function codes include: 5H to write a single coil, 0FH to write multiple coils, 06H to write a single holding register, and 10H to write multiple holding registers. The interface program will write the incoming message into the discrete quantity input read-only set in the dictionary set, and then transmit it from the discrete quantity input read-only set to the input register of the control system on the Modbus end through the Modbus protocol.
[0090] Through the dictionary collection, the interface program can access and manage Modbus data in a structured way, thereby achieving efficient interaction with the business program. The business program can send a request through the Web API interface, and the interface program retrieves the corresponding data from the dictionary collection according to the address in the request and returns it to the business program. Similarly, the business program can also send a data write request through the Web API interface, and the interface program writes the data into the corresponding data area of the Modbus protocol through the dictionary collection.
[0091] In industrial control systems, analog quantities (such as temperature, pressure, flow, etc.) are usually represented in the form of floating-point numbers, but due to the limitations of the Modbus protocol, these data need to be transmitted through registers (usually two registers represent one floating-point number). Therefore, in an embodiment of the present invention, the following steps are also included: conversion between registers and floating-point numbers, including:
[0092] Synthesis from registers to floating point numbers:
[0093] The input is the double-byte integer array to be synthesized, which represents the value of the register. The synthesis method used is the big-endian mode. According to the big-endian mode, the values of the two registers are combined into a 32-bit integer. Then, the 32-bit integer is converted to a floating-point number and the output is the integer in the synthesized state.
[0094] Parsing from floating point numbers to registers:
[0095] The input is the floating point array to be parsed, which represents the data collected by the Modbus terminal. The parsing method used is the big-endian mode, which converts the floating point number into a 32-bit integer. Then, according to the big-endian mode, the 32-bit integer is split into two 16-bit integers, corresponding to the values of the two registers respectively. The output is an integer and message containing a double-byte integer array and the parsing status.
[0096] Through conversion, data exchange and interoperability between Modbus protocol and business programs can be achieved.
[0097] Although the Modbus protocol is widely used in the field of industrial automation, its implementation is relatively complex and requires high technical skills from developers. This solution simplifies the data interaction process and reduces the difficulty of development by converting Modbus protocol data into data that can be operated by the standard Web API interface.
[0098] In traditional methods, interface programs and business programs are often tightly coupled, resulting in poor system flexibility and difficulty in adapting to changing business needs. In this embodiment, the interface program and business program are separated and communicated through standard Web API, which significantly reduces the system coupling. When the business logic changes, only the business program needs to be modified without changing the interface program; and by using Web API, the database is decoupled, solving the problem that traditional methods often need to rely on specific databases for data interaction, improving the scalability and flexibility of the system, and through the standard Web API interface, it supports multiple programming languages and platforms, improving the compatibility and portability of the system.
[0099] In the embodiment, a standard Web API interface is used so that data interaction follows a common network protocol, which enhances the openness and interoperability of the system. Any client that supports the HTTP protocol can easily access Modbus protocol data without having to care about the underlying Modbus protocol details. In addition, the standardized Web API interface also makes system maintenance simpler and more efficient. Through modular interface design and loosely coupled architecture, it is easy to add new functions or optimize existing functions in the future without large-scale reconstruction of the entire system.
[0100] Embodiment 3:
[0101] Embodiment 3 is similar to Embodiment 2, except that: in Embodiment 3, discrete input and input register are not used, and coils and holding registers are partitioned:
[0102] For the switch quantity, the switch quantity sent from the web end to the Modbus end is placed in one partition of the coil, while the switch quantity sent from the Modbus end to the web end is placed in another partition of the coil.
[0103] For analog quantity, the analog quantity sent from the web end to the Modbus end is placed in one partition of the holding register, while the analog quantity sent from the Modbus end to the web end is placed in another partition of the holding register.
[0104] The same parts of Example 3 as those of Example 2 are not described in detail. Specifically, Example 3 is different from Example 2 in that:
[0105] In step 1, in the data area of the Modbus protocol configuration, the sending and receiving of the switch quantity and analog quantity in the data are set to be processed by different Modbus protocol data areas, which are specifically performed as follows:
[0106] The switch quantity sent from the web end to the Modbus end and the switch quantity sent from the Modbus end to the web end are placed in different partitions of the coil respectively;
[0107] The analog quantity sent from the web end to the Modbus end and the analog quantity sent from the Modbus end to the web end are respectively placed in different partitions of the holding register.
[0108] Steps 2 and 3 remain unchanged. In step 4, a dictionary set is created in the public data area. The dictionary set is the same as in Example 2 and is still divided into four categories. However, the dictionary set corresponds to different partitions of coils and different partitions of holding registers of the Modbus protocol. The keys of the four categories are all integers. The first category is a readable and writable set representing coils, and the value is Boolean; the second category is a read-only set representing coils, and the value is Boolean; the third category is a readable and writable set representing holding registers, and the value is a double-byte integer type; the fourth category is a read-only set representing holding registers, and the value is a double-byte integer type.
[0109] In addition, in step 5, similar to Example 2, a Web development framework is used to build a Web API interface, and the Web API interface still includes a switch output interface, a switch input interface, an analog output interface, and an analog input interface; the difference is: for the input of the switch input interface, one of the arrays is adjusted from the original discrete input address to the partition address in the coil, and for the input of the analog input interface, one of the arrays is adjusted from the original input register address to the partition address of the holding register. Step 6 is the same as Example 2.
[0110] Example 4: In Example 4, in order to improve the transmission performance of switch quantities in some Modbus-end control systems, packaging points, that is, registers are used to represent 16 switch quantities for switch quantity communication. The switch quantity output interface and the switch quantity input interface are not used, and only the analog quantity output interface and the analog quantity input interface are used, and the analog quantity output interface and the analog quantity input interface are partitioned.
[0111] The same parts as those in Example 2 will not be described in detail. The difference between Example 4 and Example 2 is as follows:
[0112] In step 1, the holding register and the input register are partitioned, and the partitions of the holding register and the input register are used to store analog quantities and switch quantities;
[0113] In addition, a parsing function from register to switch quantity and a synthesis function from switch quantity to register are also set; the parsing function is configured to parse the data in the register into a switch quantity array, and the synthesis function is configured to synthesize the switch quantity array into the data in the register;
[0114] Steps 2 and 3 remain unchanged. In step 4, a dictionary set is created in the public data area. The dictionary set is the same as in Example 2 and is still divided into four categories. However, the dictionary set corresponds to different partitions of the input register and the holding register of the Modbus protocol. The keys of the four categories are all integers. The first category is the first readable and writable set of the holding register, and the value is a double-byte integer type; the second category represents the first readable and writable set of the holding register, and the value is a double-byte integer type; the third category represents the second readable and writable set of the holding register, and the value is a double-byte integer type; the fourth category represents the second read-only set of the input register, and the value is a double-byte integer type.
[0115] In addition, in step 5, similar to Example 2, a Web development framework is used to build a Web API interface, and the Web API interface still includes a switch output interface, a switch input interface, an analog output interface, and an analog input interface; the difference is that:
[0116] In the switch output interface, the input is adjusted to an integer array representing the address of the partition in the input read holding register to be read; the output is adjusted to a structure, which includes at least an integer representing the read result status, a double-byte integer array representing the read result, and a string used to transmit the status message. In the switch input interface, one of the input arrays adjusts the address of the original discrete input quantity to the address of the partition in the register, and the other array is adjusted to represent the value of the double-byte integer written. The input and output of the switch output interface and the switch input interface are also adjusted accordingly.
[0117] Step 6 is the same as Example 2. The other differences are that the analog quantity sent from the web end to the Modbus end is placed in the input register, and the multiple switch quantities sent from the web end to the Modbus end are packaged and stored in the input register, and are located in different partitions of the input register; the analog quantity sent from the Modbus end to the web end is placed in the holding register, and the multiple switch quantities sent from the Modbus end to the web end are packaged and stored in the holding register, and are located in different partitions of the holding register.
[0118] In an embodiment of the present invention, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the Modbus protocol conversion method for the Web application development interface as described above is implemented.
[0119] The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 3 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected by a bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a Modbus protocol conversion method for a Web application development interface is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0120] The memory may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc. The memory is used to store programs, and the processor executes the programs after receiving the execution instruction.
[0121] The processor can be an integrated circuit chip with signal processing capabilities. The above-mentioned processor can be a general-purpose processor, including a central processing unit (Central Processing Unit, referred to as: CPU), a network processor (Network Processor, referred to as: NP), etc. The processor can also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application-specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The various methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.
[0122] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0123] In an embodiment of the present invention, a computer-readable storage medium is further provided, on which a program is stored, characterized in that when the program is executed by a processor, the Modbus protocol conversion method for the Web application development interface as described above is implemented.
[0124] Those skilled in the art will appreciate that the embodiments of the embodiments of the present invention may be provided as methods, computer devices, or computer program products. Therefore, the embodiments of the present invention may take the form of complete hardware embodiments, complete software embodiments, or embodiments combining software and hardware. Moreover, the embodiments of the present invention may take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0125] The embodiments of the present invention are described with reference to flowcharts and / or block diagrams of methods, computer devices, or computer program products according to the embodiments of the present invention. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate a device for implementing the functions specified in the flowcharts and / or.
[0126] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in the flowchart.
[0127] In an embodiment of the present invention, a computer program product is further provided, comprising a computer program / instruction, wherein the computer program / instruction implements the steps of the above method when executed by a processor.
[0128] In actual application, the above-mentioned computer program products include but are not limited to: smart phones, desktop computers, laptop computers, tablet computers, host computers and server platforms, etc., and are not specifically limited here.
[0129] The Modbus protocol conversion method for the Web application development interface, the computer device, the computer-readable storage medium, and the application of the computer program product provided by the present invention are introduced in detail above. The principle and implementation mode of the present invention are explained in detail in this article by using specific examples. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation mode and the scope of application. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A Modbus protocol conversion method for a Web application development interface, characterized in that: The following steps are involved: Configure the data area of the Modbus protocol, and set the sending and receiving of the switch quantity and analog quantity in the data to be processed by different data areas of the Modbus protocol; Communicate via Modbus protocol and transmit Modbus protocol data on the Modbus side; Set up a public data area in the shared memory to cache Modbus protocol data; Creating a dictionary set in the public data area, the dictionary set corresponds to the data area setting of the Modbus protocol, and the dictionary set is configured to store the Modbus protocol data according to the classification of the data area of the Modbus protocol; Use a Web development framework to build a Web API interface, wherein the Web API interfaces correspond to the dictionary sets of the public data areas respectively; The Web API interface is configured to be accessed by a web terminal, and the web terminal accesses the corresponding dictionary collection through the Web API interface to achieve communication with the Modbus terminal.
2. A Modbus protocol conversion method for a Web application development interface according to claim 1, characterized in that: The data area of the Modbus protocol includes coils, discrete inputs, holding registers and input registers. The data area of the Modbus protocol is configured, and the sending and receiving of the switch quantity and analog quantity in the setting data are processed by different Modbus protocol data areas, which are specifically executed as follows: The switch quantity sent from the web end to the Modbus end is placed in the discrete input; The switch quantity sent from the Modbus end to the web end is placed in the coil; The analog quantity sent from the web end to the Modbus end is placed in the input register; The analog quantity sent from the Modbus end to the web end is placed in the holding register.
3. A Modbus protocol conversion method for a Web application development interface according to claim 2, characterized in that: The key of the dictionary set is an integer type, configured to represent the address of the Modbus data area, and the value is a Boolean type for switch quantity or a double-byte integer type for analog quantity, configured to represent the data at the corresponding address; the dictionary set includes: A readable and writable collection of coils, the value is Boolean type; A read-only collection of discrete inputs, the value is Boolean; A readable and writable set of holding registers, the value is a double-byte integer type; A read-only set of input registers, whose values are double-byte integers.
4. A Modbus protocol conversion method for a Web application development interface according to claim 1, characterized in that: The Web API interface includes: a switch output interface, a switch input interface, an analog output interface, and an analog input interface; The switch output interface is configured to allow the Web end to read the switch quantity, the input of the switch output interface is an integer array representing the coil address to be read, and the output of the switch output interface is a structure, which at least includes an integer representing the reading result status, a Boolean array representing the reading result, and a string for transmitting a status message; The switch quantity input interface is configured to allow the Web end to write the switch quantity to the Modbus end, the input of the switch quantity input interface is a structure containing two arrays, one array is the address of the discrete input quantity to be written, and the other array is the value of the Boolean quantity written, and the interface output of the switch quantity input interface is a structure, which at least includes an integer representing the status of the writing result and a character string for transmitting a status message; The analog output interface is configured to read analog quantities for the Web end, the input of the analog output interface is an integer array representing the address of the holding register to be read, and the output of the analog output interface is a structure, which at least includes an integer representing the status of the reading result, a double-byte integer array representing the reading result, and a character string for transmitting a status message; The analog input interface is configured to allow the Web end to write analog quantities to the Modbus end. The input of the analog input interface is a structure containing two arrays, one of which is the address to be written into the input register, and the other is the value of the double-byte integer represented by the write. The output of the analog input interface is a structure, which includes at least an integer representing the write result status and a character string for transmitting a status message.
5. A Modbus protocol conversion method for a Web application development interface according to claim 1, characterized in that: For analog quantities in Modbus protocol data, it also includes parsing from floating-point numbers to registers, and synthesis from registers to floating-point numbers.
6. A Modbus protocol conversion method for a Web application development interface according to claim 1, characterized in that: The configuration of the Modbus protocol data area sets the sending and receiving of the switch quantity and analog quantity in the data to be processed by different Modbus protocol data areas, which is specifically performed as follows: The switch quantity sent from the web end to the Modbus end and the switch quantity sent from the Modbus end to the web end are placed in different partitions of the coil respectively; The analog quantity sent from the web end to the Modbus end and the analog quantity sent from the Modbus end to the web end are respectively placed in different partitions of the holding register.
7. A Modbus protocol conversion method for a Web application development interface according to claim 1, characterized in that: The configuration of the Modbus protocol data area sets the sending and receiving of the switch quantity and analog quantity in the data to be processed by different Modbus protocol data areas, which is specifically performed as follows: The holding register and the input register are partitioned, and the partitions of the holding register and the input register are used to store analog quantities and switch quantities; Setting an analysis function from register to switch quantity and a synthesis function from switch quantity to register; the analysis function is configured to analyze the data in the register into a switch quantity array, and the synthesis function is configured to synthesize the switch quantity array into the data in the register; The analog quantity sent from the web end to the Modbus end is placed in the input register, and multiple switch quantities sent from the web end to the Modbus end are packaged and stored in the input register; The analog quantity sent from the Modbus end to the web end is placed in the holding register, and the multiple switch quantities sent from the Modbus end to the web end are packaged and stored in the holding register.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the Modbus protocol conversion method for the Web application development interface as claimed in claim 1 is implemented.
9. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, the Modbus protocol conversion method for a Web application development interface as claimed in claim 1 is implemented.
10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to claim 1 are implemented.
