Method for quickly networking digital sensorTechnical Field
The invention relates to the technical field of vehicle detection, in particular to a method for quickly networking a digital sensor.
Background
The existing truck scale is mostly an electronic truck scale, and compared with a mechanical truck scale, the electronic truck scale is high in precision, good in stability and convenient to operate, and the electronic truck scale adopts digital sensors, and in the same weighing platform, each digital sensor must have different communication addresses, so that the problem of complex connection exists. The existing solutions have the following: in the first method, only a single sensor is connected through an instrument on site, and an address is set. However, after one sensor is set, the instrument needs to be turned off, the sensor is removed, the next sensor is restarted, an address setting interface is entered, and an address is set. The operation steps are more, the wiring is complex, and the sensor can be damaged when the wiring is wrong. And secondly, identifying the sensors by inquiring the unique ID number of each digital sensor. However, the ID number of the sensor ranges from 0 to 999999 to query one by one, and assuming that the query action of each number takes 40ms, the total time is 1000000×40ms=11 hours, and the time is too long.
Disclosure of Invention
The invention mainly solves the technical problems of complex steps and long time consumption of the original digital sensor networking, provides a method for quickly networking the digital sensors, utilizes the characteristics that the sensors have unique ID numbers and RS485 buses to conflict, combines a certain detection flow to detect the ID numbers of all the received sensors, reads the stress signals of the sensors through the ID numbers or reads the stress signals of the sensors through addresses, does not need to connect the sensors one by one and set the addresses, reduces the damage rate of the sensors, and also improves the speed of the digital sensor networking.
The technical problems of the invention are mainly solved by the following technical proposal: the invention comprises the following steps:
(1) The digital instrument sends a broadcasting instruction before automatic networking to enable all the digital sensors to enter a networking state; the digital sensor is only identifiable by the digital meter in the networking state.
(2) The digital instrument sends an instruction, and the digital sensor with the same ID number from 0 to netBit replies the ID number; the ID number of the sensor is set to 10 bits in this scheme, or can be less or more, which is related to one product ID number management, the numerical range of each bit is 0 to 9, and the ID number of the digital sensor is identified from right to left.
(3) The digital sensor replies its ID number;
(4) If a single digital sensor meets the conditions, the digital instrument acquires the correct ID number, and if a plurality of digital sensors meet the conditions and reply the ID number, the RS485 bus is confused, and the digital instrument receives the confused data;
(5) After the digital instrument receives the chaotic data, adding 1 to the netbit value of the current scanning ID number, and reissuing the instruction until the digital instrument acquires the correct ID number; and (3) identifying one more ID number during scanning, and repeating the step (2), the step (3) and the step (4).
(6) After the digital instrument acquires the correct ID number, the ID number is sent to the digital sensor;
(7) If the digital sensor judges that the received ID number is the same as the ID number, a correct response is returned, and the automatic networking state is exited;
(8) If the digital instrument receives the correct response returned by the digital sensor, storing the ID number into the identified ID number group, and if the digital instrument does not receive the response of the sensor, returning to the step (5);
(9) After the digital instrument acquires all the correct ID numbers, addresses are respectively set for the digital sensors from 1 to n through the ID numbers.
Preferably, the digital meter in the step (1) makes all the sensors enter the networking state by means of instructions.
Preferably, the method of scanning the ID in the step (2) is to gradually scan the ID from the 0 th bit to the 1 st bit and the 2 nd bit … …, i.e. scan the ID from right to left.
Preferably, the netBit in the step (2) refers to a netBit, and the netBit is a number of the (n+1) th bits of the ID from right to left. If the ID number of the digital sensor is 123456789 and the netbit value is 3, the corresponding value is 7.
Preferably, in the step (2), the netBit is an integer starting from 0. Since the ID number of the digital sensor is recognized from bit 1, netBit is at least 1-1=0, and the number of digits of the ID number of the digital sensor is an integer, and netBit is also an integer.
Preferably, after the digital instrument in the step (5) receives the chaotic data, the netbit value of the current scanning ID number is added with 1, then the netbit value of the current scanning ID number is set to 0, and the instruction is reissued.
Preferably, the digital meter in the step (9) addresses the digital sensors from 1 to n respectively through ID numbers to obtain sampling data, or directly reads information of each digital sensor through the ID numbers.
The beneficial effects of the invention are as follows: the sensor has the characteristics of unique ID numbers and RS485 bus conflict, the ID numbers of all the received sensors are detected by combining a certain detection flow, the stress signals of the sensors are read through the ID numbers or the stress signals of the sensors are read through the addresses, the sensors are not required to be connected one by one and the addresses are set, the damage rate of the sensors is reduced, and the speed of the digital sensor network is also improved.
Drawings
Fig. 1 is a flow chart of the present invention.
Detailed Description
The technical scheme of the invention is further specifically described below through examples and with reference to the accompanying drawings. Examples: the method for quickly networking the digital sensor in the embodiment, as shown in fig. 1, comprises the following steps:
(1) The digital instrument reads the stress signal of each digital sensor in a command mode, and the digital instrument sends a broadcast command before automatic networking so that all the digital sensors enter a networking state.
(2) The digital instrument sends an instruction, and the digital sensor with the same ID number from 0 to netBit replies the ID number. If no digital sensor replies, judging whether the value of the netBit of the ID number is 9, if so, adding 1 to the netBit value of the current scanning ID number, setting the value of the netBit of the current scanning ID number to 0, reissuing the instruction, and repeating the step (2). The ID number of the sensor is set to 10 bits in the scheme, or can be less or more, which is related to one product ID number management, the numerical range of each bit is 0 to 9, and the ID scanning method is that the ID scanning is gradually carried out from the 0 th bit to the 1 st bit and the 2 nd bit … …. For example, the ID number of the sensor is 123456789, the ID number is: bit 0 has a value of 0; bit 1 value 9; bit 2 value 8; bit 3 value 7; bit 4 value; the value of bit 5 is 5; bit 6 value 3; bit 7 value 2; bit 8 value 1; bit 9 value 0.
(3) The digital sensor replies its ID number. netBit refers to the netBit bit, which is the number of the (n+1) th bits of the ID from right to left. If the ID number of the digital sensor is 123456789 and the netbit value is 3, the corresponding value of the netbit bit is 7. Since netBit is an integer starting from 0 and the ID number of the digital sensor is recognized from bit 1, netBit is at least 1-1=0, the number of bits of the ID number of the digital sensor is an integer, and netBit is also an integer.
(4) If a single digital sensor meets the conditions, the digital instrument acquires the correct ID number, and if a plurality of digital sensors simultaneously reply the ID number, the RS485 bus is disordered, and the digital instrument receives chaotic data.
(5) After the digital instrument receives chaotic data, adding 1 to the netbit value of the current scanning ID number, reissuing an instruction until the digital instrument obtains the correct ID number, namely, identifying one more ID number during rescanning, setting the value of the netbit of the current scanning ID number to 0, and repeating the steps (2), 3 and 4).
(6) After the digital instrument acquires the correct ID number, the ID number is sent to the digital sensor.
(7) If the digital sensor judges that the received ID number is the same as the ID number, a correct response is returned, and the automatic networking state is exited.
(8) If the digital instrument receives the correct response returned by the digital sensor, the ID number is stored in the identified ID number group, and if the digital instrument does not receive the response from the sensor, the step (5) is returned.
(9) After the digital instrument acquires all the correct ID numbers, the digital sensors are respectively provided with addresses from 1 to n through the ID numbers, or the information of each digital sensor is directly read through the ID numbers.