Automatic allocation method of RS485 communication port address

The invention discloses an automatic allocation method of an RS485 communication port address. According to the technical scheme, the method comprises the following steps: in a host and a plurality of slaves which are annularly connected in series, locking the rest of slaves except the first slave, and only allowing the first slave to receive and transmit information; transmitting a command to the first slave by the host, decoding and confirming a handshake protocol by the slave, and transmitting unlocking information and an own station number to a next slave; receiving the unlocking information and making a response by the next slave, setting the own station number as the received station number plus 1, and transmitting unlocking information and the own station number to a slave after the next slave; repeatedly transmitting the unlocking information and the station numbers of the slaves till the last slave; receiving the information about the last slave by the host, determining the quantity of online slaves and automatically allocating a communication address to each slave in order to finish address allocation of the RS485 communication port of each slave. By adopting the method, the communication port address can be allocated accurately and rapidly, extra overheads of hardware and software are avoided, and the reliability and rate of communication are ensured.