No Description

ZFM20Sample.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
  3. * Copyright (c) 2015 Intel Corporation.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. //NOT TESTED!!!
  25. public class ZFM20Sample {
  26. public static void main(String[] args) throws InterruptedException {
  27. // ! [Interesting]
  28. // Instantiate a ZFM20 Fingerprint reader on UART 0
  29. upm_zfm20.ZFM20 fp = new upm_zfm20.ZFM20(0);
  30. // make sure port is initialized properly. 57600 baud is the default
  31. if (!fp.setupTty()) {
  32. System.err.println("Failed to setup tty port parameters");
  33. System.exit(-1);
  34. }
  35. // first, set the default password and address
  36. fp.setPassword(upm_zfm20.javaupm_zfm20.ZFM20_DEFAULT_PASSWORD);
  37. fp.setAddress(upm_zfm20.javaupm_zfm20.ZFM20_DEFAULT_ADDRESS);
  38. // now verify the password. If this fails, any other commands
  39. // will be ignored, so we just bail.
  40. if (fp.verifyPassword()) {
  41. System.out.println("Password verified.");
  42. } else {
  43. System.err.println("Password verification failed.");
  44. System.exit(-1);
  45. }
  46. // how many valid stored templates (fingerprints) do we have?
  47. System.out.println("Total stored templates: " + fp.getNumTemplates());
  48. // now spin waiting for a fingerprint to successfully image
  49. System.out.println("Waiting for finger print...");
  50. while (fp.generateImage() == upm_zfm20.ZFM20.ZFM20_ERRORS_T.ERR_NO_FINGER.swigValue());
  51. // in theory, we have an image
  52. System.out.println("Image captured, converting...");
  53. short rv = fp.image2Tz(1);
  54. if (rv != upm_zfm20.ZFM20.ZFM20_ERRORS_T.ERR_OK.swigValue()) {
  55. System.err.println("Image conversion failed with error code " + rv);
  56. System.exit(-1);
  57. }
  58. System.out.println("Image conversion succeeded");
  59. // we search for a print matching slot 1, where we shored our last
  60. // converted fingerprint
  61. int[] id = new int[1];
  62. int[] score = new int[1];
  63. rv = fp.search(1, id, score);
  64. if (rv != upm_zfm20.ZFM20.ZFM20_ERRORS_T.ERR_OK.swigValue()) {
  65. if (rv == upm_zfm20.ZFM20.ZFM20_ERRORS_T.ERR_FP_NOTFOUND.swigValue()) {
  66. System.out.println("Fingerprint not found");
  67. System.exit(0);
  68. } else {
  69. System.err.println("Search failed with error code " + rv);
  70. System.exit(-1);
  71. }
  72. }
  73. System.out.println("Fingerprint found!");
  74. System.out.println("ID: " + id[0] + ", Score: " + score[0]);
  75. // ! [Interesting]
  76. }
  77. }