485 time-sharing communication-based equipment resource acquisition methodTechnical Field
The invention relates to the field of communication, in particular to a 485 time-sharing communication-based equipment resource acquisition method.
Background
When the half-duplex 485 communication mode is applied to a plurality of master nodes and slave nodes, only one node can send data at a time, and if a plurality of nodes send data at the same time, communication conflict occurs. The conventional method for acquiring resources of communication equipment generally uses such a half-duplex 485 communication mode, which includes the following two methods:
the first is to adopt a polling mode of the master device, the master device is always master, the slave device is always slave, the master device initiates communication each time, and the slave device responds, so that communication collision is not easy to occur, but the polling mode of the master device is queried at certain intervals, so that the efficiency of acquiring resources is low. Particularly, when the slave equipment has no resource change, the master equipment also sends an acquisition command to the slave equipment for resource acquisition, the interval time of each acquisition is short, the consumption of the MCU of the master equipment is overlarge, and other tasks are influenced; the second is to adopt a mode of reporting resource change to the master device by the slave device, and because the mode is a half-duplex 485 communication mode, communication conflict can be caused, and finally the slave device needs to repeatedly send the resource change to the master device.
In summary, the existing method for acquiring resources by using a half-duplex 485 communication mode has the following disadvantages:
(1) the efficiency of collecting resources is low;
(2) communication collisions are easily generated.
Disclosure of Invention
The invention aims to solve the technical problems that the existing method for acquiring resources of communication equipment by using a half-duplex 485 communication mode is low in efficiency and easy to generate communication conflicts.
In order to solve the technical problem, the technical scheme adopted by the invention is to provide an equipment resource acquisition method based on 485 time-sharing communication, which comprises the following steps:
determining the time slot of the master device and each slave device connected with the master device through an RS485 bus;
in the time slot of each slave device, sending a resource change message to the master device;
in the time slot of the master device, simultaneously returning a resource acquisition request to the corresponding slave device according to the received resource change message;
and according to the resource acquisition request received by the slave device, transmitting the resource data to the master device in the time slot of the slave device.
In the above technical solution, determining whether resource data sent by the slave device conflicts according to a conflict detection method specifically includes:
and sequentially detecting whether the parity check bit, the data length, the stop bit and the data frame of the resource data sent by the slave equipment are correct, and if so, determining that the resource data sent by the slave equipment are not collided.
In the technical scheme, the configuration parameters of the RS485 communication interface of the master device are acquired, the RS485 communication interface of the slave device is subjected to parameter configuration according to the configuration parameters, and the master device and the slave device communicate by calling respective RS485 communication interfaces.
In the above technical solution, the configuration parameters include a baud rate, a data bit, a stop bit, and a parity bit.
In the above technical solution, when the slave device receives a resource acquisition request, the slave device compresses the current resource data, and sends the compressed resource data to the master device in the time slot of the slave device, and the master device decompresses the compressed resource data.
In the above technical solution, the resource data received by the master device is decompressed, and the resource information table of the master device is updated by using the decompressed resource data.
The invention realizes that the master device and the slave device send data in respective time slots, and the master device can send the resource acquisition request to the slave device in parallel, and the slave device returns the resource data to the master device in a time-sharing manner, so that the resource acquisition of the slave device by the master device can be completed quickly and accurately, the communication conflict is avoided, and the invention has the advantages of concurrency, high efficiency, safety and redundancy, is convenient for management, and can meet the requirement of large-batch data acquisition of the communication device.
Drawings
Fig. 1 is a flow chart of an equipment resource acquisition method based on 485 time-sharing communication in the invention.
Detailed Description
The invention is described in detail below with reference to the drawings and the detailed description.
The embodiment of the invention provides a 485 time-sharing communication-based equipment resource acquisition method, which comprises the following steps as shown in figure 1:
and S1, establishing the electric connection between the master device and each slave device through the RS485 bus, and determining the time slot of the master device and each slave device.
And S2, acquiring configuration parameters of the RS485 communication interface of the master device, and configuring the parameters of the RS485 communication interface of the slave device according to the configuration parameters.
The configuration parameters include baud rate, data bits, stop bits, and parity bits.
And S3, calling the RS485 communication interface of each slave device to send a resource change message to the master device in the time slot of each slave device.
According to the scheme, the time-sharing communication of the RS485 communication interface is adopted, each slave device can call the RS485 communication interface to send data to the master device in each time slot, therefore, each slave device cannot generate communication conflict, the resource change message can be accurately and quickly reported to the master device, and meanwhile, the master device can accurately and quickly receive the resource change message of each slave device without generating communication conflict.
And S4, in the time slot of the master device, calling the RS485 communication interface according to the resource change message received by the master device, and simultaneously returning a resource acquisition request to the corresponding slave device.
According to the scheme, the time-sharing communication of the RS485 communication interface is adopted, the data can be sent by the master device in the own time slot, and the resource acquisition request can be sent to the slave device by the master device in parallel, so that the resource acquisition of the slave device by the master device can be completed quickly.
And S5, compressing the current resource data of the slave device according to the resource acquisition request received by the slave device, calling an RS485 communication interface in the time slot of the slave device, and sending the compressed resource data to the master device.
Determining whether resource data sent by slave equipment conflicts according to a conflict detection method, specifically: and sequentially detecting whether the parity check bit, the data length, the stop bit and the data frame of the resource data sent by the slave equipment are correct, and if so, determining that the resource data sent by the slave equipment are not collided.
And S6, decompressing the resource data received by the main device, and updating the resource information table of the main device by using the decompressed resource data.
The invention realizes that the master device and the slave device send data in respective time slots, and the master device can concurrently send the resource acquisition request to the slave device, and the slave device returns the resource data to the master device in a time-sharing manner, so that the resource acquisition of the slave device by the master device can be rapidly and accurately completed, the communication conflict is avoided, and the invention has the advantages of concurrency, high efficiency, safety and redundancy, is convenient for management, and can meet the requirement of large-batch data acquisition of the communication device.
The present invention is not limited to the above-mentioned preferred embodiments, and any structural changes made by anyone in the light of the present invention, all the technical solutions similar or similar to the present invention, fall within the protection scope of the present invention.