File transmission method and device, product, equipment and medium

By preallocating the address segments in the Modbus protocol and parsing the register access information, file transfer is realized, solving the problems of reduced compatibility of Modbus protocol and impact on system performance in the prior art, ensuring protocol compatibility and system performance.

CN119728673APending Publication Date: 2025-03-28SHENZHEN ENVICOOL INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411896903.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-19
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

The existing file transfer scheme based on the Modbus protocol requires adjustment of the standard Modbus protocol, resulting in reduced protocol compatibility and system performance impact.

Method used

By preallocating the address segment on the Modbus register address segment and parsing the register access information in the Modbus protocol field based on the preset transmission definition, file access information is obtained, thereby realizing file transfer and avoiding modifying the standard Modbus protocol.

Benefits of technology

Ensures the compatibility and system performance of the Modbus protocol, avoids potential problems caused by protocol adjustment, and supports the transfer of file information and random file access.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119728673A_ABST
    Figure CN119728673A_ABST
Patent Text Reader

Abstract

The invention discloses a file transmission method and device, a product, equipment and a medium. The method comprises the steps that a register access instruction of a Modbus protocol is received; when an access register address carried by the register access instruction belongs to a pre-allocated address field, register access information carried by a target original Modbus protocol field in the register access instruction is extracted, and the pre-allocated address field is an address field pre-allocated for file transmission on a Modbus register address field; analyzing the register access information based on a preset transmission definition to obtain file access information, the preset transmission definition being a definition describing the file access information based on the target original Modbus protocol field; and accessing a file system based on the file access information to realize file transmission. In this way, a standard Modbus protocol can be prevented from being modified, and therefore the compatibility of the Modbus protocol and the system performance are guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of file transmission technology, and in particular to file transmission methods, devices, products, equipment and media. Background Art

[0002] The serial port of embedded devices usually uses the Modbus (Modicon bus) protocol. Since the multi-protocol support of the serial port will increase the complexity of the system and make it more prone to problems, in order to meet the needs of embedded device file transfer and avoid the problems caused by multiple protocols, the solution of using the Modbus protocol to transfer files has emerged.

[0003] At present, the existing file transfer solutions based on Modbus protocol usually need to adjust the standard Modbus protocol and add additional Modbus function codes to realize file transfer. This leads to reduced protocol compatibility and even affects system performance. In summary, in the process of implementing the present invention, the inventors found that the prior art has at least the following problems: modifying the standard Modbus protocol, reducing the compatibility of the Modbus protocol, and affecting system performance. Summary of the invention

[0004] In view of this, the purpose of this application is to provide a file transmission method, device, product, equipment and medium, which can avoid modifying the standard Modbus protocol, thereby ensuring the compatibility of the Modbus protocol and system performance. The specific scheme is as follows:

[0005] In a first aspect, the present application discloses a file transmission method, which is applied to a slave device, comprising:

[0006] Receive register access instructions of Modbus protocol;

[0007] When the access register address carried by the register access instruction belongs to the pre-allocated address segment, extracting the register access information carried by the target original Modbus protocol field in the register access instruction, wherein the pre-allocated address segment is an address segment pre-allocated for file transfer on the Modbus register address segment;

[0008] Parsing the register access information based on a preset transmission definition to obtain file access information, wherein the preset transmission definition is a definition of the file access information based on the target original Modbus protocol field description;

[0009] The file system is accessed based on the file access information to achieve file transfer.

[0010] Optionally, when the register access instruction is a write register instruction, the target original Modbus protocol field is a data content field;

[0011] Accordingly, the register access information is parsed based on the preset transmission definition to obtain the file access information, including:

[0012] parsing the register access information based on a preset transfer definition;

[0013] If the read flag is not parsed, the file identifier of the target file, the offset of the file data to be transferred within the target file, the data length corresponding to the file data to be transferred, and the file data to be transferred parsed from the register access information are used as the file access information corresponding to the write file operation.

[0014] Optionally, the parsing the register access information based on a preset transmission definition to obtain the file access information further includes:

[0015] When a read flag is parsed, the file identifier of the target file and the offset of the file data to be transferred within the target file parsed from the register access information are used as the first part of the file access information corresponding to the read file operation.

[0016] Optionally, when the register access instruction is a read register instruction, and the write register instruction containing the read flag corresponding to the read register instruction has been parsed, the target original Modbus protocol field is a register quantity field, and the register access information is parsed based on the preset transmission definition to obtain the file access information, including:

[0017] Parsing the register access information based on a preset transmission definition to obtain a data length as a second part of the file access information corresponding to the file read operation;

[0018] Accordingly, the accessing the file system based on the file access information to achieve file transfer includes:

[0019] Reading a file system based on the first part of the file access information and the second part of the file access information to obtain file data to be transmitted;

[0020] The file data to be transmitted is stored in the target register according to the access register address carried by the read register instruction, so that when a read register instruction carrying the access register address is received again, the file data to be transmitted in the target register is returned to realize file transmission.

[0021] Optionally, the target file is a configuration file containing file description information in a folder or a file in the folder.

[0022] Optionally, the read flag is recorded in a field describing the data length or a field describing the file data to be transmitted.

[0023] Optionally, after receiving the register access instruction of the Modbus protocol, the method further includes:

[0024] encapsulating a message based on the register access instruction;

[0025] The message is sent to a message mailbox corresponding to the virtual file system, so that the virtual file system reads the message from the message mailbox, and based on the message, executes the step of parsing the register access information based on a preset transmission definition to obtain file access information and accessing the file system based on the file access information to realize the file transfer step.

[0026] Optionally, also include:

[0027] Allocating address segments to multiple files on the Modbus register address segment to obtain pre-allocated address segments corresponding to the multiple files;

[0028] Instantiate multiple virtual file systems, and bind the multiple virtual file systems to the pre-allocated address segments and message mailboxes corresponding to the multiple files, respectively, so that a message corresponding to any file is sent to the message mailbox of the virtual file system corresponding to the any file.

[0029] In a second aspect, the present application discloses a file transmission method, which is applied to a master device, comprising:

[0030] Constructing a register access instruction of the Modbus protocol based on a preset transmission definition, wherein the preset transmission definition is a definition based on the target original Modbus protocol field description file access information;

[0031] The register access instruction is sent to the slave device so that the slave device receives the register access instruction of the Modbus protocol; when the access register address carried by the register access instruction belongs to the pre-allocated address segment, the register access information carried by the target original Modbus protocol field in the register access instruction is extracted, the register access information is parsed based on the preset transmission definition to obtain the file access information, and the file system is accessed based on the file access information to realize the file transfer;

[0032] The pre-allocated address segment is an address segment pre-allocated for file transmission on the Modbus register segment.

[0033] In a third aspect, the present application discloses a file transmission device, which is applied to a slave device, including:

[0034] An instruction receiving module, used for receiving register access instructions of the Modbus protocol;

[0035] An information extraction module, configured to extract register access information carried by a target original Modbus protocol field in the register access instruction when the access register address carried by the register access instruction belongs to a pre-allocated address segment, wherein the pre-allocated address segment is an address segment pre-allocated for file transfer on the Modbus register address segment;

[0036] An information parsing module, configured to parse the register access information based on a preset transmission definition to obtain file access information, wherein the preset transmission definition is a definition of the file access information based on the target original Modbus protocol field description;

[0037] The file access module is used to access the file system based on the file access information to achieve file transmission.

[0038] In a fourth aspect, the present application discloses a computer program product, which implements the aforementioned file transfer method when executed.

[0039] In a fifth aspect, the present application discloses an electronic device, including a memory and a processor, wherein:

[0040] The memory is used to store the computer program;

[0041] The processor is used to execute the computer program to implement the aforementioned file transmission method.

[0042] In a sixth aspect, the present application discloses a computer-readable storage medium for storing a computer program, wherein the computer program implements the aforementioned file transfer method when executed by a processor.

[0043] It can be seen from the above scheme that the present application provides a file transfer method, including: receiving a register access instruction of the Modbus protocol; when the access register address carried by the register access instruction belongs to a pre-allocated address segment, extracting the register access information carried by the target original Modbus protocol field in the register access instruction, wherein the pre-allocated address segment is an address segment pre-allocated for file transfer on the Modbus register address segment; parsing the register access information based on a preset transmission definition to obtain file access information, wherein the preset transmission definition is a definition of file access information described based on the target original Modbus protocol field; accessing the file system based on the file access information to achieve file transfer.

[0044] It can be seen that the beneficial effects of the present application are: pre-allocating address segments for file transfer on the Modbus register address segment, and describing file access information based on the original Modbus protocol field that describes register access information. When the access register address carried by the register access instruction belongs to the pre-allocated address segment, the register access information carried by the target original Modbus protocol field is parsed based on the preset transmission definition to obtain the file access information and perform file transfer. In this way, the register access instruction format of the original Modbus protocol used to access registers is used for file transfer, and the corresponding field description file access information is reused, which can avoid modifying the standard Modbus protocol, thereby ensuring the compatibility of the Modbus protocol and system performance.

[0045] Correspondingly, a file transfer device, product, equipment and readable storage medium provided by the present application also have the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0047] Figure 1 A flowchart of a file transmission method provided in an embodiment of the present application;

[0048] Figure 2 A file transfer solution system framework diagram provided in an embodiment of the present application;

[0049] Figure 3 A flowchart of another file transmission method provided in an embodiment of the present application;

[0050] Figure 4 A schematic diagram of the structure of a file transmission device provided in an embodiment of the present application;

[0051] Figure 5 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0052] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0053] At present, the existing file transfer scheme based on Modbus protocol usually needs to adjust the standard Modbus protocol and add additional Modbus function codes to realize file transfer. In this way, the protocol compatibility is reduced and even the system performance is affected. In summary, in the process of implementing the present invention, the inventors found that the prior art has at least the following problems: modifying the standard Modbus protocol, reducing the compatibility of the Modbus protocol, and affecting the system performance. In addition, the prior art requires the first frame to open the specified file in terms of the data frame requirements, and can only operate one file at the same time, and does not consider the transmission of file information. The host can only determine the clear file transfer object, and does not support random file access and operation. To this end, the present application provides a file transfer scheme to solve the above-mentioned technical problems.

[0054] Considering that Modbus protocol is a standard protocol, the entire embedded system will use the standard protocol. If the file transmission is realized by modifying Modbus protocol, the protocol compatibility will be reduced. Since file transmission is an uncommon function for embedded devices, generally user data export and firmware burning, if the standard Modbus protocol is modified, it may affect the existing system. Modbus protocol is essentially a protocol for reading and writing data / registers in embedded devices. This application is based on the design of register-based extended functions, that is, some continuous registers are selected in the register as space for file transmission, while other registers are still regular registers. After receiving the message, Modbus protocol will identify read and write operations according to the function code in the frame, and call back the read or write callback function accordingly. The external interface of the embedded platform is mainly a serial port, and most of them are Modbus protocol. The file system function of the system is also required for file transmission. Therefore, this application associates Modbus protocol with file system to realize a complete file transmission solution.

[0055] See also Figure 1 As shown, the embodiment of the present application discloses a file transmission method, which is applied to a slave device, including:

[0056] Step S11: receiving a register access instruction of the Modbus protocol.

[0057] Among them, the Modbus protocol is a network communication protocol for control, which follows the master-slave protocol and has a master-slave architecture. The master device is the initiator in the Modbus communication network, which is used to initialize communication and send a request message to the slave device. The slave device is the responder in the Modbus communication network, which is used to receive the request message from the master device and return a response message after performing the corresponding operation according to the request. The register access instruction can be carried in the request, and can include a write register instruction and a read register instruction, wherein the write register instruction can be a write continuous hold register instruction, and the read register instruction can be a read continuous hold register instruction.

[0058] Step S12: When the access register address carried by the register access instruction belongs to the pre-allocated address segment, the register access information carried by the target original Modbus protocol field in the register access instruction is extracted, wherein the pre-allocated address segment is an address segment pre-allocated for file transfer on the Modbus register address segment.

[0059] Among them, the access register address is the starting address of the access register, such as the starting address of the register to be written and the starting address of the register to be read. The embodiment of the present application pre-allocates the address segment for file transfer on the Modbus register address segment to obtain the pre-allocated address segment. The pre-allocated address segment is the Modbus register address segment not used by the user. The register access instruction of the file transfer can be distinguished from the register access instruction of the conventional register operation by accessing the register address. To transmit a single file, one pre-allocated address segment can be allocated; to transmit multiple files in parallel, multiple pre-allocated address segments can be allocated.

[0060] The target original Modbus protocol field can be understood as a field describing register access information. When the register access instruction is a write register instruction, the target original Modbus protocol field can be a data content field; when the register access instruction is a read register instruction, the target original Modbus protocol field can be a register quantity field.

[0061] Step S13: parsing the register access information based on a preset transmission definition to obtain file access information, wherein the preset transmission definition is a definition of file access information based on the target original Modbus protocol field description.

[0062] The file access information may be understood as parameters used to call a file system access interface to access a file.

[0063] In this embodiment, when the register access instruction is a write register instruction, the target original Modbus protocol field is a data content field; accordingly, the register access information is parsed based on the preset transmission definition to obtain file access information, including: parsing the register access information based on the preset transmission definition; if the read flag is not parsed, the file identifier of the target file parsed from the register access information, the offset of the file data to be transmitted within the target file, the data length corresponding to the file data to be transmitted, and the file data to be transmitted are used as the file access information corresponding to the write file operation.

[0064] That is, in the embodiment of the present application, the data content field in the Modbus protocol write register instruction is used to fill in the file access information, thereby realizing data writing to the file system.

[0065] Further, in the case of parsing the read flag, the file identifier of the target file parsed from the register access information and the offset of the file data to be transmitted in the target file are used as the first part of the file access information corresponding to the read file operation. The read flag can be contained in the field describing the data length or the field describing the file data to be transmitted. For example, it is 0 to inform the slave device that a read operation will be performed next.

[0066] When the register access instruction is a read register instruction, and the write register instruction containing the read flag corresponding to the read register instruction has been parsed, the target original Modbus protocol field is the register quantity field, and the register access information is parsed based on the preset transmission definition to obtain the file access information, including: parsing the register access information based on the preset transmission definition to obtain the data length as the second part of the file access information corresponding to the read file operation.

[0067] In the embodiment of the present application, the file corresponding to the read register instruction can be determined by the access register address carried in the read register instruction, thereby determining whether the write register instruction containing the read flag corresponding to the read register instruction has been parsed. In addition, the data length of the data to be transmitted is characterized based on the number of registers.

[0068] That is, when reading a file, the embodiment of the present application uses the data content field of the Modbus protocol write register instruction to transfer the file identifier of the target file and the offset of the file data to be transferred within the target file, and uses the register quantity field of the Modbus protocol read register instruction to transfer the data length of the data to be transferred and distinguish the target file based on the access register address of the Modbus protocol read register instruction.

[0069] Step S14: Access the file system based on the file access information to achieve file transfer.

[0070] The embodiment of the present application can call the file system write interface based on the file access information corresponding to the file write operation, determine the target file according to the file identifier of the target file, and write the file data to be transferred into the target file starting from the offset of the file data to be transferred within the target file.

[0071] In addition, the embodiment of the present application can read the file system based on the first part of the file access information and the second part of the file access information to obtain the file data to be transmitted; store the file data to be transmitted into the target register according to the access register address carried by the read register instruction, so that when the read register instruction carrying the access register address is received again, the file data to be transmitted in the target register is returned to realize file transfer.

[0072] That is, the target register is the register corresponding to the target file, and the target register can be determined according to the access register address. In the embodiment of the present application, the file data to be transferred is first read from the file system and stored in the target register by the write register instruction and the read register instruction, and then the file data to be transferred is read from the target register by the read register instruction and returned to the host device to realize the file transfer.

[0073] In an embodiment of the present application, the target file is a configuration file containing file description information under a folder or a file under the folder. The file description information may include the file name, file size, etc. of the file under the folder, and is saved in the form of a key-value (i.e., a key-value pair). For example, the key is the file name, the value is abc, and abc is the file name of a certain file. The file identifier can be used to distinguish whether the file description information under the folder or the file under the folder is transmitted. For example, the file identifier is 0, which indicates that the file description information under the folder is transmitted, and non-0 indicates the file under the folder. The file identifier of the file under the folder can be a file sequence number, for example, 1 represents the first file under the folder. Before transmitting the file under the folder, the file description information under the folder needs to be transmitted to synchronize the master and the slave, and then the file under the folder is transmitted.

[0074] See also Figure 2 As shown, Figure 2 A system framework diagram of a file transfer solution provided for an embodiment of the present application. The system consists of a transport layer, a register layer, and a file system layer. The Modbus transmission protocol is associated with the file system through a data structure and a business model, and finally the file transmission operation is realized, including file reading and file writing. Through this solution, the standard file transfer function based on the native standard Modbus protocol is realized without the need for an additional transport layer and file system.

[0075] In this embodiment, the transport layer uses the native Modbus protocol frame format and all definitions, and ensures the correctness of the transmitted data through the verification mechanism provided by Modbus transmission. Two types of operations involving multiple holding registers: continuous reading of multiple holding registers: reading file information or data; continuous writing of multiple holding registers: writing file information or data. File information refers to the file description information under the folder, that is, the folder information, and file data refers to the data of the file under the folder, that is, the file content. The original Modbus protocol is reused without any changes.

[0076] Furthermore, the data part of the Modbus protocol frame is extended and defined in the register layer, and the format is as follows: File ID (i.e., identification): used to identify the file object of the operation, 2 bytes (corresponding to 1 register); File offset: offset within the file, 8 bytes (corresponding to 4 registers); Data length: file data length to be transmitted in the current frame, 2 bytes (corresponding to 1 register); Operation data: file data to be transmitted. That is, the file identifier of the target file, the offset of the file data to be transmitted within the target file, the data length corresponding to the file data to be transmitted, and the file data to be transmitted. There is no mandatory requirement for the order of the above file identifier, file offset, data length, and operation data. This application defines file transfer transferable data: file information and file data. Among them, the file ID of the file information is 0, which is all the file information sets corresponding to the current access object, that is, all the file information contained in the folder, which can be included in the configuration file. If it is a file write, the folder is the folder to be written to the slave device by the master device, and if it is a file read, the folder is the folder to be read from the slave device.

[0077] The file data corresponds to a non-zero ID, which is used to identify the file sequence number contained in the file information, that is, the sequence number of the file in the folder. For example, the ID of the first file can be 1.

[0078] Further, the file system layer includes file reading and file writing. Among them, file writing: directly through the Modbus continuous write multiple holding register instructions, that is, by multiplexing the Modbus write instruction, the write operation in the file transfer is realized, and the target write file ID, the file write pointer position, the length to be written and the write data are filled into the data part. That is, the aforementioned file ID, file offset, data length, operation data. After receiving the frame message, the embedded software takes out the information of the data part in the message. Since this information is sufficient and complete information for operating a file, it can be directly connected to the write interface of the local Fat32 file system, that is, the write interface can be called to write the file data into the file system. The embodiment of the present application supports automatic opening of files, and stipulates that the system initialization phase (i.e., the initialization phase after the device is powered on) needs to synchronize the file information on the master and slave devices through the transmission of file information. It is also possible to transmit file information before transmitting file data to achieve file information synchronization. For example, before writing, the file information of the master device is transmitted to the slave device, and before reading, the file information of the slave device is transmitted to the master device. After obtaining the read file information or write file information, the file in the folder of the file system can be opened. During file transfer, the target write file or target read file is matched according to the file ID to see if it is already opened. If it is not opened, it is actively opened, otherwise the file is directly written or read. In the embodiment of the present application, the file is opened through the virtual file system. This solution also supports random writing, and calls the file system interface to move the file write pointer by matching the file offset.

[0079] For file reading, since the Modbus read instruction part does not contain the data part, the Modbus read instruction contains information such as the read address and read length, but does not contain the data part. Therefore, it is impossible to directly reuse the Modbus read instruction to implement the file read operation, that is, the lack of the data part makes it impossible to transmit the information of the read file, so it will not be possible to transmit the extended information, but the file read operation needs to include the file ID, file offset, and read length information. In the embodiment of the present application, the file read operation needs to implement the file read through two processes:

[0080] Process a: First, reuse the Modbus write command to pass the file information to be read to the embedded device. However, unlike writing, the data part includes the read file ID, the read file offset, and the read data length. This field is passed 0 and does not contain operation data. The purpose of passing the length 0 is to tell the target device to start the read operation next.

[0081] Process b: After sending the Modbus write command, you can read the file through the Modbus read command. At this time, the number of registers in the Modbus read frame is used as the read length of the file, and the starting address in the Modbus read command is used to identify the file object in process a (distinguish files when concurrent file transmission is required, and distinguish file access and regular register operations when a single file is required). According to the definition of the file system, the read pointer will move automatically each time the file is read. If random reading is required, process a must be executed each time the read pointer position is adjusted.

[0082] The file closing is managed by the file system itself and can be closed when the Modbus communication is abnormal.

[0083] In an optional implementation, a message can be encapsulated based on the register access instruction; the message is sent to a message mailbox corresponding to the virtual file system, so that the virtual file system reads the message from the message mailbox, and based on the message, parses the register access information based on a preset transfer definition to obtain file access information and accesses the file system based on the file access information to implement the file transfer step.

[0084] Among them, the message may carry various fields of the register access instruction. In an optional implementation, the virtual file system reads the message from the message mailbox. When the access register address carried by the register access instruction belongs to the pre-allocated address segment, the register access information carried by the target original Modbus protocol field in the register access instruction is extracted. In another optional implementation, when the access register address carried by the register access instruction belongs to the pre-allocated address segment, the message is not encapsulated and sent to the corresponding message mailbox.

[0085] In an optional implementation, address segments can be allocated to multiple files on the Modbus register address segment to obtain pre-allocated address segments corresponding to the multiple files; multiple virtual file systems are instantiated, and the multiple virtual file systems are respectively bound to the pre-allocated address segments and message mailboxes corresponding to the multiple files, so that a message corresponding to any file is sent to the message mailbox of the virtual file system corresponding to any file.

[0086] In the embodiment of the present application, the Modbus protocol stack maintains the existing implementation without any special modification, that is, it still only operates the registers; each transmission operation must be fully accessed in the form of a frame; in the read and write callback function, a message is sent to the virtual file system to the message mailbox; the virtual file system periodically (such as 10ms) queries the message mailbox to confirm whether there is a new transmission request, and after taking the message from the message mailbox, directly parses the register value, according to Figure 2The format in the file is used to retrieve the relevant information of the file operation according to the definition, and then call the target file system interface to perform the file operation. For the read operation, the file system interface call needs to be implemented in the Modbus read callback function to read the target data into the register.

[0087] For single file operation, that is, only operating a single file, allocate an address segment that is not used by the user on the Modbus register segment; bind the address segment to the virtual file system; poll the message mailbox, and process the corresponding transmission operation when there is a message.

[0088] For concurrent file operations, that is, transferring multiple files at the same time, multiple address segments that are not used by users are allocated on the Modbus register segment; multiple independent message mailboxes are defined, and multiple virtual file system services are instantiated, each of which is bound to the corresponding address segments and message mailboxes; each service is executed independently; the same file needs to be locked and protected in the system to prevent file operation conflicts.

[0089] It can be seen that the embodiment of the present application pre-allocates an address segment for file transfer on the Modbus register address segment, and describes the file access information based on the original Modbus protocol field that describes the register access information. When the access register address carried by the register access instruction belongs to the pre-allocated address segment, the register access information carried by the target original Modbus protocol field is parsed based on the preset transmission definition to obtain the file access information and perform the file transfer. In this way, the register access instruction format of the original Modbus protocol used to access the register is used for file transfer, and the corresponding field description file access information is reused, which can avoid modifying the standard Modbus protocol, thereby ensuring the compatibility of the Modbus protocol and system performance.

[0090] The embodiment of the present application has strong compatibility. It can continue to be a standard protocol without modifying the frame format and usage habits of the original Modbus protocol, and implement ModbusX FTP (i.e., File Transfer Protocol), which can meet the original protocol format of Modbus RTU (i.e., Remote Terminal Unit) or ModbusTCP (i.e., Transmission Control Protocol), ensuring compatibility with existing systems; it has strong scalability, is managed through registers and message mailboxes, can be flexibly expanded through multiple groups of registers, and the register address can also be dynamically adjusted, and has extremely high scalability as a whole. The protocol is expanded through the data part of the Modbus frame, which is specifically reflected in the use of specific registers as extended function codes, ensuring the scalability of the system, and concurrent operations can be achieved through multiple groups of registers. The extension part takes into account the file identifier, ensuring that a single frame can specify an operation file, thereby supporting parallel operation of multiple files. By introducing the transmission of file information, the entire solution can access / transfer folders and any files in the folders, and realize an FTP based on Modbus transmission. The file information is transmitted in the form of Key-Value to achieve the acquisition of local and remote file information, thereby supporting the optionality of file transmission; the file offset is considered in the extension part to ensure that a single frame can specify the file operation position to support random access / operation transmission of files; the function is realized through the data part of the transmission frame, that is, a file transfer protocol independent of the transmission channel is realized, which can be fully compatible with Modbus TCP transmission in Ethernet mode later, providing a new way for remote file access.

[0091] See also Figure 3 As shown, the embodiment of the present application discloses a file transmission method, which is applied to a main device, including:

[0092] Step S21: constructing a register access instruction of the Modbus protocol based on a preset transmission definition, wherein the preset transmission definition is a definition based on the target original Modbus protocol field description file access information.

[0093] Step S22: sending the register access instruction to the slave device so that the slave device receives the register access instruction of the Modbus protocol; when the access register address carried by the register access instruction belongs to the pre-allocated address segment, extracting the register access information carried by the target original Modbus protocol field in the register access instruction, parsing the register access information based on the preset transmission definition, obtaining the file access information, and accessing the file system based on the file access information to realize the file transfer;

[0094] The pre-allocated address segment is an address segment pre-allocated for file transmission on the Modbus register segment.

[0095] It can be seen that the embodiment of the present application pre-allocates an address segment for file transfer on the Modbus register address segment, and describes the file access information based on the original Modbus protocol field that describes the register access information. When the access register address carried by the register access instruction belongs to the pre-allocated address segment, the register access information carried by the target original Modbus protocol field is parsed based on the preset transmission definition to obtain the file access information and perform the file transfer. In this way, the register access instruction format of the original Modbus protocol used to access the register is used for file transfer, which can avoid modifying the standard Modbus protocol, thereby ensuring the compatibility of the Modbus protocol and system performance.

[0096] For example, the slave device is an air-conditioning device, and the master device is a maintenance personnel terminal. The maintenance personnel terminal can construct a register access instruction of the Modbus protocol based on the preset transmission definition, first construct a read register instruction of the file information of the target folder, read the file information of the target folder from the air-conditioning device, and the target folder is a folder containing a fault log file. Then, a write register instruction is constructed, and the identifier and file offset of the fault log file are filled in the data part, and the data length part is written as 0, which is sent to the air-conditioning device to inform the air-conditioning device that the fault log file will be read, and then a read register instruction is constructed, and the register address is the address corresponding to the fault log file, and the number of registers is the number corresponding to the data length of the data to be read, which is sent to the air-conditioning device. The air-conditioning device obtains the read file ID, file offset and data length based on the write register instruction and the read register instruction, and reads the fault log file data from the file system to the target register. The maintenance personnel terminal issues a read register instruction to read the fault log file data in the target register. Among them, the write register instruction and the read register instruction are the write continuous hold register instruction and the read continuous hold register instruction respectively. This realizes the fault log reading of the air-conditioning device. In addition, the maintenance personnel terminal can also write the configuration parameters of the air-conditioning device into the configuration parameter file of the air-conditioning device. The maintenance personnel terminal constructs a write register instruction, and the data part is the identifier of the configuration parameter file of the air conditioner, the offset of the parameter to be written in the file, the length of the parameter to be written, and the parameter to be written. The air conditioner parses the data part in the write register instruction, obtains the identifier of the configuration parameter file, the offset of the parameter to be written in the file, the length of the parameter to be written, and the parameter to be written, calls the write interface of the file system, and writes the configuration parameter file of the file system.

[0097] See also Figure 4 As shown, the embodiment of the present application discloses a file transmission device, which is applied to a slave device, including:

[0098] The instruction receiving module 11 is used to receive the register access instruction of the Modbus protocol;

[0099] An information extraction module 12 is used to extract the register access information carried by the target original Modbus protocol field in the register access instruction when the access register address carried by the register access instruction belongs to the pre-allocated address segment, wherein the pre-allocated address segment is an address segment pre-allocated for file transfer on the Modbus register address segment;

[0100] An information parsing module 13, configured to parse the register access information based on a preset transmission definition to obtain file access information, wherein the preset transmission definition is a definition of the file access information based on the target original Modbus protocol field description;

[0101] The file access module 14 is used to access the file system based on the file access information to achieve file transmission.

[0102] The information parsing module 13 is specifically used for: when the register access instruction is a write register instruction, the target original Modbus protocol field is a data content field; parsing the register access information based on a preset transmission definition; if the read flag is not parsed, the file identifier of the target file, the offset of the file data to be transmitted in the target file, the data length corresponding to the file data to be transmitted, and the file data to be transmitted parsed from the register access information are used as the file access information corresponding to the write file operation. If the read flag is parsed, the file identifier of the target file and the offset of the file data to be transmitted in the target file parsed from the register access information are used as the first part of the file access information corresponding to the read file operation.

[0103] The information parsing module 13 is specifically used for: when the register access instruction is a read register instruction, and the write register instruction containing the read flag corresponding to the read register instruction has been parsed, the target original Modbus protocol field is the register quantity field, parsing the register access information based on a preset transmission definition to obtain a data length as the second part of the file access information corresponding to the read file operation;

[0104] Correspondingly, the file access module 14 is specifically used to: read the file system based on the first part of the file access information and the second part of the file access information to obtain the file data to be transmitted; store the file data to be transmitted into the target register according to the access register address carried by the read register instruction, so that when the read register instruction carrying the access register address is received again, the file data to be transmitted in the target register is returned to realize file transfer.

[0105] In the embodiment of the present application, the target file is a configuration file containing file description information in a folder or a file in the folder. The read flag is recorded in a field describing the data length or a field describing the file data to be transmitted.

[0106] Furthermore, the device also includes:

[0107] A message encapsulation module, used for encapsulating a message based on the register access instruction;

[0108] The message sending module is used to send the message to the message mailbox corresponding to the virtual file system, so that the virtual file system reads the message from the message mailbox, and starts the information parsing module 13 and the file access module 14 to execute the parsing of the register access information based on the preset transmission definition based on the message, obtain the file access information, and access the file system based on the file access information to realize the file transfer step.

[0109] The device further comprises:

[0110] An address allocation module is used to allocate address segments to multiple files on the Modbus register address segment, and obtain pre-allocated address segments corresponding to the multiple files;

[0111] The binding module is used to instantiate multiple virtual file systems and bind the multiple virtual file systems to the pre-allocated address segments and message mailboxes corresponding to the multiple files, so that a message corresponding to any file is sent to the message mailbox of the virtual file system corresponding to the file.

[0112] It can be seen that the embodiment of the present application pre-allocates an address segment for file transfer on the Modbus register address segment, and describes the file access information based on the original Modbus protocol field that describes the register access information. When the access register address carried by the register access instruction belongs to the pre-allocated address segment, the register access information carried by the target original Modbus protocol field is parsed based on the preset transmission definition to obtain the file access information and perform the file transfer. In this way, the register access instruction format of the original Modbus protocol used to access the register is used for file transfer, and the corresponding field description file access information is reused, which can avoid modifying the standard Modbus protocol, thereby ensuring the compatibility of the Modbus protocol and system performance.

[0113] The embodiment of the present application discloses a computer program product, which implements the file transmission method disclosed in the above embodiment when executed.

[0114] For the specific process of the above-mentioned file transmission method, reference may be made to the corresponding contents disclosed in the above-mentioned embodiments, which will not be described in detail here.

[0115] See also Figure 5 As shown, an embodiment of the present application discloses an electronic device 20, including a processor 21 and a memory 22; wherein the memory 22 is used to store a computer program; the processor 21 is used to execute the computer program, and the file transfer method disclosed in the above embodiment.

[0116] For the specific process of the above-mentioned file transmission method, reference may be made to the corresponding contents disclosed in the above-mentioned embodiments, which will not be described in detail here.

[0117] Furthermore, the memory 22 as a carrier for storing resources may be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the storage method may be temporary storage or permanent storage.

[0118] In addition, the electronic device 20 also includes a power supply 23, a communication interface 24, an input / output interface 25 and a communication bus 26; wherein the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and an external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input / output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0119] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the file transfer method disclosed in the aforementioned embodiment.

[0120] For the specific process of the above-mentioned file transmission method, reference may be made to the corresponding contents disclosed in the above-mentioned embodiments, which will not be described in detail here.

[0121] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0122] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0123] The file transfer method, device, product, equipment and medium provided by the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A file transmission method, characterized in that: Applicable to slave devices, including: Receive register access instructions of Modbus protocol; When the access register address carried by the register access instruction belongs to the pre-allocated address segment, extracting the register access information carried by the target original Modbus protocol field in the register access instruction, wherein the pre-allocated address segment is an address segment pre-allocated for file transfer on the Modbus register address segment; Parsing the register access information based on a preset transmission definition to obtain file access information, wherein the preset transmission definition is a definition of the file access information based on the target original Modbus protocol field description; The file system is accessed based on the file access information to achieve file transfer.

2. The file transmission method according to claim 1, characterized in that: When the register access instruction is a write register instruction, the target original Modbus protocol field is a data content field; Accordingly, the register access information is parsed based on the preset transmission definition to obtain the file access information, including: parsing the register access information based on a preset transfer definition; If the read flag is not parsed, the file identifier of the target file, the offset of the file data to be transferred within the target file, the data length corresponding to the file data to be transferred, and the file data to be transferred parsed from the register access information are used as the file access information corresponding to the write file operation.

3. The file transmission method according to claim 2, characterized in that: The step of parsing the register access information based on the preset transmission definition to obtain the file access information further includes: When a read flag is parsed, the file identifier of the target file and the offset of the file data to be transferred within the target file parsed from the register access information are used as the first part of the file access information corresponding to the read file operation.

4. The file transmission method according to claim 3, characterized in that: When the register access instruction is a read register instruction, and the write register instruction containing the read flag corresponding to the read register instruction has been parsed, the target original Modbus protocol field is the register quantity field, and the register access information is parsed based on the preset transmission definition to obtain the file access information, including: Parsing the register access information based on a preset transmission definition to obtain a data length as a second part of the file access information corresponding to the file read operation; Accordingly, the accessing the file system based on the file access information to achieve file transfer includes: Reading a file system based on the first part of the file access information and the second part of the file access information to obtain file data to be transmitted; The file data to be transmitted is stored in the target register according to the access register address carried by the read register instruction, so that when a read register instruction carrying the access register address is received again, the file data to be transmitted in the target register is returned to realize file transmission.

5. The file transmission method according to claim 2, characterized in that: The target file is a configuration file containing file description information in a folder or a file in the folder.

6. The file transmission method according to claim 2, characterized in that: The read flag is recorded in the field describing the data length or the field describing the file data to be transmitted.

7. The file transmission method according to any one of claims 1 to 6, characterized in that: After receiving the register access instruction of the Modbus protocol, the method further includes: encapsulating a message based on the register access instruction; The message is sent to a message mailbox corresponding to the virtual file system, so that the virtual file system reads the message from the message mailbox, and based on the message, executes the step of parsing the register access information based on a preset transmission definition to obtain file access information and accessing the file system based on the file access information to realize the file transfer step.

8. The file transmission method according to claim 7, characterized in that: Also includes: Allocating address segments to multiple files on the Modbus register address segment to obtain pre-allocated address segments corresponding to the multiple files; Instantiate multiple virtual file systems, and bind the multiple virtual file systems to the pre-allocated address segments and message mailboxes corresponding to the multiple files, respectively, so that a message corresponding to any file is sent to the message mailbox of the virtual file system corresponding to the any file.

9. A file transmission method, characterized in that: Applicable to main equipment, including: Constructing a register access instruction of the Modbus protocol based on a preset transmission definition, wherein the preset transmission definition is a definition based on the target original Modbus protocol field description file access information; The register access instruction is sent to the slave device so that the slave device receives the register access instruction of the Modbus protocol; when the access register address carried by the register access instruction belongs to the pre-allocated address segment, the register access information carried by the target original Modbus protocol field in the register access instruction is extracted, the register access information is parsed based on the preset transmission definition to obtain the file access information, and the file system is accessed based on the file access information to realize the file transfer; The pre-allocated address segment is an address segment pre-allocated for file transmission on the Modbus register segment.

10. A file transmission device, characterized in that: Applicable to slave devices, including: An instruction receiving module, used for receiving register access instructions of the Modbus protocol; An information extraction module, configured to extract register access information carried by a target original Modbus protocol field in the register access instruction when the access register address carried by the register access instruction belongs to a pre-allocated address segment, wherein the pre-allocated address segment is an address segment pre-allocated for file transfer on the Modbus register address segment; An information parsing module, configured to parse the register access information based on a preset transmission definition to obtain file access information, wherein the preset transmission definition is a definition of the file access information based on the target original Modbus protocol field description; The file access module is used to access the file system based on the file access information to achieve file transmission.

11. A computer program product, characterized in that When the computer program product is executed, the file transmission method according to any one of claims 1 to 9 is implemented.

12. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store the computer program; The processor is used to execute the computer program to implement the file transmission method according to any one of claims 1 to 9.

13. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the file transmission method according to any one of claims 1 to 9 is implemented.

Citation Information

Cited By

  • Data processing method, system and device

    CN121396773A