No Description

zfm20.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*jslint node:true, vars:true, bitwise:true, unparam:true */
  2. /*jshint unused:true */
  3. /*
  4. * Author: Zion Orent <zorent@ics.com>
  5. * Copyright (c) 2015 Intel Corporation.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. var fingerprint_lib = require('jsupm_zfm20');
  27. // Instantiate a ZFM20 Fingerprint reader on UART 0
  28. var myFingerprintSensor = new fingerprint_lib.ZFM20(0);
  29. // make sure port is initialized properly. 57600 baud is the default.
  30. if (!myFingerprintSensor.setupTty(fingerprint_lib.int_B57600))
  31. {
  32. console.log("Failed to setup tty port parameters");
  33. process.exit(1);
  34. }
  35. // how many valid stored templates (fingerprints) do we have?
  36. console.log("Total stored templates: " + myFingerprintSensor.getNumTemplates());
  37. console.log(" ");
  38. // now spin waiting for a fingerprint to successfully image
  39. console.log("Waiting for finger print...");
  40. while (myFingerprintSensor.generateImage() == fingerprint_lib.ZFM20.ERR_NO_FINGER)
  41. ;
  42. // in theory, we have an image
  43. console.log("Image captured, converting...");
  44. var rv = myFingerprintSensor.image2Tz(1);
  45. if (rv != fingerprint_lib.ZFM20.ERR_OK)
  46. {
  47. console.log("Image conversion failed with error code " + rv);
  48. process.exit(1);
  49. }
  50. console.log("Image conversion succeeded.");
  51. console.log("Searching database...");
  52. var myid = new fingerprint_lib.uint16Array(0);
  53. myid.setitem(0, 0);
  54. var myscore = new fingerprint_lib.uint16Array(0);
  55. myscore.setitem(0, 0);
  56. // we search for a print matching slot 1, where we stored our last
  57. // converted fingerprint
  58. rv = myFingerprintSensor.search(1, myid, myscore)
  59. if (rv != fingerprint_lib.ZFM20.ERR_OK)
  60. {
  61. if (rv == fingerprint_lib.ZFM20.ERR_FP_NOTFOUND)
  62. {
  63. console.log("Finger Print not found");
  64. process.exit(0);
  65. }
  66. else
  67. {
  68. console.log("Search failed with error code " + rv);
  69. process.exit(1);
  70. }
  71. }
  72. console.log("Fingerprint found!");
  73. console.log("ID: " + myid.getitem(0) + ", Score: " + myscore.getitem(0));
  74. // Print message when exiting
  75. function exit()
  76. {
  77. myFingerprintSensor = null;
  78. fingerprint_lib.cleanUp();
  79. fingerprint_lib = null;
  80. console.log("Exiting");
  81. process.exit(0);
  82. }
  83. process.on('SIGINT', exit);
  84. process.on('exit', exit);