Disclosure of Invention
The invention provides a card reading method and a card reading device of a card reader, and mainly aims to solve the problems that in the prior art, a trigger needs to be added to a peripheral hardware circuit of the card reader, so that the peripheral hardware cost of the card reader is increased, and the use is inconvenient.
In order to solve the technical problems, the invention adopts the following technical scheme:
a card reading method of a card reader comprises the following steps;
acquiring a power-on signal of a card reader, and initializing the card reader according to the power-on signal;
after the card is detected to be inserted into the card reader, a preset detection message is transmitted to an upper computer through a communication protocol;
verifying and judging the response message fed back by the upper computer according to a preset time threshold and a verification parameter, and resetting the card reader when the verification and judgment are failed; and performing card reading operation on the card in the card reader until the verification judgment is passed.
As an implementable manner, the response message fed back by the upper computer is verified and judged according to a preset time threshold and a verification parameter, and when the verification judgment is failed, the card reader is reset; until the verification judgment is passed, carrying out card reading operation on the card in the card reader, and comprising the following steps;
judging the response message fed back by the upper computer according to a preset time threshold;
if the card reader receives a response message fed back by the upper computer within a preset time threshold, analyzing the response message; verifying the analysis result according to a preset verification parameter, and reading the card in the card reader according to the verification result;
and if the card reader does not receive the response message fed back by the upper computer within the preset time threshold, resetting the card reader.
As an implementation manner, the reading operation of the card in the card reader according to the verification result includes the following steps;
verifying the analysis result according to a preset verification parameter;
if the verification is passed, performing card reading operation on the card in the card reader;
and if the verification fails, resetting the card reader.
As an implementable manner, the card reading method of the card reader provided by the invention further comprises the following steps;
and after the card reader is initialized according to the power-on signal, circularly detecting whether the card reader is inserted into the card or not.
As an implementable manner, the card reading method of the card reader provided by the invention further comprises the following steps;
and after the card is detected to be inserted into the card reader, acquiring target data in the card, and storing the target data into a cache area of the card reader.
Correspondingly, the invention also provides a card reading device of the card reader, which comprises a power-on initialization module, a transmission module and a card reading module;
the power-on initialization module is used for acquiring a power-on signal of the card reader and initializing the card reader according to the power-on signal;
the transmission module is used for transmitting a preset detection message to the upper computer through a communication protocol after the card is detected to be inserted into the card reader;
the card reading module is used for verifying and judging the response message fed back by the upper computer according to a preset time threshold and the verification parameters, and resetting the card reader when the verification and judgment are failed; and performing card reading operation on the card in the card reader until the verification judgment is passed.
As an implementation manner, the card reading module comprises a judging unit, an analyzing unit and a resetting unit;
the judging unit is used for judging the response message fed back by the upper computer according to a preset time threshold;
the analysis unit is used for analyzing the response message fed back by the upper computer if the card reader receives the response message within a preset time threshold; verifying the analysis result according to a preset verification parameter, and reading the card in the card reader according to the verification result;
and the resetting unit is used for resetting the card reader if the card reader does not receive the response message fed back by the upper computer within a preset time threshold.
As an implementation manner, the parsing unit includes an authentication subunit, a card reading subunit and a resetting subunit;
the verification subunit is used for verifying the analysis result according to a preset verification parameter;
the card reading subunit is used for reading the card in the card reader if the verification is passed;
and the resetting subunit is used for resetting the card reader if the verification fails.
As an implementation manner, the card reading device of the card reader provided by the invention further comprises a cycle detection module;
and the cycle detection module is used for performing cycle detection on whether the card reader is inserted into the card or not after the card reader is initialized according to the power-on signal.
As an implementation manner, the card reading device of the card reader provided by the invention further comprises a cache module;
the cache module is used for acquiring target data in the card and storing the target data into a cache area of the card reader after the card is detected to be inserted into the card reader.
Compared with the prior art, the technical scheme has the following advantages:
according to the card reading method and the card reading device of the card reader, after the card is detected to be inserted into the card reader, the preset detection message is transmitted to the upper computer through a communication protocol; the card reader actively verifies and judges the communication condition between the card reader and the upper computer, and after the verification and judgment are failed, the card reader is reset, namely, the controller of the upper computer enumerates the card reader again; until the verification judgment is passed, performing card reading operation on the card in the card reader; therefore, the increase of the cost of peripheral hardware of the card reader is avoided, and when the upper computer cannot read target data in the card reader, the upper computer can automatically reset, so that the controller of the upper computer can enumerate the card reader again, and the robustness of the card reader is enhanced.
Detailed Description
The above and further features and advantages of the present invention will be apparent from the following, complete description of the invention, taken in conjunction with the accompanying drawings, wherein the described embodiments are merely some, but not all embodiments of the invention.
Referring to fig. 1, a card reading method of a card reader according to an embodiment of the present invention includes the following steps;
s100, acquiring a power-on signal of the card reader, and initializing the card reader according to the power-on signal;
s200, after the card is detected to be inserted into the card reader, transmitting a preset detection message to an upper computer through a communication protocol;
s300, verifying and judging the response message fed back by the upper computer according to a preset time threshold and a verification parameter, and resetting the card reader when the verification and judgment are failed; and performing card reading operation on the card in the card reader until the verification judgment is passed.
It should be noted that the card reader of the present invention is of a type that performs data interaction with an upper computer in a USB interface manner. The upper computer comprises a PC end, a flat plate end, a mobile end, an industrial personal computer and other equipment. That is, the invention actually carries out data interaction on the card reader and the upper computer through the USB data line, and the upper computer reads the card of the card reader. The card reader is powered on to obtain the power-on signal, so that the card reader is initialized according to the power-on signal, wherein the initialization comprises initialization not limited to the card reader system and initialization of USB port configuration.
In this embodiment, the communication protocol includes, but is not limited to, USB communication protocol, SCSI communication protocol, CCID communication protocol, etc., and can be implemented by configuring the communication protocol in advance. The preset detection message comprises a message header, a message length, a command word parameter, data content and data verification. And the response message fed back by the upper computer comprises a message header, a message length, command word parameters, data contents and data verification.
Specifically, the data content in the detection message and the data content in the response message are in a corresponding relationship. The correspondence may be a preset data content implementation. For example, the data content in the detection message is "hello", and the data content of the response message corresponding thereto is "ok". The specific transmission feedback process is that after the upper computer receives the detection message with the hello, the detection message is analyzed and recoded. When the data content of the detected message obtained by analysis is hello, the data content is recoded to obtain a response message with ok and the response message is fed back to the card reader. Of course, if the data content of the detected packet obtained by the analysis is other data, the data may not be fed back directly or a response packet with "no" may be fed back. In other embodiments, the specific content of the correspondence between the data content in the detection message and the data content in the response message may be set arbitrarily.
For the card reader, the standard of the verification judgment needs to obtain the response message within a preset time threshold, and the data content in the response message needs to be matched with the verification parameter, which can be simply understood as that the data content of the response message is "ok". Of course, the verification parameter may be other preset data. That is, if an accurate response message is not obtained within a preset time threshold, the card reader is reset, that is, the controller of the upper computer re-enumerates the card reader. And performing card reading operation on the card in the card reader until the verification judgment is passed. The operation that a reset key needs to be manually pressed in the prior art is avoided, the time of a user is saved, and the cost of peripheral hardware of the card reader does not need to be increased.
According to the card reading method of the card reader, after the card is detected to be inserted into the card reader, the preset detection message is transmitted to the upper computer through a communication protocol; the card reader actively verifies and judges the communication condition between the card reader and the upper computer, and after the verification and judgment are failed, the card reader is reset, namely, the controller of the upper computer enumerates the card reader again; until the verification judgment is passed, performing card reading operation on the card in the card reader; therefore, the increase of the cost of peripheral hardware of the card reader is avoided, and when the upper computer cannot read target data in the card reader, the upper computer can automatically reset, so that the controller of the upper computer can enumerate the card reader again, and the robustness of the card reader is enhanced.
Further, step S300 includes the following steps;
s310, judging a response message fed back by the upper computer according to a preset time threshold;
s320, if the card reader receives a response message fed back by the upper computer within a preset time threshold, analyzing the response message; verifying the analysis result according to a preset verification parameter, and reading the card in the card reader according to the verification result;
and S320, if the card reader does not receive the response message fed back by the upper computer within the preset time threshold, resetting the card reader.
The time threshold is set in the card reader in advance, and can be 0.5S, 1S, 2S, 4S and the like. In this embodiment, if the time threshold is 1S, that is, if no response message fed back by the upper computer is received in 1S, the card reader is directly reset. The reset processing of the card reader is to enumerate the card reader again by the controller of the upper computer. The whole process of re-electrifying, initializing and sending the detection message can be automatically carried out, the operation of the card reader after the fault occurs is simplified, and convenience is brought to users.
Further, in step S320, a card reading operation is performed on a card in the card reader according to the verification result, including the following steps; verifying the analysis result according to a preset verification parameter; if the verification is passed, performing card reading operation on the card in the card reader; and if the verification fails, resetting the card reader.
The specific process of the verification may be to compare the preset verification parameter with the data content of the response message obtained by the analysis. And if the verification parameters are consistent with the data content of the response message, the verification is passed. If the verification parameter is inconsistent with the data content of the response message, the verification is not passed. Through simple comparison, complex algorithms are avoided, and therefore the response speed of the card reader is improved. The invention improves the stability grade of the card reader system with little software overhead on the premise of not increasing the hardware cost, thereby greatly improving the user experience.
In order to further improve the robustness of the card reader, compared with the first embodiment, the card reading method of the card reader provided by the second embodiment of the invention is characterized by further comprising the following steps; and after the card reader is initialized according to the power-on signal, circularly detecting whether the card reader is inserted into the card or not. The parameters configured for the port may be circularly monitored after the card reader is initialized. For example, the port configuration is 0 in the case of no card and 1 in the case of card. Then monitoring that the parameter of the port configuration becomes 1, then it is assumed that a card is inserted into the card reader. In other embodiments, a particular card type may be further identified by setting different parameters. The cycle detection can also be realized by arranging a sensor in an insertion interface of the card, for example, a position sensor is arranged, and a trigger signal is generated when the card is detected to be inserted.
In order to improve the reading speed of the target data, compared with the first embodiment, the card reading method of the card reader provided by the third embodiment of the invention is characterized by further comprising the following steps; and after the card is detected to be inserted into the card reader, acquiring target data in the card, and storing the target data into a cache area of the card reader. The buffer area of the card reader is a temporary storage area, and after the card is detected to be inserted into the card reader, the communication protocol authentication result is not considered. Firstly, storing target data in a card to a cache region of a card reader, and after the verification judgment is passed, reading the target data in the cache region by an upper computer. The card reading interruption caused by the interaction problem between the card and the card reader in the use process can be avoided.
Based on the same inventive concept, the embodiment of the invention also provides a card reading device of the card reader, and the implementation of the system can be realized by referring to the process of the method, and the repeated parts are not described redundantly.
Fig. 2 is a schematic structural diagram of a card reading device of a card reader according to a fourth embodiment of the present invention, including a power-on initialization module 100, a transmission module 200, and a card reading module 300; the power-on initialization module 100 is configured to obtain a power-on signal of the card reader, and initialize the card reader according to the power-on signal; the transmission module 200 is used for transmitting a preset detection message to an upper computer through a communication protocol after detecting that the card is inserted into the card reader; the card reading module 300 is configured to verify and judge the response message fed back by the upper computer according to a preset time threshold and the verification parameter, and perform a card reading operation on a card in the card reader after the verification and judgment are passed.
According to the card reading device of the card reader, after the card is detected to be inserted into the card reader, the preset detection message is transmitted to the upper computer through a communication protocol; the card reader actively verifies and judges the communication condition between the card reader and the upper computer, and after the verification and judgment are failed, the card reader is reset, namely, the controller of the upper computer enumerates the card reader again; until the verification judgment is passed, performing card reading operation on the card in the card reader; therefore, the increase of the cost of peripheral hardware of the card reader is avoided, and when the upper computer cannot read target data in the card reader, the upper computer can automatically reset, so that the controller of the upper computer can enumerate the card reader again, and the robustness of the card reader is enhanced.
In order to further improve the robustness of the card reader, the card reading device of the card reader provided by the fourth embodiment of the present invention further includes a cycle detection module 400; the cycle detection module 400 is configured to perform a cycle detection on whether the card reader is inserted into the card after the card reader is initialized according to the power-on signal.
In order to increase the reading speed of the target data, the card reading device of the card reader provided by the fourth embodiment of the present invention further includes a cache module; the cache module is used for acquiring target data in the card and storing the target data into a cache area of the card reader after detecting that the card is inserted into the card reader.
Fig. 3 is a schematic structural diagram of the card reading module 300, which includes a determining unit 310, an analyzing unit 320, and a resetting unit 330; the judging unit 310 is configured to judge the response message fed back by the upper computer according to a preset time threshold; the analysis unit 320 is configured to analyze the response message if the card reader receives the response message fed back by the upper computer within a preset time threshold; verifying the analysis result according to a preset verification parameter, and reading the card in the card reader according to the verification result; the resetting unit 330 is configured to perform resetting processing on the card reader if the card reader does not receive the response message fed back by the upper computer within a preset time threshold.
Fig. 4 is a schematic structural diagram of the parsing unit 320, which includes an authentication subunit 321, a card reading subunit 322, and a reset subunit 323; the verification subunit 321 is configured to verify the analysis result according to a preset verification parameter; the card reading clip unit 322 is used for reading the card in the card reader if the verification is passed; the reset subunit 323 is configured to perform a reset process on the card reader if the verification fails.
Although the present invention has been described with reference to the preferred embodiments, it is not intended to limit the present invention, and those skilled in the art can make variations and modifications of the present invention without departing from the spirit and scope of the present invention by using the methods and technical contents disclosed above.