Summary of the invention
The objective of the invention is to overcome the deficiencies in the prior art, a kind of method of automatic detection Serial Port Information is provided, its step is as follows:
At first, in serial communication terminal and host computer, pre-install Handshake Protocol respectively;
When the serial communication terminal connects host computer by serial ports, host computer is according to the available Serial Port Information that is pre-stored in storage unit, send handshake request to all available serial ports successively with default baud rate, if having the serial ports feedback of at least one to shake hands replys, then shake hands successfully, and set up with the serial communication terminal that this serial ports is connected down and to communicate by letter, delete in the available serial ports that this Serial Port Information will be stored from storage unit simultaneously, the shake hands baud rate value of replying of this string slogan and receiving is preserved in the lump by in storage unit and by man-machine interface feedback string slogan and baud rate value;
Further, the method for aforesaid automatic detection Serial Port Information, the judgement of wherein said available serial ports is as follows:
Host computer is opened all serial ports successively, if can successfully be opened, illustrates that this serial ports can use, and the storage unit that simultaneously the string slogan of available serial ports is kept at host computer is standby.
The method of described automatic detection Serial Port Information wherein also comprises:
After a serial communication endpoint registration was finished, host computer can repeat to send a handshake request to all available serial ports, if shake hands response feedback, and the then renewal of registration, otherwise, finish.
Automatically detect the method for Serial Port Information as preferred version, host computer receives that the response time of shaking hands of serial communication terminal is between 0 millisecond to 5000 milliseconds.
Automatically detect the method for Serial Port Information as preferred version, host computer receives that the response time of shaking hands of serial communication terminal is between 0 millisecond to 200 milliseconds.
Automatically detect the method for Serial Port Information as preferred version, all serial ports numbers of host computer self are no less than 1.
Automatically detect the method for Serial Port Information as preferred version, all serial ports numbers of host computer self are 2 to 10.
Described default baud rate order is as follows successively:
300 bits per seconds, 600 bits per seconds, 1200 bits per seconds, 2400 bits per seconds, 4800 bits per seconds, 9600 bits per seconds, 19200 bits per seconds, 38400 bits per seconds, 43000 bits per seconds, 56000 bits per seconds, 115200 bits per seconds.
Described Handshake Protocol is as follows:
Serial communication terminal and host computer communication protocol are the ASCII character of 10 byte regular lengths, and protocol format is: AAA#BBB#CC, and wherein AAA is an instruction type, and BBB is operation, and CC is a parameter, and # is a blank character, can not have.
Instruction type comprises two kinds: CMD and DAT, CMD representative sends is instruction, the transmission of DAT representative be data.
When beginning to shake hands, host computer sends to the serial communication terminal:
CMD#CHK#00 represents whether host computer inspection serial communication terminal is normal
After the serial communication terminal is received instruction, if the serial communication terminal normally sends to host computer:
CMD#CHK#OK
If the serial communication terminal is wrong, send to host computer:
CMD#ERR#XX
Annotate: XX is an error code.
Receive the CMD#CHK#OK of serial communication terminal transmission when host computer after, send Address requests to the serial communication terminal:
CMD#ADD#RE
When the serial communication terminal is received Address requests, send:
CMD#ADD#XX
Annotate: XX is the ASCII character address, serial port terminal device address 00-99
Host computer sends the log-on message request code to the serial communication terminal:
CMD#VER#RE
When the serial communication terminal is received above-mentioned request, send:
CMD#?VER?#XX
Annotate: XX is the ASCII character address, serial communication terminal code 00-99
Host computer is to serial communication terminal transmits data request code:
CMD#REQ#XX
Annotate: XX is the request of ASCII character data type:
When the serial communication terminal is received request of data, send the data length bag:
DAT#NUMXXX
Annotate: XXX is an ASCII character packet number
Next serial communication terminal transmission length is 10 packet, sends the back that finishes and sends:
CMD#DAT#OK
The expression data send and finish.
Embodiment
The present invention will be further described below in conjunction with embodiment.
Embodiment 1
Shown in Fig. 1, the serial ports number of the host computer in the present embodiment is 10, logic flow of the present invention is as follows: the host computer start is to start to open own serial ports according to serial ports number preface, if can successfully be opened, illustrate that this serial ports can use, after serial ports all is opened, judge whether the string slogan of opening for the last time is 10, if host computer is standby with the storage unit that the string slogan of available serial ports is kept at host computer, otherwise return step S101.When the serial communication terminal connects host computer by serial ports, host computer is according to the available Serial Port Information that is pre-stored in storage unit, send handshake request to all available serial ports successively with default baud rate, if having the serial ports of at least one to shake hands 200 milliseconds of internal feedbacks replys, then shake hands successfully, and set up with the serial communication terminal that this serial ports is connected down and to communicate by letter, delete in the available serial ports that this Serial Port Information will be stored from storage unit simultaneously, this string slogan and receiving shakes hands that the baud rate value of replying is stored in storage unit in the lump and by man-machine interface feedback string slogan and baud rate value; Otherwise repeat this step S104.
After communication is set up successfully, the serial communication terminal can send to host computer in log-on message wherein and registers solidifying, host computer is stored in the storage unit of host computer in the lump with the information of the log-on message of serial communication terminal and the serial ports that connected thereof, and registration is finished automatically.
Described log-on message comprises at least a in the address, product type, production code member, firmware version number, product producer of communication terminal.
After a serial communication endpoint registration was finished, host computer can repeat to send a handshake request to all available serial ports, if shake hands response feedback, then return step S104, otherwise, enter step S109, statistics and preserve answering equipment information such as the string slogan of corresponding serial ports and baud rate value.
Embodiment 2
Shown in Fig. 2, the serial ports number of the host computer in the present embodiment is 2, logic flow of the present invention is as follows: the host computer start is to start to open own serial ports according to serial ports number preface, if can successfully be opened, illustrate that this serial ports can use, after serial ports all is opened, judge whether the string slogan of opening for the last time is 2, if host computer is standby with the storage unit that the string slogan of available serial ports is kept at host computer, otherwise return step S201.When the serial communication terminal connects host computer by serial ports, host computer is according to the available Serial Port Information that is pre-stored in storage unit, send handshake request to all available serial ports successively with default baud rate, if having the serial ports of at least one to shake hands 5000 milliseconds of internal feedbacks replys, then shake hands successfully, and set up with the serial communication terminal that this serial ports is connected down and to communicate by letter, delete in the available serial ports that this Serial Port Information will be stored from storage unit simultaneously, this string slogan and receiving shakes hands that the baud rate value of replying is kept at storage unit in the lump and by man-machine interface feedback string slogan and baud rate value, otherwise repeats this step S204.
After a serial communication endpoint registration was finished, host computer can repeat to send a handshake request to available serial ports, if shake hands response feedback, then return step S204, otherwise, enter step S209, statistics and preserve answering equipment information such as the string slogan of corresponding serial ports and baud rate value.
Embodiment 3
Present embodiment is a kind of software program that utilizes method of the present invention to finish, said procedure operates in the host computer, this program not only can be finished technique effect of the present invention, the Serial Port Information of host computer can also be reported to operating personnel by man-machine interface simultaneously.
When the serial ports automatic identification procedure moves, open on the computing machine serial ports 1 at first respectively to serial ports 10, if opening, serial ports illustrates that successfully serial ports exists and do not have occupied.After the been scanned, available serial ports is preserved storage unit.Afterwards, program can be opened available serial ports successively, and sends handshake request, replys if receive shaking hands of serial communication terminal in 1000 milliseconds, then thinks and communicates by letter successfully.Shake hands after the success, the serial communication terminal sends the address to host computer, registers on host computer, and host computer is also preserved the Serial Port Information of this equipment connection simultaneously, finishes automatic identifying.Host computer among this embodiment is an X86 framework PC.Software development environment Microsoft Visual Studio 2008; Programming language is a C# language.This program major function and characteristics: this program is applied to various serial communication equipment, obtains the Serial Port Information of connection device automatically.Characteristics such as this program has simply, and is easy to operate have also been saved people's working time simultaneously greatly, have saved human cost.
The above, it only is preferred embodiment of the present invention, be not that the present invention is done any pro forma restriction, though the present invention has disclosed with preferred embodiment as is above-mentioned, yet be not to be used to limit the present invention, any those skilled in the art, in not breaking away from technical scheme scope of the present invention, can utilize the technology contents of above-mentioned disclosure to make the equivalent embodiment that a little change is considered as equivalent variations, all contents that does not break away from technical solution of the present invention, according to technical spirit of the present invention above embodiment is made any simple modification, equivalent variations and modification all belong to technical scope of the present invention.