Equipment unique identification code acquisition method based on RS-485 bus
By using matrix coding and a phased screening mechanism, the address conflict problem in obtaining device identification codes on the RS-485 bus is solved, realizing automated device identification and dynamic adaptation, which is suitable for industrial environments.
Patent Information
- Application Number
- CN202511114668.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-11
- Publication Date
- 2025-11-11
AI Technical Summary
In existing technologies, the RS-485 bus has difficulty efficiently obtaining the unique identification code of the device when multiple slave devices are connected, resulting in address conflicts and strong dependence on manual configuration. Furthermore, it lacks a dynamic filtering mechanism, leading to high communication complexity.
An automated identification mechanism employing matrix coding and phased dynamic filtering is used. By constructing an initial matrix, the host and slave interact, and using an iterative combination method, the unique identification code of the device is gradually filtered out. This includes four steps: constructing an initial matrix, host-slave communication interaction, conflict dynamic filtering, and iterative combination and precise positioning.
It significantly reduces communication complexity, supports dynamic access and hot-swapping of devices, is suitable for variable-length identification codes, has high compatibility and strong fault tolerance, and can realize automated identification of devices in industrial environments.
Smart Images

Figure CN120935142A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial communication and equipment identification technology, specifically to a method for obtaining a unique device identification code based on an RS-485 bus. Background Technology
[0002] The RS-485 bus, a two-wire differential signal bus, is a commonly used internal communication standard between programmable logic controllers (PLCs) in industrial environments. It employs a half-duplex operating mode and supports multi-point data communication. In industrial settings, the RS-485 bus offers advantages such as good interference immunity (stable signal), simple wiring, and low cost, making it the most widely used serial bus standard.
[0003] In industrial control systems, the RS-485 bus is widely used for data transmission between devices due to its strong anti-interference capabilities and support for multi-point communication. However, when multiple slave devices are connected to the same bus, efficiently obtaining the unique identification code (such as serial number) of each device becomes a critical issue. Traditional methods have the following limitations:
[0004] High reliance on manual configuration: Some solutions require pre-assigning a fixed address to each device (such as a DIP switch or manual input), which increases deployment and maintenance costs and makes it difficult to adapt to scenarios where devices are dynamically added or removed.
[0005] Insufficient conflict and fault tolerance: If multiple slave devices respond to the same instruction, it will cause bus conflicts; existing methods lack dynamic filtering mechanisms, making it difficult to extract useful information from conflict responses.
[0006] Therefore, in view of the problems of address conflicts, strong dependence on manual configuration, and difficulty in resolving response conflicts in existing technologies, there is an urgent need for a method that does not require manual intervention, supports dynamic device access, and can efficiently match variable-length identification. It is essential to use this method to obtain the unique identification code of the device, thereby reducing communication complexity. Summary of the Invention
[0007] The technical problem to be solved by this invention is to address the problems existing in the background technology, such as address conflicts, strong dependence on manual configuration, and difficulty in resolving response conflicts. Therefore, this invention provides an automated identification mechanism based on matrix operations and phased dynamic screening. Through matrix encoding, phased verification, and iterative screening mechanisms, the communication complexity can be significantly reduced, the above-mentioned technical bottlenecks can be solved, and the needs of automated device identification can be met. Specifically, it is a method for obtaining a unique device identification code based on an RS-485 bus.
[0008] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows: a method for obtaining a unique device identification code based on an RS-485 bus, applicable to communication between a master and multiple slave devices, wherein the slave device includes a device memory module for storing a unique identification code of the device; the acquisition method utilizes matrix encoding and communication interaction between the master and slave devices, dynamically filters based on conflicts, and adopts an iterative combination method to achieve precise positioning, thereby obtaining a unique identification code for identifying the device, specifically including the following steps:
[0009] S1. Construct an initial matrix, where the rows of the initial matrix correspond to the character set and the columns correspond to the identification code length, and use the constructed initial matrix as the source matrix;
[0010] S2. Master-slave communication interaction: The RS-485 master traverses all elements of the source matrix. The master generates a data frame containing the start bit, length, and character segment according to the matrix elements. The master assembles the data frame according to the matrix elements and sends the data frame to all slaves connected to the RS-485 bus. The slave determines whether to give a response based on the received data frame.
[0011] S3. Conflict dynamic filtering: The slave responds based on the matching result of the received segment and its own identification code. The master identifies the valid segments through the valid matrix and filters invalid characters by combining the element-by-element multiplication rule.
[0012] S4. Iterative Combination and Precise Positioning: Through multiple rounds of matrix recombination, odd-numbered columns are recombined to form new effective matrices, while empty characters are removed. Longer effective segments are gradually generated, and through multiple rounds of screening, the complete and unique identification code for identifying the device is finally determined.
[0013] Furthermore, in the method for obtaining a unique device identifier based on an RS-485 bus as described in this invention, in the initial matrix construction stage of step S1, the initial matrix is constructed as follows:
[0014] Assuming the unique identifier is a string SN of length n, it can be represented as: SN = s1s2s3...s n The initial matrix S has m rows and n columns, and the elements of matrix S are S_m and S_n. ij Where i = 1, 2, ..., m, and j = 1, 2, ..., n; S ij It belongs to set A = {x | x ∈ character}; where the value of m is equal to the number of elements in set A, and the value of n is equal to the length of the device's unique identifier. Matrix S is used as the source matrix for communication and interaction between the master and slave devices.
[0015] Furthermore, the method for obtaining a unique device identification code based on an RS-485 bus as described in this invention specifically includes the following steps in step S2, the host-slave communication interaction stage:
[0016] S1.RS-485 host traversal matrix
[0017] The host extracts one element from the source matrix one by one from left to right and top to bottom until the entire source matrix has been traversed once. Taking the source matrix as an example, it first traverses all elements in the first column, then traverses the second column, and so on until the last column has been traversed.
[0018] S2. Based on the element group data frame
[0019] The data frames sent by the RS-485 host follow the following format. The smallest unit of the unique identifier can be: character, byte, half word, word or double word; assuming that the starting bit of the unique identifier segment is 0, the segment length is 4, and the identifier segment is "ABCD"; where "ABCD" represents the identifier segment number obtained by arranging and combining uppercase letters A to Z.
[0020] Assume the element retrieved by the host is S. ij Then the starting bit of the unique identifier segment is j, and the segment length is S. ij The length of the identification code segment is S. ij The data frame consists of: j, len(S) ij ),S ij ;
[0021] S3. Send a data frame to the slave device.
[0022] The host sends the data frame: j, len(S) ij ),S ij Send to the slave device;
[0023] S4. The slave device responds according to the rules.
[0024] The slave device on the RS-485 bus responds appropriately based on the received data frame, its own unique identifier, and the communication protocol. Assuming the identifier segment is the string "ABCD", the slave device responds based on the segment start bit j and segment length len(S) of the unique identifier. ij Extract a segment of its own unique identifier to form a unique identifier segment. Compare "ABCD" with the segment. If they are the same, the slave device sends a response to the master device; otherwise, it does not respond to the master device.
[0025] Furthermore, in the method for obtaining a unique device identifier based on an RS-485 bus as described in this invention, the filtering method in step S3, dynamic conflict filtering stage, is as follows:
[0026] The RS-485 master determines the validity of a segment by checking whether the slave responds. This information is stored in matrix V. If an RS-485 slave responds to the segment, a 1 is used to indicate that the segment is valid; otherwise, a 0 is used to indicate that the segment is invalid.
[0027] A valid matrix is used to indicate whether a segment of string exists at a given position. If it exists, it is valid; otherwise, it is invalid. The elements of matrix V are V0. ij Where i = 1, 2, ..., m, and j = 1, 2, ..., n, and V ij ∈{0,1}; for example, V 11 A value of 1 indicates that at least one device's unique identifier exists. 11 If V 11 If the value is 0, then S does not exist. 11 ; where matrix V is:
[0028]
[0029] If the initial matrix has only one column, the entire process ends after this step is completed;
[0030] If a slave device responds to an element in a column, that element is a unique identifier for that slave device; otherwise, the element is invalid.
[0031] Furthermore, in the method for obtaining a unique device identification code based on an RS-485 bus as described in this invention, the construction of the effective matrix and the multi-round screening method in step S4, iterative combination and precise positioning stage, specifically include the following processes:
[0032] S1. First determine the intermediate matrix.
[0033] First, define the rule for multiplying two matrices. Suppose we have two matrices, matrix A and matrix B, then...
[0034] and
[0035] The result of multiplying them element by element is calculated as follows:
[0036]
[0037] Therefore, the resulting matrix C is:
[0038] Here, we define the rule for element-wise multiplication, where the elements T of the resulting matrix T are... ij Defined as Where ε is an empty string;
[0039] The calculated result matrix T is:
[0040]
[0041] The specific calculation method is as follows: For each i and j, calculate T. ij The method is: in, It is an indicator function, when V ij When =1, the value is S. ij Otherwise, the value is ε, representing an empty string;
[0042] S2. Construct a matrix containing only valid segments.
[0043] The result matrix T in S1 is rearranged according to the following rules:
[0044] S21. Traversal rule: Traverse matrix T in column order, that is, first traverse all elements of the first column, then traverse all elements of the second column, and so on, until all columns have been traversed;
[0045] S22. Removal rule: For each element T ij If T ij =ε, where ε represents an empty string, then remove that element;
[0046] S23. New Matrix Construction: Construct a new matrix S of size m. ' ×n, where m ' It is the number of elements remaining in each column after removing all empty string elements;
[0047] For each column j, arrange the non-empty string elements in order to form a new matrix;
[0048] Suppose the source matrix is: The rearranged matrix: ε represents an empty position;
[0049] S3. Construct the next possible segments.
[0050] The matrix is rearranged according to the following rules:
[0051] S31. Traversal rule: Traverse the matrix according to the odd-numbered columns;
[0052] S32. Combination rule: Take a string element A from the odd-numbered columns in descending order, and then combine it with all the elements in the next column of the current column. Each new element resulting from the combination is an element in a new matrix column, and they are arranged in the order of combination.
[0053] S33. Rules for constructing a new matrix: Let the number of rows and columns of the old matrix be m×n, and the number of rows of the new matrix be... The number of columns is n×n;
[0054] Mathematical description:
[0055] The elements of the source matrix A are A ij , where i = 1, 2, ..., m, and j = 1, 2, ..., n;
[0056] The elements of the target matrix B are B ij Where i = 1, 2, ..., m × m, and
[0057] New matrix construction:
[0058]
[0059] The newly constructed matrix is used as the source matrix, and then the process is repeated in step S2 above to reconstruct a matrix containing only valid segments. Through multiple rounds of filtering, the complete and unique identification code for identifying the device is finally determined.
[0060] The device unique identification code acquisition method based on RS-485 bus described in this invention has the following advantages compared with the prior art: Through matrix-based phased verification and dynamic filtering mechanism, it can avoid multi-slave response conflicts, significantly reduce bus communication pressure, and has the characteristics of high efficiency and no conflict; it requires no pre-allocation of addresses or manual intervention, supports dynamic device access and hot-swapping scenarios, and achieves fully automatic adaptation; it is applicable to variable-length unique identification codes (such as numbers and character sequences), adapts to heterogeneous industrial equipment environments, and has high compatibility; through iterative elimination of invalid segments, it can accurately identify even in the presence of local signal interference, and has strong fault tolerance.
[0061] Therefore, the acquisition method described in this invention, through matrix encoding, phased verification and iterative screening mechanism, can significantly reduce communication complexity, thereby meeting the needs of automated equipment identification. It can be widely applied to large-scale equipment networking scenarios such as smart grids and industrial automation, providing underlying support for equipment management, fault location and security authentication. Attached Figure Description
[0062] The present invention will now be described in further detail with reference to the accompanying drawings.
[0063] Figure 1 This is a schematic diagram illustrating the connection between the host and slave devices described in this invention.
[0064] Figure 2 This is a flowchart illustrating the workflow of the host computer described in this invention.
[0065] Figure 3This is a flowchart illustrating the operation of the slave device described in this invention. Detailed Implementation
[0066] The following specific embodiments illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification.
[0067] It should be understood that the structures, proportions, sizes, etc., depicted in the accompanying drawings are merely for illustrative purposes to aid those skilled in the art and to facilitate understanding. They are not intended to limit the scope of the invention and therefore have no substantial technical significance. Any modifications to the structure, changes in proportions, or adjustments to size, without affecting the effectiveness or purpose of the invention, should still fall within the scope of the disclosed technical content. Furthermore, the terms "upper," "lower," "left," and "right" used in this specification are merely for clarity and not intended to limit the scope of the invention. Changes or adjustments to their relative relationships, without substantially altering the technical content, should also be considered within the scope of the invention's implementation.
[0068] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "connection" and "provided with" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0069] It should be noted that the term "comprising" or any other variation is intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0070] This invention provides a method for obtaining a unique device identification code based on an RS-485 bus, applicable to communication between a master and multiple slave devices. Each slave device includes a device memory module for storing a unique identification code. The method utilizes matrix encoding and communication interaction between the master and slave devices, dynamically filters for conflicts, and employs an iterative combination approach to achieve precise positioning, thereby obtaining the unique identification code used to identify the device. Specifically, the method includes the following steps:
[0071] S1. Construct an initial matrix, where the rows of the initial matrix correspond to the character set and the columns correspond to the identification code length, and use the constructed initial matrix as the source matrix;
[0072] S2. Master-slave communication interaction: The RS-485 master traverses all elements of the source matrix. The master generates a data frame containing the start bit, length, and character segment according to the matrix elements. The master assembles the data frame according to the matrix elements and sends the data frame to all slaves connected to the RS-485 bus. The slave determines whether to give a response based on the received data frame.
[0073] S3. Conflict dynamic filtering: The slave responds based on the matching result of the received segment and its own identification code. The master identifies the valid segments through the valid matrix and filters invalid characters by combining the element-by-element multiplication rule.
[0074] S4. Iterative Combination and Precise Positioning: Through multiple rounds of matrix recombination, odd-numbered columns are recombined to form new effective matrices, while empty characters are removed. Longer effective segments are gradually generated, and through multiple rounds of screening, the complete and unique identification code for identifying the device is finally determined.
[0075] The device connection diagram between the host and the slave is shown below. Figure 1 As shown, it includes slave devices 1 to n, with multiple slave devices connected to the master device. The working principle of the master device is as follows: Figure 2 As shown, the working principle of the slave device is as follows: Figure 3 As shown.
[0076] To explain in detail how the acquisition method described in this invention can meet the needs of automated device identification, the following six stages are described in detail: constructing an initial matrix, master-slave communication interaction rules, identifying valid elements of the matrix, constructing valid segments, constructing a matrix containing only valid segments, and constructing possible segments for the next round.
[0077] Step 1: Construct the initial matrix
[0078] Assuming the unique identifier is a string SN of length n, it can be represented as: SN = s1s2s3...s n ;
[0079] The initial matrix S has m rows and n columns, and the elements of matrix S are S_m and S_n. ij Where i = 1, 2, ..., m, and j = 1, 2, ..., n; S ij It belongs to set A = {x | x ∈ character}.
[0080] The value of m is equal to the number of elements in set A. For example, if set A = {all uppercase letters from A to Z}, then m = 26; if set A = {all lowercase letters and Arabic numerals from a to z}, then m = 26 + 10 = 36.
[0081] The value of n is equal to the length of the device's unique identifier. For example, if the device's unique identifier is 2502140480001001, then n = 16; if the unique identifier is 04171234, then n = 8.
[0082] Example: Assume the unique identifier of a device consists of 16 Arabic numerals from 0 to 9 (example unique identifier: 2502140480001001), then m = 10, n = 16, and the set is A = "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}. The matrix is as follows:
[0083]
[0084] Use matrix S as the source matrix in the next operation.
[0085] Step 2: Master-Slave Communication and Interaction Rules
[0086] The RS-485 host traverses all elements of the source matrix, groups data frames according to the elements of the matrix, and sends data frames to all slave devices connected to the RS-485 bus. The slave devices determine whether to respond based on the received data frames.
[0087] (1) RS-485 host traversal matrix:
[0088] The host extracts one element from the source matrix one by one from left to right and top to bottom until the entire source matrix has been traversed once. Taking the matrix in the first step as an example, the first column 0 to 9 is traversed first, then the second column is traversed, and so on until all 16 columns have been traversed.
[0089] (2) Based on the element group data frame:
[0090] The data frames sent by the RS-485 host follow the following format. The smallest unit of unique identification can be: character, byte, half-word, word, or double word.
[0091] Starting bit of unique identifier segment Segment length Identification code segment 0 4 "2502”
[0092] Assume the element retrieved by the host is S. ij Then the starting bit of the unique identifier segment is j, and the segment length is S. ij The length of the identification code segment is S. ij The data frame consists of: j, len(S) ij ),S ij ;
[0093] (3) Send data frames to the slave device:
[0094] The host transmits the data frame: j, len(S) ij ),S ijSend to the slave device;
[0095] (4) The slave device responds according to the rules:
[0096] On an RS-485 bus, the slave device responds appropriately based on the received data frame, its own unique identifier, and the communication protocol. For example, assuming the identifier segment is the string "2502", the slave device responds based on the segment start bit j and segment length len(S) of the unique identifier. ij Extract a segment of its own unique identifier to form a unique identifier segment. Compare "2502" with the segment. If they are the same, the slave device sends a response to the master device; otherwise, it does not respond to the master device.
[0097] Step 3: Identify the valid elements of the matrix
[0098] The RS-485 master determines the validity of a segment by checking whether the slave responds. This information is stored in matrix V. If an RS-485 slave responds to the segment, a 1 is used to indicate that the segment is valid; otherwise, a 0 is used to indicate that the segment is invalid.
[0099] A valid matrix is used to indicate whether the segment string at the corresponding position exists (is valid). The elements of matrix V are V... ij Where i = 1, 2, ..., m and j = 1, 2, ..., n, and V ij ∈{0,1};
[0100] For example, V 11 A value of 1 indicates that at least one device's unique identifier exists. 11 If V 11 If the value is 0, then S does not exist. 11 :
[0101] If the initial matrix has only one column, the entire process ends after this step.
[0102] If a slave device responds to an element in a column, that element is a unique identifier for that slave device; otherwise, the element is invalid.
[0103] Step 4: Constructing effective segments
[0104] (1) Determine the intermediate matrix
[0105] Here, we first define the rule for multiplying two matrices, assuming we have two matrices:
[0106] and
[0107] The result of multiplying them element by element is calculated as follows:
[0108]
[0109] Therefore, the resulting matrix C is:
[0110] Here, we define the rule for element-wise multiplication, where the elements T of the resulting matrix T are... ij Defined as ε is an empty string.
[0111] (2) Operational rules
[0112] The intermediate matrix is calculated as follows:
[0113]
[0114] Specific calculation: For each i and j, calculate T. ij The method is: in It is an indicator function, when V ij When =1, the value is S. ij Otherwise, the value is ε (representing an empty string).
[0115] Step 5: Construct a matrix containing only valid segments
[0116] The result matrix T from the previous step is then rearranged according to the following rules:
[0117] The result matrix T from the previous step is then rearranged according to the following rules:
[0118] (1) Traversal rule: Traverse matrix T in column order, that is, first traverse all elements of the first column, then traverse all elements of the second column, and so on, until all columns are traversed.
[0119] (2) Removal rule: For each element T ij If T ij =ε (ε represents an empty string), then remove the element.
[0120] (3) Construction of a new matrix: Construct a new matrix S with size m. ' ×n, where m ' This represents the number of elements remaining in each column after removing all empty string elements. For each column j, the non-empty string elements are arranged in order to form a new matrix.
[0121] Example:
[0122] Source matrix: The rearranged matrix: ε represents an empty position.
[0123] Step 6: Construct the next possible segments
[0124] The matrix is rearranged according to the following rules:
[0125] Traversal rule: Traverse the matrix by odd-numbered columns;
[0126] Combination rule: Take a string element A from the odd-numbered columns in top-to-bottom order, and then combine it with all the elements in the next column of the current column. Each new element resulting from the combination is an element in a new matrix column, and they are arranged in the order of combination.
[0127] New matrix construction rules: Let the number of rows and columns of the old matrix be m×n, and the number of rows of the new matrix be... The number of columns is n×n;
[0128] Mathematical description:
[0129] The elements of the source matrix A are A ij , where i = 1, 2, ..., m, and j = 1, 2, ..., n;
[0130] The elements of the target matrix B are B ij Where i = 1, 2, ..., m × m and
[0131] New matrix construction:
[0132]
[0133] Use the newly constructed matrix as the source matrix, and then return to step two.
[0134] Example
[0135] To further illustrate how the acquisition method described in this invention can meet the requirements for automated device identification, the following explanation uses an RS-485 host as an edge gateway and an RS-485 slave as a smart miniature circuit breaker as an example:
[0136] Assuming two micro-circuit breakers are connected to the RS-485 bus, and their unique identification codes are "2310250491234567" and "3102190538901234" respectively, the edge gateway identifies the unique identification codes of multiple intelligent micro-circuit breakers using the method employed in this invention. The specific identification process is as follows:
[0137] S1. First round of identification
[0138] The source dictionary S is:
[0139]
[0140] Traversal rules:
[0141] Start traversing from the top left corner;
[0142] First frame of the first column: 010, second frame: 011, third frame: 012…;
[0143] The first frame of the second column: 1 10, the second frame: 11 1, the third frame: 1 12…;
[0144] The first frame of the third column: 210, the second frame: 211, the third frame: 212…;
[0145] Identifier dictionary:
[0146] If a device responds, mark the position as 1; otherwise, mark it as 0.
[0147]
[0148] Valid Segment: Based on the source dictionary and the identifier dictionary, the unique identifier of the device is calculated to contain the following characters (segment):
[0149]
[0150] S2. Second round of recognition
[0151] The source dictionary S is:
[0152]
[0153] Traversal rules:
[0154] Start traversing from the top left corner;
[0155] First frame of the first column: 0221, second frame: 0223, third frame: 0231…;
[0156] The first frame of the second column: 2200, the second frame: 2202, the third frame: 2210…;
[0157] The first frame of the third column: 4215, the second frame: 4219, the third frame: 4225…;
[0158] Identifier dictionary: If there is a device response, mark this position as 1; otherwise, mark it as 0.
[0159]
[0160] Valid Segment: Based on the source dictionary and the identifier dictionary, the unique identifier of the device is calculated to contain the following characters (segment):
[0161]
[0162] S3. Third round of recognition
[0163] The source dictionary S is:
[0164]
[0165] Traversal rules:
[0166] Start traversing from the top left corner:
[0167] First frame of the first column: 042302, second frame: 042310, third frame: 043102…;
[0168] The first frame of the second column: 441904, the second frame: 441905, the third frame: 442504…;
[0169] The first frame of the third column: 843823, the second frame: 843890, the third frame: 849123…;
[0170] Identifier dictionary: If there is a device response, mark this position as 1; otherwise, mark it as 0.
[0171]
[0172] Valid Segment: Based on the source dictionary and the identifier dictionary, the unique identifier of the device is calculated to contain the following characters (segment):
[0173]
[0174] S4. Fourth round of recognition
[0175] The source dictionary S is:
[0176]
[0177] Traversal rules:
[0178] Start traversing from the top left corner:
[0179] First frame of the first column: 0823101905, second frame: 0823102504…;
[0180] The first frame of the second column: 8838901234, the second frame: 8838904567…;
[0181] Identifier dictionary: If there is a device response, mark this position as 1; otherwise, mark it as 0.
[0182]
[0183] Valid Segment: Based on the source dictionary and the identifier dictionary, the unique identifier of the device is calculated to contain the following characters (segment):
[0184]
[0185] S5. Fifth Round of Recognition
[0186] The source dictionary S is:
[0187]
[0188] Traversal rules:
[0189] Start traversing from the top left corner;
[0190] First frame of the first column: 0162310250438901234; Second frame: 0162310250491234567; Third frame: 0163102190538901234; Fourth frame: 0163102190591234567;
[0191] Identifier dictionary: If there is a device response, mark this position as 1; otherwise, mark it as 0.
[0192]
[0193] Valid segment: Based on the source dictionary and the identifier dictionary, the unique identifier of the device is calculated to contain the following characters (segment);
[0194]
[0195] Conclusion: Two slave devices were connected to the RS-485 bus, and their unique identification codes were "2310250491234567" and "3102190538901234" respectively.
[0196] Therefore, the acquisition method described in this invention, through matrix-based phased verification and dynamic filtering mechanisms, can avoid multi-slave response conflicts, significantly reduce bus communication pressure, and has the characteristics of high efficiency and no conflict: no pre-allocation of addresses or manual intervention is required, it supports dynamic device access and hot-swapping scenarios, and achieves fully automatic adaptation; it is suitable for variable-length unique identification codes (such as numbers and character sequences), adapts to heterogeneous industrial equipment environments, and has high compatibility; by iteratively eliminating invalid segments, it can accurately identify even in the presence of local signal interference, and has strong fault tolerance.
[0197] In summary, the acquisition method described in this invention, through matrix encoding, phased verification, and iterative screening mechanisms, can significantly reduce communication complexity, thereby meeting the needs of automated equipment identification. It can be widely applied in large-scale equipment networking scenarios such as smart grids and industrial automation, providing underlying support for equipment management, fault location, and security authentication.
[0198] Other aspects of this invention that are not detailed herein are all conventional techniques known to those skilled in the art.
[0199] The scope of protection of this invention is not limited to the technical solutions disclosed in the specific embodiments. The above description is only a preferred embodiment of this invention and does not limit this invention. Any minor modifications, equivalent substitutions and improvements made based on the technical solutions of this invention should be included within the scope of protection of the technical solutions of this invention.
Claims
1. A method for obtaining a unique device identification code based on an RS-485 bus, applicable to communication between a master and multiple slave devices, wherein each slave device includes a device memory module for storing a unique identification code for the device; characterized in that: The acquisition method utilizes matrix encoding and communication between the host and slave devices, dynamically filters for conflicts, and employs an iterative combination approach to achieve precise positioning, thereby obtaining a unique identification code for device identification. Specifically, it includes the following steps: S1. Construct an initial matrix, where the rows of the initial matrix correspond to the character set and the columns correspond to the identification code length, and use the constructed initial matrix as the source matrix; S2. Master-slave communication interaction: The RS-485 master traverses all elements of the source matrix. The master generates a data frame containing the start bit, length, and character segment according to the matrix elements. The master assembles the data frame according to the matrix elements and sends the data frame to all slaves connected to the RS-485 bus. The slave determines whether to give a response based on the received data frame. S3. Conflict dynamic filtering: The slave responds based on the matching result of the received segment and its own identification code. The master identifies the valid segments through the valid matrix and filters invalid characters by combining the element-by-element multiplication rule. S4. Iterative Combination and Precise Positioning: Through multiple rounds of matrix recombination, odd-numbered columns are recombined to form new effective matrices, while empty characters are removed. Longer effective segments are gradually generated, and through multiple rounds of screening, the complete and unique identification code for identifying the device is finally determined.
2. The method for obtaining a unique device identification code based on an RS-485 bus according to claim 1, characterized in that, In step S1, the initial matrix is constructed as follows: Assuming the unique identifier is a string SN of length n, it can be represented as: SN = s1s2s3...s n The initial matrix S has m rows and n columns, and the elements of matrix S are S_m and S_n. ij Where i = 1, 2, ..., m, and j = 1, 2, ..., n; S ij It belongs to set A = {x | x ∈ character}; where the value of m is equal to the number of elements in set A, and the value of n is equal to the length of the device's unique identifier. Matrix S is used as the source matrix for communication and interaction between the master and slave devices.
3. The method for obtaining a unique device identification code based on an RS-485 bus according to claim 2, characterized in that, In step S2, the master-slave communication interaction stage, the specific steps include: S1.RS-485 host traversal matrix The host extracts one element from the source matrix one by one from left to right and top to bottom until the entire source matrix has been traversed once. Taking the source matrix as an example, it first traverses all elements in the first column, then traverses the second column, and so on until the last column has been traversed. S2. Based on the element group data frame The data frames sent by the RS-485 host follow the following format. The smallest unit of the unique identifier can be: character, byte, half word, word or double word; assuming that the starting bit of the unique identifier segment is 0, the segment length is 4, and the identifier segment is "ABCD"; where "ABCD" represents the identifier segment number obtained by arranging and combining uppercase letters A to Z. Assume the element retrieved by the host is S. ij Then the starting bit of the unique identifier segment is j, and the segment length is S. ij The length of the identification code segment is S. ij The data frame consists of: j, len(S) ij ),S ij ; S3. Send a data frame to the slave device. The host sends the data frame: j, len(S) ij ),S ij Send to the slave device; S4. The slave device responds according to the rules. The slave device on the RS-485 bus responds appropriately based on the received data frame, its own unique identifier, and the communication protocol. Assuming the identifier segment is the string "ABCD", the slave device responds based on the segment start bit j and segment length len(S) of the unique identifier. ij Extract a segment of its own unique identifier to form a unique identifier segment. Compare "ABCD" with the segment. If they are the same, the slave device sends a response to the master device; otherwise, it does not respond to the master device.
4. The method for obtaining a unique device identification code based on an RS-485 bus according to claim 3, characterized in that, In step S3, the dynamic conflict filtering stage, the filtering method is as follows: The RS-485 master determines the validity of a segment by checking whether the slave responds. This information is stored in matrix V. If an RS-485 slave responds to the segment, a 1 is used to indicate that the segment is valid; otherwise, a 0 is used to indicate that the segment is invalid. A valid matrix is used to indicate whether a segment of string exists at a given position. If it exists, it is valid; otherwise, it is invalid. The elements of matrix V are V0. ij Where i = 1, 2, ..., m, and j = 1, 2, ..., n, and V ij ∈{0,1}; for example, V 11 A value of 1 indicates that at least one device's unique identifier exists. 11 If V 11 If the value is 0, then S does not exist. 11 ; where matrix V is: If the initial matrix has only one column, the entire process ends after this step is completed; If a slave device responds to an element in a column, that element is a unique identifier for that slave device; otherwise, the element is invalid.
5. The method for obtaining a unique device identification code based on an RS-485 bus according to claim 4, characterized in that, In step S4, the iterative combination and precise positioning stage, the construction of the effective matrix and the multi-round screening method specifically include the following processes: S1. First determine the intermediate matrix. First, define the rule for multiplying two matrices. Suppose we have two matrices, matrix A and matrix B, then... and The result of multiplying them element by element is calculated as follows: Therefore, the resulting matrix C is: Here, we define the rule for element-wise multiplication, where the elements T of the resulting matrix T are... ij Defined as Where ε is an empty string; The calculated result matrix T is: The specific calculation method is as follows: For each i and j, calculate T. ij The method is: in, It is an indicator function, when V ij When =1, the value is S. ij Otherwise, the value is ε, representing an empty string; S2. Construct a matrix containing only valid segments. The result matrix T in S1 is rearranged according to the following rules: S21. Traversal rule: Traverse matrix T in column order, that is, first traverse all elements of the first column, then traverse all elements of the second column, and so on, until all columns have been traversed; S22. Removal rule: For each element T ij If T ij =ε, where ε represents an empty string, then remove that element; S23. New Matrix Construction: Construct a new matrix S of size m. ' ×n, where m ' It is the number of elements remaining in each column after removing all empty string elements; For each column j, arrange the non-empty string elements in order to form a new matrix; Suppose the source matrix is: The rearranged matrix: ε represents an empty position; S3. Construct the next possible segments. The matrix is rearranged according to the following rules: S31. Traversal rule: Traverse the matrix according to the odd-numbered columns; S32. Combination rule: Take a string element A from the odd-numbered columns in descending order, and then combine it with all the elements in the next column of the current column. Each new element resulting from the combination is an element in a new matrix column, and they are arranged in the order of combination. S33. Rules for constructing a new matrix: Let the number of rows and columns of the old matrix be m×n, and the number of rows of the new matrix be... The number of columns is n×n; Mathematical description: The elements of the source matrix A are A ij , where i = 1, 2, ..., m, and j = 1, 2, ..., n; The elements of the target matrix B are B ij Where i = 1, 2, ..., m × m, and New matrix construction: The newly constructed matrix is used as the source matrix, and then the process is repeated in step S2 above to reconstruct a matrix containing only valid segments. Through multiple rounds of filtering, the complete and unique identification code for identifying the device is finally determined.