Program downloading method, system and storage medium

By setting buffers and frame numbers in the PLC, the problem of slow PLC program file download speed was solved, enabling zero-wait data transfer and improving download efficiency.

CN116233207BActive Publication Date: 2026-04-21SHENZHEN CITY SAMKOON TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN CITY SAMKOON TECH
Filing Date
2023-02-20
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

In existing technologies, the download speed of PLC program files is relatively slow, especially when the data volume is large. The synchronous read and write speed is limited, while the asynchronous read and write speed is improved but is limited by the data transmission structure.

Method used

By using a buffer and frame sequence number method, a buffer is set in the RAM storage unit of the PLC, data frames are received according to the frame sequence number, and data blocks are moved to the Flash storage unit when the buffer is idle, thus realizing zero-wait data transfer.

Benefits of technology

It improves the download speed of PLC program files, reduces the parsing time of frame headers and tails, makes full use of buffer idle time, realizes zero-wait data transfer, and improves download efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116233207B_ABST
    Figure CN116233207B_ABST
Patent Text Reader

Abstract

This application discloses a program download method, system, and storage medium, relating to the field of controller technology. The program download method includes: receiving a download command from a host computer to enter a download mode, and receiving a data frame sent by the host computer, wherein the data frame includes a program file fragment and a corresponding frame number; reading the data frame into a preset buffer according to the frame number, wherein the buffer is located in the PLC's RAM storage unit; when the free space in the current buffer meets a preset condition, reading the next data frame into the buffer; forming a data block based on the program file fragment in the data frame, and writing the data block from the RAM storage unit's buffer to the PLC's Flash storage unit; obtaining the program file fragment based on the data block written to the Flash storage unit, and obtaining the program file based on the program file fragment. This application can improve the program download speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of controller technology, and in particular to a program downloading method, system, and storage medium. Background Technology

[0002] In related technologies, PLCs (Programmable Logic Controllers), as a core control device for automation, are widely used in many automated devices. To control related equipment via a PLC, the written program file needs to be transferred to the PLC for downloading. Currently, common file download methods for PLCs include synchronous read / write and asynchronous read / write. Synchronous read / write is relatively slow, and when the data volume is large, the downloaded data is of poor quality, which can limit its application scope. While asynchronous read / write can improve download speed, the improvement is limited by the data transmission structure. Therefore, how to improve the download speed of program files has become an urgent technical problem to be solved. Summary of the Invention

[0003] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes a program download method, system, and storage medium that can effectively improve program download speed.

[0004] The program downloading method according to the first aspect of this application, applied to a programmable logic controller (PLC), includes:

[0005] The system receives a download command from the host computer to enter download mode and receives data frames sent by the host computer, wherein the data frames include program file fragments and corresponding frame numbers;

[0006] The data frame is read into a preset buffer according to the frame sequence number, wherein the buffer is set in the RAM storage unit of the PLC;

[0007] When the current free space in the buffer meets the preset conditions, the next data frame is read into the buffer;

[0008] Data blocks are formed based on the program file fragments in the data frame, and the data blocks are written from the buffer of the RAM storage unit to the Flash storage unit of the PLC.

[0009] The program file fragment is obtained from the data block written to the Flash storage unit, and the program file is obtained from the program file fragment.

[0010] The program download method according to the embodiments of this application has at least the following beneficial effects: First, the system enters download mode upon receiving a download instruction from the host computer and receives a data frame sent by the host computer, wherein the data frame includes a program file fragment and a corresponding frame number; second, the data frame is read into a preset buffer according to the frame number, wherein the buffer is set in the RAM storage unit of the PLC; third, when the free space of the current buffer meets a preset condition, the next data frame is read into the buffer; then, a data block is formed according to the program file fragment in the data frame, and the data block is written from the buffer of the RAM storage unit to the Flash storage unit of the PLC; finally, the program file fragment is obtained according to the data block written to the Flash storage unit, and the program file is obtained according to the program file fragment. The program download method of this application, on the one hand, only requires setting the buffer and the frame sequence number of the data frame to receive data frames according to the set frame sequence number and quickly read data, without the need to set frame headers and trailers, reducing the parsing time of frame headers and trailers and improving data reading efficiency; on the other hand, when data blocks begin to appear in the buffer, the data blocks in the buffer are moved to the Flash storage unit without waiting for all data transmission to be completed before data movement, achieving zero-wait movement and further improving download speed. Therefore, the program download method of this application can effectively improve the program download speed by setting a buffer and achieving zero wait.

[0011] According to some embodiments of this application, the step of receiving a download instruction from the host computer to enter the download mode includes:

[0012] The communication port of the host computer communicating with the PLC is identified according to the download instruction, and the operation interface corresponding to the buffer of the communication port is initialized.

[0013] According to some embodiments of this application, before reading the data frame into a preset buffer according to the sequence number, the method includes:

[0014] Based on the data partitions contained in the program file, determine the data erasure order of the Flash storage unit;

[0015] According to the data erasure order, the data in the Flash storage unit is erased sequentially in units of Flash sectors to obtain the data space required for each data partition.

[0016] According to some embodiments of this application, the step of forming a data block based on the program file fragment in the data frame and writing the data block from the buffer of the RAM storage unit to the Flash storage unit of the PLC includes:

[0017] Data blocks are formed based on the program file fragments in the data frame, and the data blocks are moved from the buffer of the RAM storage unit to the Flash storage unit of the PLC;

[0018] Release the buffer memory occupied by the data block to adjust the size of the free space in the buffer.

[0019] According to some embodiments of this application, the step of reading the next data frame into the buffer when the current free space of the buffer meets a preset condition includes:

[0020] If the current free space is greater than the data size of the received data frame, adjust the receiving address;

[0021] The next data frame is read into the buffer according to the adjusted receive address.

[0022] According to some embodiments of this application, the method further includes:

[0023] The data blocks written to the Flash storage unit are verified.

[0024] According to some embodiments of this application, the verification of the data block written to the Flash storage unit includes:

[0025] Based on the data partitions contained in the program file, the data in each data partition is verified, and the program file corresponding to the data block that passes the verification is determined as the target file that has been successfully downloaded.

[0026] According to some embodiments of this application, the method further includes:

[0027] Enter run mode to execute the program file.

[0028] A program download system according to a second aspect embodiment of this application includes:

[0029] At least one memory;

[0030] At least one processor;

[0031] At least one program;

[0032] The program is stored in the memory, and the processor executes at least one of the programs to implement the program download method as described in the first aspect embodiment.

[0033] According to a third aspect embodiment of the present application, a computer-readable storage medium stores computer-executable instructions for causing a computer to perform a program downloading method as described in the first aspect embodiment.

[0034] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0035] The present application will be further described below with reference to the accompanying drawings and embodiments, wherein:

[0036] Figure 1 This is an architecture diagram of a program download system provided in one embodiment of this application;

[0037] Figure 2 This is a schematic flowchart illustrating a program download method provided in one embodiment of this application;

[0038] Figure 3 This is a schematic diagram of the structure of a data frame provided in one embodiment of this application;

[0039] Figure 4 This is a schematic diagram of the structure of a buffer provided in one embodiment of this application;

[0040] Figure 5 A flowchart illustrating a program download method provided in another embodiment of this application;

[0041] Figure 6 This is a schematic diagram of the structure of a program download system provided in one embodiment of this application.

[0042] Figure label:

[0043] Memory 200, processor 300. Detailed Implementation

[0044] The embodiments of this application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0045] It should be noted that although functional modules are divided in the system diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the system or the order in the flowchart. The terminology in the specification, claims, and the foregoing figures is used to distinguish similar objects and is not necessarily used to describe a specific order or sequence.

[0046] In the description of this application, "several" means one or more, "multiple" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.

[0047] In the description of this application, unless otherwise expressly defined, terms such as "setup," "installation," and "connection" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this application in conjunction with the specific content of the technical solution.

[0048] In the description of this application, the terms "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0049] The following is an explanation of some of the terms used in this application.

[0050] PLC (Programmable Logic Controller): Programmable logic controller.

[0051] FIFO (First In First Out): A data cache structure that operates on a first-in, first-out basis.

[0052] RAM: Random Access Memory (RAM), also known as "random access memory," is an internal memory that directly exchanges data with the CPU; it is also called main memory. It can be read and written at any time, and the speed is very fast.

[0053] FLASH: Flash memory is a type of memory device, specifically a non-volatile memory.

[0054] USB: Universal Serial Bus (USB) is a serial bus standard for connecting computer systems to external devices. It is also a technical specification for input / output interfaces and is widely used in personal computers, mobile devices, and other information and communication products.

[0055] RS-232: One of the communication interfaces on personal computers, an asynchronous transmission standard interface defined by the Electronic Industries Association (EIA). RS-232 interfaces typically appear in 9-pin (DB-9) or 25-pin (DB-25) configurations. Personal computers generally have two RS-232 interfaces, referred to as COM1 and COM2 respectively.

[0056] RS485: RS485 is a standard that defines the electrical characteristics of drivers and receivers in a balanced digital multipoint system. This standard was defined by the Telecommunications Industry Association and the Electronic Industries Alliance. Digital communication networks using this standard can effectively transmit signals over long distances and in environments with high electronic noise.

[0057] In PLC download applications, the speed of downloading and updating program files plays a crucial role in the efficiency and experience of research and development. Therefore, how to improve the speed of program download and updates is an important technical issue.

[0058] It should be noted that, as Figure 1 The figure shows the system model of the program download system of this application. The program file of the PLC is downloaded by the corresponding host software in the PC. The receiving end is the PLC controller. The specific hardware communication end is USB, RS232 or RS485.

[0059] Functionally, the entire update process involves the host software copying the program file data to the PLC's storage unit. For PLC systems, the main factors affecting download speed during program updates are: the upper limit bandwidth of PLC hardware communication peripherals, the data transfer speed of the data transfer unit, and the read / write speed of the memory unit.

[0060] Analysis shows that, given limited hardware resources, improving update download speed to approach the minimum total latency caused by hardware primarily depends on the software download algorithm. Currently, common implementation solutions include:

[0061] 1. Synchronous read and write

[0062] This method reads the data into RAM, then moves the read data to Flash, and repeats this process until all the program file data has been moved. After that, the Flash is read to verify the moved data, which is a "read-before-write" waiting operation synchronous method.

[0063] 2. Asynchronous read / write

[0064] This method performs the operations of reading data into RAM and transferring RAM data to Flash asynchronously, i.e., the "read-write" method, which is more efficient than the synchronous read-write operation.

[0065] The above method has the following drawbacks:

[0066] 1. Synchronous read and write will slow down the download speed due to software processing and significantly reduce the speed of program download and updates.

[0067] 2. Although asynchronous read / write is more efficient than synchronous read / write, it is constrained by the traditional data frame structure (frame header + data + frame trailer), which requires additional memory overhead for data frame parsing and introduces memory data transfer operations again, thereby increasing time overhead and slowing down download speed.

[0068] Based on this, this application provides a program download method, system, and storage medium. The method of defining a single circular buffer is used to achieve asynchronous download, which makes full use of the idle time of the PLC when receiving data blocks to transfer RAM data to the FLASH memory, achieving zero waiting time. This reduces memory usage while further improving the speed of PLC program update and download.

[0069] Below, according to Figure 2 This application describes a program download method according to an embodiment.

[0070] It is understandable that, such as Figure 2 As shown, a program download method is provided, applied to a programmable logic controller (PLC), the method comprising:

[0071] Step S100: Receive a download instruction from the host computer to enter download mode, and receive a data frame sent by the host computer, wherein the data frame includes a program file fragment and a corresponding frame number.

[0072] It should be noted that, as Figure 3 As shown, the program file to be received by the PLC contains user data (USER area, ladder diagram), XML data area, and CONFIG configuration area data, with a total size of less than 128KB. During transmission, the host computer extracts the file data to be downloaded according to the data frame structure defined by the transmission protocol and adds the frame sequence number (num) and data CRC checksum to the end. Therefore, the redefined data frame includes a frame sequence number, data partitions, and CRC checksum.

[0073] Step S110: Read the data frame into a preset buffer according to the frame sequence number, wherein the buffer is set in the RAM storage unit of the PLC;

[0074] Step S120: When the current free space of the buffer meets the preset conditions, the next data frame is read into the buffer;

[0075] Step S130: Form a data block based on the program file fragment in the data frame, and write the data block from the buffer of the RAM storage unit to the Flash storage unit of the PLC.

[0076] It should be noted that, as Figure 4 As shown, in PLCs with limited memory resources, constructing a buffer of appropriate size is extremely important to the PLC's resource overhead. In order to meet the data frame structure specified by the protocol, the buffer size is defined as size = 1028 bytes in this scheme, but the operable buffer is 1024 bytes. The size of the data received and read each time is set as data block block_size, where rd_idx is the index of the data block that has been read into the buffer (read index) and wr_idx is the index of the data block that has been written to Flash (write index).

[0077] It should be noted that the smallest adjustable unit for reading the index rd_idx is block_size. Therefore, when rd_idx - wr_idx = block_size, the system's read / write efficiency is optimal, with no waiting time. However, writing to Flash requires an additional command sequence. Performing too many of these operations will consume time and reduce download speed. Therefore, the amount of data transferred to Flash each time can be adjusted to block_size * n (where n is an integer multiple), depending on the situation. Specifically, writing to Flash requires an additional command sequence to unlock or disable Flash read / write operations. During this process, it is necessary to poll and wait for the corresponding registers to be set. Performing too many of these operations will consume time.

[0078] Step S140: Obtain the program file fragment based on the data block written to the Flash storage unit, and obtain the program file based on the program file fragment.

[0079] The system receives a download command from the host computer to enter download mode and receives data frames sent by the host computer. Each data frame includes a program file fragment and a corresponding frame number. Next, the data frame is read into a preset buffer based on the frame number, which is located in the PLC's RAM storage unit. Then, when the free space in the current buffer meets a preset condition, the next data frame is read into the buffer. Afterward, data blocks are formed based on the program file fragments in the data frames, and these data blocks are written from the RAM storage unit's buffer to the PLC's Flash storage unit. Finally, the program file fragment is obtained from the data blocks written to the Flash storage unit, and the program file is obtained from the program file fragments. This program download method, on the one hand, only requires setting the buffer and the frame number of the data frame to receive data frames according to the set frame number and quickly read data, eliminating the need to set frame headers and trailers, reducing the parsing time for frame headers and trailers, and improving data reading efficiency. On the other hand, when data blocks begin to appear in the buffer, the data blocks in the buffer are moved to the Flash storage unit without waiting for all data transmission to complete, achieving zero-wait data transfer and further improving download speed. Therefore, the program download method of this application can effectively improve the program download speed by setting a buffer and zero waiting time.

[0080] Understandably, receiving a download command from the host computer and entering download mode includes:

[0081] The download command identifies the communication port of the host computer that communicates with the PLC, and initializes the operation interface corresponding to the buffer of the communication port.

[0082] It should be noted that, before reading the data frame into the preset buffer according to the sequence number, the method includes:

[0083] Based on the data partitions contained in the program file, determine the data erasure order of the Flash storage unit;

[0084] According to the data erasure order, the data in the Flash storage unit is erased sequentially in units of Flash sectors to obtain the data space required for each data partition.

[0085] It should be noted that the step of forming a data block based on the program file fragment in the data frame and writing the data block from the buffer of the RAM storage unit to the Flash storage unit of the PLC includes:

[0086] Data blocks are formed based on the program file fragments in the data frame, and the data blocks are moved from the buffer of the RAM storage unit to the Flash storage unit of the PLC;

[0087] Release the buffer memory occupied by the data block to adjust the size of the free space in the buffer.

[0088] It is understood that the step of reading the next data frame into the buffer when the current free space of the buffer meets the preset conditions includes:

[0089] If the current free space is greater than the data size of the received data frame, adjust the receiving address;

[0090] The next data frame is read into the buffer according to the adjusted receive address.

[0091] It is understood that the method also includes:

[0092] The data blocks written to the Flash storage unit are verified.

[0093] It is understood that the verification of the data block written to the Flash storage unit includes:

[0094] Based on the data partitions contained in the program file, the data in each data partition is verified, and the program file corresponding to the data block that passes the verification is determined as the target file that has been successfully downloaded.

[0095] Understandably, the methods also include:

[0096] Enter run mode to execute the program file.

[0097] The following is combined Figure 5 This application describes a method for downloading a program according to an embodiment.

[0098] The specific steps for concurrent read and write operations using multithreading are as follows:

[0099] Step 1: Enter download mode:

[0100] Upon receiving the correct start download instruction sequence, the PLC identifies the communication port currently used for downloading, initializes the buffer operation interface corresponding to this communication port, and enters download mode.

[0101] Step 2: Erase sectors in stages:

[0102] The PLC begins reading the program data contained in the data frame into the buffer. Before transferring the data from the buffer to the Flash memory, it performs a Flash erase operation to ensure that the Flash erase operation precedes the data writing operation, eliminating waiting time during data writing. Because the larger the Flash erase space, the longer the erasure process, the erase operation does not erase the entire programming space at once, but rather in multiple stages, with the size of the erased area measured in Flash sectors. Specifically, because the larger the Flash erase space, the longer the erase process, the erase operation does not erase all the space required for program data at once. Instead, it is performed in three stages based on the three main areas of the program file (USER area (ladder diagram), XML data area, and CONFIG configuration area). After the previous area is erased, the next area is erased, and the size of each erase operation is measured in Flash sectors.

[0103] Step 3: RAM Data Transfer

[0104] When a data block begins to appear in the buffer, the data in the buffer can be moved to the program memory Flash, i.e., a Flash write operation is performed. After the data block is moved, the buffer is marked as releasing the memory of this data block, and the size of the free space in the buffer is automatically adjusted.

[0105] Step 4, Read-Write Loop:

[0106] The system checks if the current buffer has enough free space to write data. If so, after each data block is received, the address for the next reception is adjusted within the buffer, and the next data block is read in. It's important to note that the data from the next frame will overwrite the end of the previous frame. This process is repeated until all data has been received. It's crucial to ensure that reading data blocks precedes transferring them to Flash, so that the buffer always contains unwritten data, preventing Flash write operations from waiting for data to be read into the buffer and thus reducing download speed. If the write condition is not met, the system must wait.

[0107] Specifically, when the size of the free space is greater than the size of the currently received data frame, after each data block is received, the address for the next reception is adjusted in the buffer, and the next data block is read in. If the condition is not met, it is necessary to wait. It should be noted that the data of the next frame will overwrite the frame tail structure of the previous frame. This operation is repeated until all data is received.

[0108] Step 5: Partition Verification

[0109] Once all data blocks have been transferred, the written program file undergoes partition verification (three data partitions). This involves reading FLASH data from different data areas for verification. If the verification passes, the download is successful; otherwise, the download fails, and the process waits for the next download cycle to begin.

[0110] Step 6: The download process is complete. Enter the running mode and execute the program.

[0111] The program download method of this application has the following effects:

[0112] Firstly, a small FIFO buffer is all that's needed to efficiently and reliably complete the download and update process.

[0113] Compared to synchronous read / write methods, which typically require defining buffers of tens or hundreds of KB, and traditional asynchronous read / write methods, which require additional RAM space to assist in processing traditional data structures (frame header + data + frame tail), this method only needs a 1028-byte FIFO buffer to efficiently complete the update task of the downloaded program file; it is especially superior in memory-scarce situations.

[0114] Secondly, multiple communication ports can share the same buffer by simply registering the corresponding buffer operation interface, thus reducing the overhead of PLC memory resources.

[0115] Thirdly, it makes full use of the idle time when the data block is received to move the RAM data to the Flash, achieving zero waiting time for data transfer and greatly improving the download speed.

[0116] In summary, this method requires minimal memory resources, has a simple, efficient, and reliable download process, and is compatible with various hardware communication ports, making it suitable for applications in resource-constrained PLC controllers or scenarios with limited memory.

[0117] The following reference Figure 6 This application describes a program download system according to an embodiment of the present application.

[0118] It is understandable that, such as Figure 6 As shown, the program download system includes:

[0119] At least one memory 200;

[0120] At least one processor 300;

[0121] At least one program;

[0122] The program is stored in memory 200, and processor 300 executes at least one program to implement the program download method described above. Figure 6 Take a processor 300 as an example.

[0123] The processor 300 and the memory 200 can be connected via a bus or other means. Figure 6 Take a bus connection as an example.

[0124] The memory 200, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and signals, such as the program instructions / signals corresponding to the program download system in this embodiment. The processor 300 executes various functional applications and data processing by running the non-transitory software programs, instructions, and signals stored in the memory 200, thereby implementing the program download method of the above-described method embodiment.

[0125] The memory 200 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data related to the program download method described above. Furthermore, the memory 200 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory 200 may optionally include memory remotely located relative to the processor 300, and these remote memories can be connected to the program download system via a network. Examples of such networks include, but are not limited to, the Internet of Things (IoT), software-defined networks, sensor networks, the Internet, enterprise intranets, local area networks (LANs), mobile communication networks, and combinations thereof.

[0126] One or more signals are stored in memory 200, and when executed by one or more processors 300, the program download method in any of the above method embodiments is executed. For example, the method described above is executed.

[0127] The following reference Figure 6 This application describes a computer-readable storage medium according to embodiments thereof.

[0128] like Figure 6 As shown, a computer-readable storage medium stores computer-executable instructions that are executed by one or more processors 300, for example, by... Figure 6 One or more processors 300 may execute the program download method described in the above method embodiments. For example, the method described above may be executed.

[0129] The system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0130] Based on the above description of the embodiments, those skilled in the art will understand that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media and communication media. As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital multifunction disk or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is known to those skilled in the art that communication media typically contain computer-readable signals, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and can include any information delivery medium.

[0131] The embodiments of this application have been described in detail above with reference to the accompanying drawings. However, this application is not limited to the above embodiments. Within the scope of knowledge possessed by those skilled in the art, various changes can be made without departing from the spirit of this application. Furthermore, unless otherwise specified, the embodiments and features described in the embodiments of this application can be combined with each other.

Claims

1. A program download method, characterized in that, The method, applied to a programmable logic controller (PLC), includes: The system receives a download command from the host computer to enter download mode and receives data frames sent by the host computer, wherein the data frames include program file fragments and corresponding frame numbers; The data frame is read into a preset buffer according to the frame number, wherein the buffer is set in the RAM storage unit of the PLC; the minimum unit that the read index of the buffer can be adjusted each time is a data block; When the current free space in the buffer meets the preset conditions, the next data frame is read into the buffer; Data blocks are formed based on the program file fragments in the data frame, and the data blocks are written from the buffer of the RAM storage unit to the Flash storage unit of the PLC. The program file fragment is obtained from the data block written to the Flash storage unit, and the program file is obtained from the program file fragment; The step of writing the data block from the buffer of the RAM storage unit to the Flash storage unit of the PLC includes: adjusting the amount of data moved from the buffer to the Flash storage unit each time to n times the amount of the data block, based on the time consumption of the additional command sequence required when writing to the Flash storage unit, where n is an integer; the additional command sequence is used to unlock or disable the read and write operations of the Flash storage unit.

2. The program download method according to claim 1, characterized in that, The step of receiving a download command from the host computer to enter download mode includes: The communication port of the host computer communicating with the PLC is identified according to the download instruction, and the operation interface corresponding to the buffer of the communication port is initialized.

3. The program download method according to claim 1, characterized in that, Before reading the data frame into a preset buffer according to the sequence number, the method includes: Based on the data partitions contained in the program file, determine the data erasure order of the Flash storage unit; According to the data erasure order, the data in the Flash storage unit is erased sequentially in units of Flash sectors to obtain the data space required for each data partition.

4. The program download method according to claim 1, characterized in that, The step of forming a data block based on the program file fragment in the data frame and writing the data block from the buffer of the RAM storage unit to the Flash storage unit of the PLC includes: Data blocks are formed based on the program file fragments in the data frame, and the data blocks are moved from the buffer of the RAM storage unit to the Flash storage unit of the PLC; Release the buffer memory occupied by the data block to adjust the size of the free space in the buffer.

5. The program download method according to claim 1, characterized in that, The step of reading the next data frame into the buffer when the current free space of the buffer meets a preset condition includes: If the current free space is greater than the data size of the received data frame, adjust the receiving address; The next data frame is read into the buffer according to the adjusted receive address.

6. The program download method according to claim 1, characterized in that, The method further includes: The data blocks written to the Flash storage unit are verified.

7. The program download method according to claim 6, characterized in that, The verification of the data block written to the Flash storage unit includes: Based on the data partitions contained in the program file, the data in each data partition is verified, and the program file corresponding to the data block that passes the verification is determined as the target file that has been successfully downloaded.

8. The program download method according to claim 1, characterized in that, The method further includes: Enter run mode to execute the program file.

9. A program download system, characterized in that, include: At least one memory; At least one processor; At least one program; The program is stored in the memory, and the processor executes at least one of the programs to implement the program download method as described in any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions for causing a computer to perform the program download method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Data reading and writing method and device based on asynchronous annular buffer area

    CN110704335A

  • Real-time data processing method and device and equipment

    CN111405040A