A kind of code keypad usb communication abnormal restoring method and system
Technical field
The present invention relates to usb communication technical field, more particularly to a kind of code keypad usb communication abnormal restoring method and
System.
Background technology
Code keypad is one of requisite computer peripheral of financial POS, is widely used in communication, political affairs
The service occupatioies such as mansion, traffic, government, industry and commerce, the tax, supermarket, cooperation banking system, POS and management system use, mainly in leading to
It is used to input password.In existing code keypad, except Password Input module, it is also integrated with signature plate module, sound wave mould
Block and scan module etc..In communication process, the connection of terminal and external code keypad is normal, but the interference due to hardware or
The impact of person's surrounding enviroment, so that of short duration disconnection in terminal and external code keypad, then recovers normal feelings at once again
Condition, although now terminal and external code keypad connect normally, communication service disconnects.
In the prior art, POS main frame mainly connects external code keypad by USB port, carries out communication service by USB
Data transfer, POS main frame and code keypad, during communication strike-machine, because be interfered leading to USB to disconnect, lead to lead to
Each bottom layer driving module occurs during letter and cannot receive response data, return time-out error so that application program because
Non-artificial interference, leads to service disconnection, thus have impact on application program normally running.
Content of the invention
For this reason, it may be necessary to provide a kind of usb communication restoration methods and system, for solving existing USB device because being interfered,
And separated in short-term, lead to communication abnormality and the problem interrupted.
For achieving the above object, inventor provide a kind of code keypad usb communication abnormal restoring method, walk including following
Suddenly:
By the sequencing of data is activation, insert frame number in code keypad with being connected in the data that equipment is sent;
In DRP data reception process, code keypad returns the response message of every frame data, response packet with being connected equipment
Include data receiver success, data receiver failure data receives time-out;
Whether detection code keypad is abnormal with the usb communication being connected equipment, if so, then reconnects mechanism by communication and builds again
Vertical code keypad and the communication connection being connected equipment;
Communication connection again set up after, code keypad be connected equipment by received response message and data
Frame number, judge whether data repeats to receive, and communication counterpart data receiver situation, and abandon repeated data, and carrying out
Data re-transmitting.
Further, described communication reconnects mechanism and includes:
Judge code keypad and be connected whether equipment disconnects, if so, then detect code keypad and whether be connected equipment
Connect, if it is not, then exiting the mechanism of reconnecting;
Whether if code keypad is detected and being connected equipment and connect, code keypad is shaken hands again with being connected equipment;
Shake hands after success, judge code keypad and whether to be successfully connected equipment two-way authentication, if so, then recover communication, if
No, then refusal communication.
Further, reconnect mechanism again set up communication connection after with being connected equipment by communication in code keypad, password
Keyboard passes through broadcast mode and sends current usb communication connection status, wherein, described each bottom to each bottom layer driving module being comprised
Layer drive module includes key-press input bottom layer driving module, sign board bottom layer driving module and scanner bottom layer driving module.
Further, when usb communication exception is detected, code keypad, after actively cutting out usb communication, reopens
Usb communication, sets up code keypad and the communication connection being connected equipment again.
For achieving the above object, inventor additionally provides a kind of code keypad usb communication abnormal restoring system, including insertion
Unit, response unit, communication reconnect unit and processing unit;
Described insertion unit be used for by data is activation sequencing, code keypad be connected the data that equipment is sent
Middle insertion frame number;
Described response unit is used in DRP data reception process, and code keypad returns the response of every frame data with being connected equipment
Information, response message includes data receiver success, data receiver failure data receives time-out;
Described communication reconnects unit for detecting code keypad and the usb communication being connected equipment whether exception, if so, then leads to
Cross communication and reconnect the communication connection that mechanism is set up code keypad again and is connected equipment;
Described processing unit is used for after communication connection is set up again, code keypad be connected equipment by received
Response message and the frame number of data, judge whether data repeats to receive, and communication counterpart data receiver situation, and abandon weight
Complex data, and carry out data re-transmitting.
Further, described communication reconnects unit and includes connection judgment subelement, shake hands subelement and certification subelement;
Whether described connection judgment subelement is used for judging code keypad and is connected equipment and disconnects, and if so, then detects
Code keypad be connected whether equipment connects, if it is not, then exiting the mechanism of reconnecting;
Described subelement of shaking hands is for when code keypad is detected with being connected equipment and connecting, code keypad sets with being connected
Standby again shake hands;
Described certification subelement is used for, after success of shaking hands, judging code keypad and being connected whether equipment two-way authentication becomes
Work(, if so, then recovers communication, if it is not, then refusal communication.
Further, also include radio unit, described radio unit is used for passing through communication in code keypad with being connected equipment
After the mechanism that reconnects sets up communication connection again, code keypad passes through broadcast mode and works as to each bottom layer driving module transmission being comprised
Front usb communication connection status, wherein, described each bottom layer driving module includes key-press input bottom layer driving module, sign board bottom
Drive module and scanner bottom layer driving module.
Further, described communication reconnects unit and is additionally operable to when usb communication exception is detected, and code keypad passes through actively
After closing usb communication, reopen usb communication, set up code keypad again and the communication connection being connected equipment.
It is different from prior art, technique scheme is passed through to insert frame number in the data sending, and sets up data and answer
Answer mechanism and communication reconnects mechanism, can have no progeny in the communications, re-establish communication service and connect, and efficiently solve cryptographic key
Disk usb communication is had no progeny because being disturbed in the short time, and identical data repeats to receive and sends, and causes communicating pair asynchronous or weight
Multiple operational issue.
Brief description
Fig. 1 is the flow chart of code keypad usb communication abnormal restoring method described in specific embodiment;
Fig. 2 is the schematic diagram of data is activation described in specific embodiment and response;
Fig. 3 is the flow chart reconnecting mechanism that communicates described in specific embodiment;
Fig. 4 is the flow chart connecting equipment sending data described in specific embodiment;
Fig. 5 is to connect device data described in specific embodiment to receive response handling process;
Fig. 6 is code keypad usb communication abnormal restoring system module block diagram described in specific embodiment.
Description of reference numerals:
10th, insert unit;
20th, response unit;
30th, communication reconnects unit;
40th, processing unit.
Specific embodiment
By the technology contents of detailed description technical scheme, structural features, realized purpose and effect, below in conjunction with concrete reality
Apply example and coordinate accompanying drawing to be explained in detail.
Refer to Fig. 1, a kind of the present embodiment code keypad usb communication abnormal restoring method, this code keypad usb communication is different
Often restoration methods, comprise the following steps:
S101, by data is activation sequencing, code keypad be connected in the data that equipment is sent insert frame number.
Wherein, described connection equipment is the equipment that code keypad is connected, and in the present embodiment, described connection equipment is preferably POS
Machine.In the present embodiment, described code keypad is provided with keyboard input module, and in other embodiments, described code keypad also wraps
Include signature plate module and scanner module, each module includes hardware circuit and corresponding bottom layer driving module respectively, wherein,
Keyboard input module is used for obtaining the password digital information of input, and described signature plate module is used for obtaining the letter such as signature of user
Breath, described scanner is used for scanning one-dimension code or Quick Response Code treats bar code information.Described keyboard input module, signature plate module and sweeping
Retouch rifle module and share a USB communication interface, each module carries out data transmit-receive by this USB communication interface.Each bottom layer driving mould
Block, when with being connected equipment (i.e. host side) proper communication, inserts frame number in each data of described transmission, wherein, in order to
It is easy to distinguish different pieces of information, the frame number of different pieces of information is different.The data of such as transmission can be incremented by by the sequencing sending
Frame number.
S102, in DRP data reception process, code keypad and be connected equipment return every frame data response message, response believe
Breath includes data receiver success, data receiver failure data receives time-out.Described response message is to be carried out by USB communication protocol
Send, wherein, the schematic diagram of data is activation and response as shown in Fig. 2 wherein, connects equipment for specially POS.Code keypad
With connection equipment every send or receive response data after, all determined whether by response message ACK other side have been received by count
According to, based on above communication process, when usb communication disconnects, foundation ACK reception condition carries out various usb communication error situations and sentences
Disconnected, and processed accordingly.
Whether S103, detection code keypad are abnormal with the usb communication being connected equipment, if so, then reconnect mechanism by communication
The communication connection set up code keypad again and be connected equipment.In order that the communication service being disturbed and disconnecting can be timely extensive
Multiple, the technical program is passed through communication and is reconnected the communication connection that mechanism is set up code keypad again and is connected equipment.Refer to Fig. 3,
When communication service detects transmission data or receiving data is abnormal, Auto-reconnect detection is supported in communication service, when connection equipment
When having reconnected with code keypad, connection equipment is re-started with code keypad shakes hands, and after success of shaking hands, is led to
Letter both sides carry out two-way authentication, and certification is passed through to detain communication service recovery communication function, and when two-way authentication failure, then refuses extensive
Multiple communication service.
S104, after communication connection is set up again, code keypad be connected equipment by received response message with
And the frame number of data, judge whether data repeats to receive, and communication counterpart data receiver situation, and abandon repeated data, with
And carry out data re-transmitting.When the frame number of received data is repeated, then illustrate that this data repeats to receive, needs will repeat
Data abandons;And when the response message receiving is to receive time-out or reception failure etc., then need to resend this data.
In the above-described embodiments, code keypad and connection equipment insert frame number in the data sending, and set up data
Acknowledgement mechanism and communication reconnect mechanism, can have no progeny in the communications, re-establish communication service and connect, by described response message
May know that the reception condition of the data sending, can determine whether to repeat receiving data by described frame number, therefore in communication
In have no progeny, can timely set up connection and communication service, and can effectively solve the problem that identical data repeat receive and send, cause
Communicating pair is asynchronous or repetitive operation problem.
In the present embodiment, frame number is to be inserted by USB communication interface agreement, is inserted without each bottom layer driving module
Frame number operates.In the case that multiple modules share USB communication interface, frame number insertion, each bottom are carried out by USB communication interface agreement
Layer drive module need not carry out the program upgrading of upgrade communication aspect.
In the above-described embodiments, described code keypad be connected equipment except re-establishing code keypad and being connected equipment
Communication connection when, carry out data repeating transmission and abandon repeated data, under the non-disconnection of communication service, simply response letter
Breath video data reception failure or response time-out when, be also carried out data weight and.Refer to Fig. 4, in an embodiment, connect equipment
The flow chart sending data.Connect equipment sending data and include step:
S401, connection equipment according to the response message receiving, judge the whether reception failure of the data that sends, if it is not, then
Communication is normal, if so, then goes to step S402;
S402, judge whether support data re-transmitting, if it is not, then going to step S405;If support data re-transmitting, go to step
S403;
S403, judge whether data re-transmitting number of times is full, if so, goes to step S405, if it is not, then going to step S404;
S404, frame number keep constant, retransmit this data;Step S401 is transferred back to after data re-transmitting;
S405, renewal frame number then send next data, and communication overtime exits.
Refer to Fig. 5, receive response handling process for connecting device data.This connection device data receives response processing stream
Journey includes:
S501, judge whether support data re-transmitting mechanism, if so, then go to step S502, if it is not, then going to step S505;Place
Reason response data, updates frame number, and that is, frame number adds 1;
S502, the frame number of extraction data, then go to step S503;
S503, judge whether frame number has repetition, that is, whether consistent, if so, then go to step S504, if it is not, then going to step
S505;
S504, Data duplication receive, and abandon the data repeating to receive;
S505, process response data, update frame number, that is, frame number adds 1.
In order to support each bottom layer driving to understand the connection status of current USB in real time, in the above-described embodiments, in cryptographic key
Disk is set up after communication connection again with being connected equipment and reconnecting mechanism by communication, and code keypad also can be by broadcast mode to being wrapped
The each bottom layer driving module containing sends current usb communication connection status, so that it is guaranteed that bottom layer driving module grasps currently in real time
Communications status.
In usb communication, code keypad end detects work(as a side of usb communication it is also desirable to communication abnormality can be carried out
Can, and carry out reconnecting process.Code keypad communication reconnects mechanism and flow process and the communication of connection equipment, and to reconnect mechanism consistent, simply
Because directly coming into contacts with USB hardware in code keypad end, code keypad end does not have communication service Auto-reconnect thread.Therefore password
Keyboard to reconnect mechanism as follows:Actively disconnect USB, then reopen USB.When code keypad actively disconnects USB and connects, connect
Equipment can detect exception quickly, and automatically into Auto-reconnect detection and recovers;So so that both sides can be synchronous as early as possible
Communications status;Whether by the frame number of communication protocol, to distinguish is repeated data.
Refer to Fig. 6, a kind of embodiment code keypad usb communication abnormal restoring system, this code keypad usb communication is abnormal
Recovery system, reconnects unit 30 and processing unit 40 including insertion unit 10, response unit 20, communication;
Described insertion unit 10 be used for by data is activation sequencing, code keypad be connected the number that equipment is sent
According to middle insertion frame number;
Described response unit 20 is used in DRP data reception process, and code keypad returns answering of every frame data with being connected equipment
Answer information, response message includes data receiver success, data receiver failure data receives time-out;
Whether described communication reconnects unit 30 abnormal with the usb communication being connected equipment for detecting code keypad, if so, then
The communication connection that mechanism is set up code keypad again and is connected equipment is reconnected by communication;
Described processing unit 40 is used for after communication connection is set up again, code keypad be connected equipment by received
Response message and data frame number, judge whether data repeats to receive, and communication counterpart data receiver situation, and abandoning
Repeated data, and carry out data re-transmitting.
In embodiment, code keypad and connection equipment insert frame number in the data sending, and set up data answering machine
System and communication reconnect mechanism, can have no progeny in the communications, re-establish communication service and connect, be may know that by described response message
The reception condition of the data sending, can determine whether to repeat receiving data by described frame number, therefore has no progeny in the communications,
Connection and communication service can timely be set up, and can effectively solve the problem that identical data repeats to receive and sends, cause communication double
The asynchronous or repetitive operation problem in side.
In the present embodiment, frame number is to be inserted by USB communication interface agreement, is inserted without each bottom layer driving module
Frame number operates.In the case that multiple modules share USB communication interface, frame number insertion, each bottom are carried out by USB communication interface agreement
Layer drive module need not carry out the program upgrading of upgrade communication aspect.
In one embodiment, described communication reconnect unit include connection judgment subelement, shake hands subelement and certification single
Unit;
Whether described connection judgment subelement is used for judging code keypad and is connected equipment and disconnects, and if so, then detects
Code keypad be connected whether equipment connects, if it is not, then exiting the mechanism of reconnecting;
Described subelement of shaking hands is for when code keypad is detected with being connected equipment and connecting, code keypad sets with being connected
Standby again shake hands;
Described certification subelement is used for, after success of shaking hands, judging code keypad and being connected whether equipment two-way authentication becomes
Work(, if so, then recovers communication, if it is not, then refusal communication.
In order to support each bottom layer driving to understand the connection status of current USB in real time, described code keypad usb communication is different
Often recovery system also includes radio unit, and described radio unit is used for reconnecting mechanism with being connected equipment by communication in code keypad
After setting up communication connection again, code keypad passes through broadcast mode and leads to each bottom layer driving module current USB of transmission being comprised
Letter connection status, wherein, described each bottom layer driving module includes key-press input bottom layer driving module, sign board bottom layer driving module
With scanner bottom layer driving module.
Described communication reconnects unit and is additionally operable to when usb communication exception is detected, and code keypad leads to by actively cutting out USB
After letter, reopen usb communication, set up code keypad again and the communication connection being connected equipment.In usb communication, cryptographic key
Disk end as usb communication a side it is also desirable to communication abnormality detection function can be carried out, and carry out reconnecting process.Code keypad
Communication reconnects mechanism and flow process and to reconnect mechanism consistent for the communication connecting equipment, only because code keypad end is direct and USB is hard
Part is come into contacts with, and code keypad end does not have communication service Auto-reconnect thread.Therefore code keypad to reconnect mechanism as follows:Actively disconnected
Open USB, then reopen USB.When code keypad actively disconnects USB and connects, connection equipment can detect exception quickly, and from
The dynamic Auto-reconnect that enters detects and recovers;So so that both sides can synchronous communication state as early as possible;By the frame of communication protocol
Number, whether to distinguish is repeated data.
It should be noted that herein, such as first and second or the like relational terms are used merely to a reality
Body or operation are made a distinction with another entity or operation, and not necessarily require or imply these entities or deposit between operating
In any this actual relation or order.And, term " inclusion ", "comprising" or its any other variant are intended to
The comprising of nonexcludability, so that include a series of process of key elements, method, article or terminal unit not only include those
Key element, but also include other key elements being not expressly set out, or also include for this process, method, article or end
The intrinsic key element of end equipment.In the absence of more restrictions, limited by sentence " including ... " or " comprising ... "
It is not excluded that also there is other key element in process, method, article or the terminal unit including described key element in key element.This
Outward, herein, " more than ", " less than ", " exceeding " etc. be interpreted as not including this number;" more than ", " below ", " within " etc. understand
It is including this number.
Those skilled in the art are it should be appreciated that the various embodiments described above can be provided as method, device or computer program product
Product.These embodiments can be using complete hardware embodiment, complete software embodiment or the embodiment combining software and hardware aspect
Form.All or part of step in the method that the various embodiments described above are related to can be instructed by program correlation hardware Lai
Complete, described program can be stored in the storage medium that computer equipment can read, for executing the various embodiments described above side
All or part of step described in method.Described computer equipment, including but not limited to:Personal computer, server, general-purpose computations
Machine, special-purpose computer, the network equipment, embedded device, programmable device, intelligent mobile terminal, intelligent home device, Wearable
Smart machine, vehicle intelligent equipment etc.;Described storage medium, including but not limited to:RAM, ROM, magnetic disc, tape, CD, sudden strain of a muscle
Deposit, USB flash disk, portable hard drive, storage card, memory stick, webserver storage, network cloud storage etc..
The various embodiments described above are with reference to the method according to embodiment, equipment (system) and computer program
Flow chart and/or block diagram are describing.It should be understood that can be by every in computer program instructions flowchart and/or block diagram
Flow process in one flow process and/or square frame and flow chart and/or block diagram and/or the combination of square frame.These computers can be provided
Programmed instruction to computer equipment processor to produce a machine so that by the finger of the computing device of computer equipment
Order produces and is used for what realization was specified in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame
The device of function.
These computer program instructions may be alternatively stored in and the computer that computer equipment works in a specific way can be guided to set
So that the instruction being stored in this computer equipment readable memory produces the manufacture including command device in standby readable memory
Product, this command device is realized in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame middle finger
Fixed function.
These computer program instructions also can be loaded on computer equipment so that executing a series of on a computing device
Operating procedure is to produce computer implemented process, thus the instruction executing on a computing device is provided for realizing in flow process
The step of the function of specifying in one flow process of figure or multiple flow process and/or one square frame of block diagram or multiple square frame.
Although being described to the various embodiments described above, those skilled in the art once know basic wound
The property made concept, then can make other change and modification to these embodiments, so the foregoing is only embodiments of the invention,
Not thereby the equivalent structure that the scope of patent protection of the restriction present invention, every utilization description of the invention and accompanying drawing content are made
Or equivalent flow conversion, or directly or indirectly it is used in other related technical fields, all include the patent in the present invention in the same manner
Within protection domain.