An efficient and reliable method for upgrading software of multiple devices on RS485 bus
By subcontracting RS485 bus device software upgrade files and actively responding in a time-sharing manner, the problems of long transmission time and low reliability are solved, efficient and reliable multi-device software upgrades are achieved, and transmission efficiency and device response stability are improved.
Patent Information
- Application Number
- CN202410398278.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-03
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-04-03
AI Technical Summary
In the existing RS485 bus device software upgrade method, a single upgrade file data transmission leads to problems such as long transmission time, low reliability and low transmission efficiency.
Divide the software upgrade file into multiple data packets, and actively respond according to the device address, set the active delay response time, resend the data packets with timeout or error response, define the abnormal device entry and exit mechanism, update the response time, and realize the device Automatically upload status in a time-sharing manner.
It shortens the software upgrade time, improves transmission efficiency, avoids transmission interruption and waste, ensures the normal upgrade of other devices, and does not affect the response time of normal equipment.
Smart Images

Figure CN118138452B
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of software data processing, and in particular to an efficient and reliable method for upgrading the software of multiple devices on an RS485 bus. Background Art
[0002] The RS485 bus is a 2-wire, half-duplex, multi-node communication network with the characteristics of high data bandwidth, long-distance transmission, high anti-interference ability and flexible scalability. The RS485 bus is widely used in the fields of industrial automation and the Internet of Things, and has become a standard communication interface for industrial equipment. The RS485 bus network consists of a host computer and multiple devices. The host computer includes but is not limited to PC applications, data collectors, and intelligent gateways. The devices are various types of industrial equipment or the same type of equipment. In normal status, the host computer establishes communication with each device through the device protocol or device address to collect data or issue instructions.
[0003] In practical applications, for the convenience of management and maintenance, the host computer usually only connects one type of device or one communication protocol to the RS485 bus. In daily maintenance, it is necessary to upgrade the software of the RS485 bus devices. The software upgrade is actually divided into two steps: upgrade file transmission and device local update. The upgrade file transmission takes up most of the time of the entire upgrade process. Existing technologies usually use point-to-point transmission, broadcast transmission or broadcast + polling transmission for upgrade file transmission. In the above methods, once an abnormality occurs in the device in the RS485 bus, it will affect the transmission of subsequent data packets, resulting in long transmission time, low reliability and low transmission efficiency.
[0004] Therefore, how to provide a multi-device software upgrade method to reduce transmission time and improve transmission efficiency is a technical problem that needs to be urgently solved by technical personnel in this field. Summary of the invention
[0005] To this end, the present invention provides an efficient and reliable RS485 bus multi-device software upgrade method to solve the problems of long transmission time, low reliability and low transmission efficiency caused by the single transmission of existing upgrade file data in the prior art.
[0006] In order to achieve the above object, the present invention provides the following technical solutions:
[0007] An efficient and reliable method for upgrading software of multiple devices on RS485 bus, comprising the following steps:
[0008] Step S1: Obtain the software upgrade file, and the host computer divides the software upgrade file into multiple data packets;
[0009] Step S2: presetting device addresses for all devices on the RS485 bus, the devices receive data packets in sequence according to different device addresses, and actively respond in time-sharing;
[0010] Step S3: The devices preliminarily set the active delayed response time according to their respective device addresses;
[0011] Step S4: When the device response times out or the device response is received incorrectly, the host computer resends the data packet to the device and waits for the device to respond again;
[0012] Step S5: If the number of times the device re-responds exceeds the first threshold, the re-responding device is defined as an abnormal device, the host computer requests the abnormal device to enter the exit mechanism, and the devices update and set active delayed response time according to their respective device addresses.
[0013] Furthermore, in step S3, the devices preliminarily set the active delayed response time according to their respective device addresses through a first calculation function, and the first calculation function is:
[0014]
[0015] Where t is the unit response time of the device, B is the baud rate of the RS485 bus, 10 represents the number of bits transmitted in a single byte, Len is the number of bytes in the data packet, and T i is the active delayed response time of the i-th device, i is the rank of the i-th device, and n is the total number of devices.
[0016] Furthermore, in step S5, the devices update and set the active delayed response time according to their respective device addresses through a second calculation function, and the second calculation function is:
[0017]
[0018] Where t is the unit response time of the device, B is the baud rate of the RS485 bus, 10 represents the number of bits transmitted in a single byte, Len is the number of bytes in the data packet, and T i is the active delayed response time of the i-th device, i is the rank of the i-th device, m is the rank of the abnormal device, and n is the total number of devices.
[0019] Furthermore, in step S1, the host computer divides the software upgrade file into multiple data packets, specifically including:
[0020] Get the total number of bytes of the software upgrade file and the baud rate of the RS485 bus;
[0021] The baud rate of the RS485 bus determines the data length Len bytes of the upgrade file;
[0022] Divide the upgrade file into P data packets evenly according to the data length Len bytes;
[0023] If the number of bytes in the Pth data packet is less than Len bytes, the number of bytes in the Pth data packet is padded with 0 to Len bytes.
[0024] Furthermore, based on the preset device addresses of all devices on the RS485 bus, the host computer sends and receives broadcasts in sequence according to the device addresses, and records the device status of all devices, including:
[0025] All devices on the RS485 bus are preset with device addresses Add={1, 2, 3, ..., n}, where n is the total number of devices;
[0026] The host computer sends and receives broadcasts in the order of device addresses, turns on the device, and records the device status S = {S1, S2, S3, ..., S n}, where S1 is the device status of address 1, S2 is the device status of address 2, S3 is the device status of address 3, S n The device status of address n;
[0027] The host computer sends and receives broadcasts to the target device, obtains the device address of the target device, and marks the device status corresponding to the device address as ready for upgrade;
[0028] The device address of the non-target device is obtained, and the device state corresponding to the device address is marked as a silent state.
[0029] Further, based on a device response timeout or a device response reception error, the device re-responds, and the device state of the re-responding device is upgrade preparation, and the device state of the device that has completed the response is a silent state.
[0030] Furthermore, after the host computer requests the abnormal device to enter the exit mechanism, the device upgrade status is updated, specifically: the device address m of the abnormal device is obtained, and the device status S corresponding to the device address m is updated. m Mark as silent state.
[0031] Furthermore, in step S5, if the device successfully responds within the first threshold, the device is defined as a normal device, and continues to send data packets, and the device continues to respond according to the active delayed response time in step S3.
[0032] The present invention has the following advantages:
[0033] This application obtains the software upgrade file, and the host computer divides the software upgrade file into multiple data packets. The device addresses are preset for all devices on the RS485 bus. The devices receive data packets in sequence according to different device addresses and actively respond in time. The devices preliminarily set the active delayed response time according to their respective device addresses. When the device response times out or the device response is received incorrectly, the host computer resends the data packet to the device and waits for the device to respond again. If the number of device re-responses exceeds the first threshold, the re-responding device is defined as an abnormal device, and the host computer requests the abnormal device to enter the exit mechanism. The devices update the active delayed response time according to their respective device addresses.
[0034] The device response provided in this application adopts time-sharing active upload. The device sends the receiving status to the upper computer in sequence with a delay according to the device address, and the device actively uploads the status in time-sharing, which shortens the upgrade time. When the device response times out or the device responds to a reception error, the upper computer resends the data packet to the device and waits for the device to respond again, instead of interrupting the transmission or exiting the upgrade with an error, avoiding wasting transmission time and improving transmission efficiency. When the device that responds again is an abnormal device, the upper computer requests the abnormal device to enter the exit mechanism, which does not affect the upgrade of other normal devices. The remaining devices reduce the delayed response time, shorten the response time, and improve transmission efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the implementation methods of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the implementation methods or the description of the prior art. Obviously, the drawings in the following description are only exemplary, and for ordinary technicians in this field, other implementation drawings can be derived from the provided drawings without creative work.
[0036] The structures, proportions, sizes, etc. illustrated in this specification are only used to match the contents disclosed in the specification so as to facilitate understanding and reading by persons familiar with the technology. They are not used to limit the conditions under which the present invention can be implemented, and therefore have no substantial technical significance. Any structural modification, change in proportion or adjustment of size shall still fall within the scope of the technical contents disclosed in the present invention without affecting the effects and purposes that can be achieved by the present invention.
[0037] Figure 1 A flowchart of a multi-device software upgrade method provided by the present invention;
[0038] Figure 2 A device address map for presetting a RS485 bus device in the upgrade method provided by the present invention;
[0039] Figure 3 This is a delay diagram of the active response of the RS485 bus device in the upgrade method provided by the present invention. DETAILED DESCRIPTION
[0040] The following is a description of the implementation of the present invention by specific embodiments. People familiar with the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0041] In order to solve the problems of long transmission time, low reliability and low transmission efficiency caused by the single transmission of existing upgrade file data in the prior art, the present invention provides an efficient and reliable RS485 bus multi-device software upgrade method, such as Figure 1 As shown, the following steps are included:
[0042] Step S1: Obtain the software upgrade file, and the host computer divides the software upgrade file into multiple data packets;
[0043] Step S2: presetting device addresses for all devices on the RS485 bus, the devices receive data packets in sequence according to different device addresses, and actively respond in time-sharing;
[0044] Step S3: The devices preliminarily set the active delayed response time according to their respective device addresses;
[0045] Step S4: When the device response times out or the device response is received incorrectly, the host computer resends the data packet to the device and waits for the device to respond again;
[0046] Step S5: If the number of times the device re-responds exceeds the first threshold, the re-responding device is defined as an abnormal device, and the host computer requests the abnormal device to enter the exit mechanism, and the device updates and sets the active delayed response time according to its respective device address. If the device successfully responds within the first threshold, the device is defined as a normal device, and continues to send data packets, and the device continues to respond according to the active delayed response time in step S3.
[0047] The software upgrade file is transmitted to all devices on the RS485 bus through the host computer. The upgrade files are huge in number, so the upgrade files are divided into multiple data packets. Multiple data packets are transmitted to different devices on the RS485 bus in sequence. After receiving the data packet, the device actively responds to the host computer, indicating that the upgrade work of this device has been completed.
[0048] The upgrade file needs to be transmitted on the RS485 bus. Each device on the RS485 bus receives the data packet at a different time. In order to enable the device to automatically respond to its working status after receiving the data packet, set the active delay response time on each device. When the device response times out, the host computer retransmits the data packet to the timed-out device. At this time, the device that has completed the upgrade in front of the timed-out device remains silent and does not process or respond to information. If the device re-responds more than 3 times, the timed-out device enters the exit mechanism, so that the timed-out device always remains silent, and does not process or respond during subsequent data packet transmissions.
[0049] This application proposes a response mechanism, a retransmission mechanism and an exit mechanism in the upgrade file transmission process. The response mechanism proposes a communication method for the host computer to obtain the device status. After the host computer sends the data packet, it does not need to poll the device status again, which increases the bus time consumption. The device actively uploads the status in time-sharing, which shortens the upgrade time.
[0050] The retransmission mechanism provides a method for handling device abnormalities during the upgrade file transmission process. When the device receives an abnormality, you can try to retransmit the upgrade package instead of interrupting the transmission or reporting an error to exit the upgrade.
[0051] The exit mechanism proposes a method for handling abnormal devices after they exit the upgrade. When the device upgrade is abnormal, the upgrade must be exited without affecting the upgrade of other normal devices. After the normal device detects that a device has exited the upgrade, in order to shorten the response time, some devices will reduce the response delay. The exit mechanism further improves the reliability of RS485 bus upgrades.
[0052] like Figure 2 As shown in the figure, all devices on the RS485 bus have preset device addresses, and all devices are marked with device addresses 1 to n in sequence. Figure 3 As shown, the corresponding active delay response time is set according to each device on the RS485 bus.
[0053] In step S3, the devices preliminarily set the active delayed response time through a first calculation function according to their respective device addresses. The first calculation function is:
[0054]
[0055] Where t is the unit response time of the device, B is the baud rate of the RS485 bus, 10 represents the number of bits transmitted for a single byte: 1 start bit, 8 data bits, 1 stop bit, Len is the number of bytes in the data packet, T i is the active delayed response time of the i-th device, i is the rank of the i-th device, and n is the total number of devices.
[0056] The host computer sends a packet of data or message to the RS485 bus. After the transmission is completed, it no longer polls the reception status of each device, but the device actively responds in time-sharing. The device actively uploads the status in time-sharing, which shortens the upgrade time.
[0057] In step S5, the devices update and set the active delayed response time according to their respective device addresses through a second calculation function, where the second calculation function is:
[0058]
[0059] Where t is the unit response time of the device, B is the baud rate of the RS485 bus, 10 represents the number of bits transmitted for a single byte: 1 start bit, 8 data bits, 1 stop bit, Len is the number of bytes in the data packet, T i is the active delayed response time of the i-th device, i is the rank of the i-th device, m is the rank of the abnormal device, and n is the total number of devices.
[0060] If the device response times out or the device response reception error occurs, the host computer system will rebroadcast the last packet of data to the RS485 bus to allow these devices to receive it again. The devices that have successfully received the data will remain silent and will not process or respond. If the device re-responds more than 3 times, the host computer will send an exit command to the abnormal device. During the subsequent upgrade process, the abnormal device will remain silent. Other normal devices will parse the exit command sent by the host computer to obtain the address of the exit device. When the device address of the normal device is greater than the device address of the exit device, the response delay will automatically subtract one unit of response time in the subsequent upgrade, which can reduce the response time. If there are still abnormal devices in the subsequent upgrade process, the devices after the abnormal device address will continue to subtract one unit of response time when upgrading, and so on.
[0061] In step S1, the host computer divides the software upgrade file into multiple data packets, specifically including:
[0062] Get the total number of bytes of the software upgrade file and the baud rate of the RS485 bus;
[0063] Determine the data length Len bytes of the upgrade file based on the baud rate of the RS485 bus;
[0064] Divide the upgrade file into P data packets evenly according to the data length Len bytes;
[0065] If the number of bytes in the Pth data packet is less than Len bytes, the number of bytes in the Pth data packet is padded with 0 to Len bytes.
[0066] The host computer transmits P data to the devices on the RS485 bus in the order of device addresses. The devices on the RS485 bus receive the data packets and respond actively.
[0067] The data length Len is automatically adjusted with the baud rate of the RS485 bus. Common baud rates for the RS485 bus are 2400bps, 4800bps, 9600bps, 19200bps, 38400bps and 115200bps. On the one hand, the larger the baud rate, the more data is transmitted per unit time, but at the same time, the higher the baud rate, the higher the anti-interference capability of the RS485 bus. On the other hand, the larger the Len, the larger the data volume of a single transmission, and the higher the transmission efficiency. The corresponding relationship between the baud rate and the data length Len is shown in Table 1.
[0068] Table 1
[0069] Serial number Baud rate (bps) Data length Len (bytes) 1 2400 256 2 4800 256 3 9600 512 4 19200 512 5 38400 1024 6 115200 1024 7 other 512
[0070] The upgrade process proposes an adaptive baud rate transmission method, which solves the problem of bus interference caused by baud rate differences and ensures that the upgrade file transmission process is more reasonable and stable.
[0071] Based on the preset device addresses of all devices on the RS485 bus, the host computer sends and receives broadcasts in sequence according to the device addresses and records the device status of all devices, including:
[0072] All devices on the RS485 bus are preset with device addresses Add={1, 2, 3, ..., n}, where n is the total number of devices;
[0073] The host computer sends and receives broadcasts in the order of device addresses, turns on the device, and records the device status S = {S1, S2, S3, ..., S n}, where S1 is the device status of address 1, S2 is the device status of address 2, S3 is the device status of address 3, S n The device status of address n;
[0074] The host computer sends and receives broadcasts to the target device, obtains the device address of the target device, and marks the device status corresponding to the device address as ready for upgrade;
[0075] The device address of the non-target device is obtained, and the device state corresponding to the device address is marked as a silent state.
[0076] Based on the device response timeout or device response reception error, the device responds again, and the device status of the device that responds again is upgrade preparation, and the device status of the device that has completed the response is silent.
[0077] After the host computer requests the abnormal device to enter the exit mechanism, the device upgrade status is updated, specifically: obtain the device address m of the abnormal device, and update the device status S corresponding to the device address m. m Mark as silent state.
[0078] Data packets are transmitted in sequence according to device addresses 1 to n, and the host computer broadcasts devices 1 to n accordingly, prompting the target devices to prepare for the upgrade. For example, when device 1 receives a data packet, it marks device 1 as ready for upgrade and marks devices 2 to n as silent; when device 2 receives a data packet, it marks device 2 as ready for upgrade and marks devices 1 and 3 to n as silent; when device 3 receives a data packet, it marks device 3 as ready for upgrade and marks devices 1 to 2 and 4 to n as silent; when device n receives a data packet, it marks device n as ready for upgrade and marks devices 1 to n-1 as silent.
[0079] When the response of device m times out, the host computer retransmits the data packet to device m. At this time, device m is ready for upgrading, and devices 1 to m remain silent without processing or responding to information.
[0080] If the number of times device m re-responds is greater than 3, the device m enters the exit mechanism, so that the device m always remains in a silent state, and never processes or responds to subsequent data packets. The active delayed response time of devices m to n is reduced by one unit response time.
[0081] Before upgrading, devices that need to be upgraded are notified through broadcast to prepare for the upgrade, and devices that do not need to be upgraded remain silent. Upgrading on demand is more convenient and flexible.
[0082] Although the present invention has been described in detail above by general description and specific embodiments, it is obvious to those skilled in the art that some modifications or improvements can be made to the present invention. Therefore, these modifications or improvements made without departing from the spirit of the present invention all belong to the scope of protection claimed by the present invention.
Claims
1. An efficient and reliable method for upgrading software of multiple devices on RS485 bus. It is characterized in that The following steps are involved: Step S1: Obtain the software upgrade file, and the host computer divides the software upgrade file into multiple data packets; Step S2: presetting device addresses for all devices on the RS485 bus, the devices receive data packets in sequence according to different device addresses, and actively respond in time-sharing; Step S3: The devices preliminarily set the active delayed response time according to their respective device addresses; Step S4: When the device response times out or the device response is received incorrectly, the host computer resends the data packet to the device and waits for the device to respond again; Step S5: If the number of times the device re-responds exceeds the first threshold, the device that re-responds is defined as an abnormal device, the host computer requests the abnormal device to enter the exit mechanism, and the device updates and sets the active delayed response time according to its respective device address; In step S3, the devices preliminarily set the active delayed response time through a first calculation function according to their respective device addresses, and the first calculation function is: Where t is the unit response time of the device, B is the baud rate of the RS485 bus, 10 represents the number of bits transmitted in a single byte, Len is the number of bytes in the data packet, and T i is the active delayed response time of the i-th device, i is the rank of the i-th device, and n is the total number of devices; In step S5, the devices update and set the active delayed response time according to their respective device addresses through a second calculation function, where the second calculation function is: Where t is the unit response time of the device, B is the baud rate of the RS485 bus, 10 represents the number of bits transmitted in a single byte, Len is the number of bytes in the data packet, and T i is the active delayed response time of the i-th device, i is the rank of the i-th device, m is the rank of the abnormal device, and n is the total number of devices; In step S1, the host computer divides the software upgrade file into multiple data packets, specifically including: Get the total number of bytes of the software upgrade file and the baud rate of the RS485 bus; The baud rate of the RS485 bus determines the data length Len bytes of the upgrade file; Divide the upgrade file into P data packets evenly according to the data length Len bytes; If the number of bytes in the Pth data packet is less than Len bytes, the number of bytes in the Pth data packet is padded with 0 to Len bytes.
2. The method for efficiently and reliably upgrading the multi-device software of RS485 bus as claimed in claim 1, It is characterized in that Based on the preset device addresses of all devices on the RS485 bus, the host computer sends and receives broadcasts in sequence according to the device addresses and records the device status of all devices, including: All devices on the RS485 bus are preset with device addresses Add={1, 2, 3, ..., n}, where n is the total number of devices; The host computer sends and receives broadcasts in the order of device addresses, turns on the device, and records the device status S={S 1 , S 2 , S 3 , …, S n }, where S 1 The device state with address 1, S 2 The device status of address 2, S 3 The device status of address 3, S n The device status of address n; The host computer sends and receives broadcasts to the target device, obtains the device address of the target device, and marks the device status corresponding to the device address as ready for upgrade; The device address of the non-target device is obtained, and the device state corresponding to the device address is marked as a silent state.
3. the method for efficiently and reliably upgrading the multi-device software of RS485 bus as claimed in claim 2, It is characterized in that Based on the device response timeout or device response reception error, the device responds again, and the device status of the device that responds again is upgrade preparation, and the device status of the device that has completed the response is silent.
4. the method for efficiently and reliably upgrading the multi-device software of RS485 bus as claimed in claim 2, It is characterized in that After the host computer requests the abnormal device to enter the exit mechanism, the device upgrade status is updated, specifically: obtain the device address m of the abnormal device, and update the device status S corresponding to the device address m. m Mark as silent state.
5. The method for upgrading the multi-device software of RS485 bus efficiently and reliably as claimed in claim 1, It is characterized in that In step S5, if the device successfully responds within the first threshold, the device is defined as a normal device, and continues to send data packets. The device continues to respond according to the active delayed response time in step S3.
