commands.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /**
  2. * 修改自https://github.com/song940/node-escpos/blob/master/commands.js
  3. * ESC/POS _ (Constants)
  4. */
  5. var _ = {
  6. LF: [0x0a],
  7. FS: [0x1c],
  8. FF: [0x0c],
  9. GS: [0x1d],
  10. DLE: [0x10],
  11. EOT: [0x04],
  12. NUL: [0x00],
  13. ESC: [0x1b],
  14. EOL: '\n',
  15. };
  16. /**
  17. * [FEED_CONTROL_SEQUENCES Feed control sequences]
  18. * @type {Object}
  19. */
  20. _.FEED_CONTROL_SEQUENCES = {
  21. CTL_LF: [0x0a], // Print and line feed
  22. CTL_GLF: [0x4a, 0x00], // Print and feed paper (without spaces between lines)
  23. CTL_FF: [0x0c], // Form feed
  24. CTL_CR: [0x0d], // Carriage return
  25. CTL_HT: [0x09], // Horizontal tab
  26. CTL_VT: [0x0b], // Vertical tab
  27. };
  28. _.CHARACTER_SPACING = {
  29. CS_DEFAULT: [0x1b, 0x20, 0x00],
  30. CS_SET: [0x1b, 0x20]
  31. };
  32. _.LINE_SPACING = {
  33. LS_DEFAULT: [0x1b, 0x32],
  34. LS_SET: [0x1b, 0x33]
  35. };
  36. /**
  37. * [HARDWARE Printer hardware]
  38. * @type {Object}
  39. */
  40. _.HARDWARE = {
  41. HW_INIT: [0x1b, 0x40], // Clear data in buffer and reset modes
  42. HW_SELECT: [0x1b, 0x3d, 0x01], // Printer select
  43. HW_RESET: [0x1b, 0x3f, 0x0a, 0x00], // Reset printer hardware
  44. Print:[0x1b, 0x64,0x01] //Print and feed paper
  45. };
  46. /**
  47. * [CASH_DRAWER Cash Drawer]
  48. * @type {Object}
  49. */
  50. _.CASH_DRAWER = {
  51. CD_KICK_2: [0x1b, 0x70, 0x00], // Sends a pulse to pin 2 []
  52. CD_KICK_5: [0x1b, 0x70, 0x01], // Sends a pulse to pin 5 []
  53. };
  54. /**
  55. * [MARGINS Margins sizes]
  56. * @type {Object}
  57. */
  58. _.MARGINS = {
  59. BOTTOM: [0x1b, 0x4f], // Fix bottom size
  60. LEFT: [0x1b, 0x6c], // Fix left size
  61. RIGHT: [0x1b, 0x51], // Fix right size
  62. };
  63. /**
  64. * [PAPER Paper]
  65. * @type {Object}
  66. */
  67. _.PAPER = {
  68. PAPER_FULL_CUT: [0x1d, 0x56, 0x00], // Full cut paper
  69. PAPER_PART_CUT: [0x1d, 0x56, 0x01], // Partial cut paper
  70. PAPER_CUT_A: [0x1d, 0x56, 0x41], // Partial cut paper
  71. PAPER_CUT_B: [0x1d, 0x56, 0x42], // Partial cut paper
  72. };
  73. /**
  74. * [TEXT_FORMAT Text format]
  75. * @type {Object}
  76. */
  77. _.TEXT_FORMAT = {
  78. TXT_NORMAL: [0x1b, 0x21, 0x00], // Normal text
  79. TXT_2HEIGHT: [0x1b, 0x21, 0x10], // Double height text
  80. TXT_2WIDTH: [0x1b, 0x21, 0x20], // Double width text
  81. TXT_4SQUARE: [0x1b, 0x21, 0x30], // Double width & height text
  82. TXT_UNDERL_OFF: [0x1b, 0x2d, 0x00], // Underline font OFF
  83. TXT_UNDERL_ON: [0x1b, 0x2d, 0x01], // Underline font 1-dot ON
  84. TXT_UNDERL2_ON: [0x1b, 0x2d, 0x02], // Underline font 2-dot ON
  85. TXT_BOLD_OFF: [0x1b, 0x45, 0x00], // Bold font OFF
  86. TXT_BOLD_ON: [0x1b, 0x45, 0x01], // Bold font ON
  87. TXT_ITALIC_OFF: [0x1b, 0x35], // Italic font ON
  88. TXT_ITALIC_ON: [0x1b, 0x34], // Italic font ON
  89. TXT_FONT_A: [0x1b, 0x4d, 0x00], // Font type A
  90. TXT_FONT_B: [0x1b, 0x4d, 0x01], // Font type B
  91. TXT_FONT_C: [0x1b, 0x4d, 0x02], // Font type C
  92. TXT_ALIGN_LT: [0x1b, 0x61, 0x00], // Left justification
  93. TXT_ALIGN_CT: [0x1b, 0x61, 0x01], // Centering
  94. TXT_ALIGN_RT: [0x1b, 0x61, 0x02], // Right justification
  95. };
  96. /**
  97. * [BARCODE_FORMAT Barcode format]
  98. * @type {Object}
  99. */
  100. _.BARCODE_FORMAT = {
  101. BARCODE_TXT_OFF: [0x1d, 0x48, 0x00], // HRI barcode chars OFF
  102. BARCODE_TXT_ABV: [0x1d, 0x48, 0x01], // HRI barcode chars above
  103. BARCODE_TXT_BLW: [0x1d, 0x48, 0x02], // HRI barcode chars below
  104. BARCODE_TXT_BTH: [0x1d, 0x48, 0x03], // HRI barcode chars both above and below
  105. BARCODE_FONT_A: [0x1d, 0x66, 0x00], // Font type A for HRI barcode chars
  106. BARCODE_FONT_B: [0x1d, 0x66, 0x01], // Font type B for HRI barcode chars
  107. BARCODE_HEIGHT: function (height) { // Barcode Height [1-255]
  108. return [0x1d, 0x68, height];
  109. },
  110. BARCODE_WIDTH: function (width) { // Barcode Width [2-6]
  111. return [0x1d, 0x77, width];
  112. },
  113. BARCODE_HEIGHT_DEFAULT: [0x1d, 0x68, 0x64], // Barcode height default:100
  114. BARCODE_WIDTH_DEFAULT: [0x1d, 0x77, 0x01], // Barcode width default:1
  115. BARCODE_UPC_A: [0x1d, 0x6b, 0x00], // Barcode type UPC-A
  116. BARCODE_UPC_E: [0x1d, 0x6b, 0x01], // Barcode type UPC-E
  117. BARCODE_EAN13: [0x1d, 0x6b, 0x02], // Barcode type EAN13
  118. BARCODE_EAN8: [0x1d, 0x6b, 0x03], // Barcode type EAN8
  119. BARCODE_CODE39: [0x1d, 0x6b, 0x04], // Barcode type CODE39
  120. BARCODE_ITF: [0x1d, 0x6b, 0x05], // Barcode type ITF
  121. BARCODE_NW7: [0x1d, 0x6b, 0x06], // Barcode type NW7
  122. BARCODE_CODE93: [0x1d, 0x6b, 0x48], // Barcode type CODE93
  123. BARCODE_CODE128: [0x1d, 0x6b, 0x49], // Barcode type CODE128
  124. };
  125. /**
  126. * [IMAGE_FORMAT Image format]
  127. * @type {Object}
  128. */
  129. _.IMAGE_FORMAT = {
  130. S_RASTER_N: [0x1d, 0x76, 0x30, 0x00], // Set raster image normal size
  131. S_RASTER_2W: [0x1d, 0x76, 0x30, 0x01], // Set raster image double width
  132. S_RASTER_2H: [0x1d, 0x76, 0x30, 0x02], // Set raster image double height
  133. S_RASTER_Q: [0x1d, 0x76, 0x30, 0x03], // Set raster image quadruple
  134. };
  135. /**
  136. * [BITMAP_FORMAT description]
  137. * @type {Object}
  138. */
  139. _.BITMAP_FORMAT = {
  140. BITMAP_S8: [0x1b, 0x2a, 0x00],
  141. BITMAP_D8: [0x1b, 0x2a, 0x01],
  142. BITMAP_S24: [0x1b, 0x2a, 0x20],
  143. BITMAP_D24: [0x1b, 0x2a, 0x21]
  144. };
  145. /**
  146. * [GSV0_FORMAT description]
  147. * @type {Object}
  148. */
  149. _.GSV0_FORMAT = {
  150. GSV0_NORMAL: [0x1d, 0x76, 0x30, 0x00],
  151. GSV0_DW: [0x1d, 0x76, 0x30, 0x01],
  152. GSV0_DH: [0x1d, 0x76, 0x30, 0x02],
  153. GSV0_DWDH: [0x1d, 0x76, 0x30, 0x03]
  154. };
  155. /**
  156. * [BEEP description]
  157. * @type {string}
  158. */
  159. _.BEEP = [0x1b, 0x42]; // Printer Buzzer pre hex
  160. /**
  161. * [COLOR description]
  162. * @type {Object}
  163. */
  164. _.COLOR = {
  165. 0: [0x1b, 0x72, 0x00], // black
  166. 1: [0x1b, 0x72, 0x01] // red
  167. };
  168. /**
  169. * [exports description]
  170. * @type {[type]}
  171. */
  172. module.exports = _;