commands.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. };
  45. /**
  46. * [CASH_DRAWER Cash Drawer]
  47. * @type {Object}
  48. */
  49. _.CASH_DRAWER = {
  50. CD_KICK_2: [0x1b, 0x70, 0x00], // Sends a pulse to pin 2 []
  51. CD_KICK_5: [0x1b, 0x70, 0x01], // Sends a pulse to pin 5 []
  52. };
  53. /**
  54. * [MARGINS Margins sizes]
  55. * @type {Object}
  56. */
  57. _.MARGINS = {
  58. BOTTOM: [0x1b, 0x4f], // Fix bottom size
  59. LEFT: [0x1b, 0x6c], // Fix left size
  60. RIGHT: [0x1b, 0x51], // Fix right size
  61. };
  62. /**
  63. * [PAPER Paper]
  64. * @type {Object}
  65. */
  66. _.PAPER = {
  67. PAPER_FULL_CUT: [0x1d, 0x56, 0x00], // Full cut paper
  68. PAPER_PART_CUT: [0x1d, 0x56, 0x01], // Partial cut paper
  69. PAPER_CUT_A: [0x1d, 0x56, 0x41], // Partial cut paper
  70. PAPER_CUT_B: [0x1d, 0x56, 0x42], // Partial cut paper
  71. };
  72. /**
  73. * [TEXT_FORMAT Text format]
  74. * @type {Object}
  75. */
  76. _.TEXT_FORMAT = {
  77. TXT_NORMAL: [0x1b, 0x21, 0x00], // Normal text
  78. TXT_2HEIGHT: [0x1b, 0x21, 0x10], // Double height text
  79. TXT_2WIDTH: [0x1b, 0x21, 0x20], // Double width text
  80. TXT_4SQUARE: [0x1b, 0x21, 0x30], // Double width & height text
  81. TXT_UNDERL_OFF: [0x1b, 0x2d, 0x00], // Underline font OFF
  82. TXT_UNDERL_ON: [0x1b, 0x2d, 0x01], // Underline font 1-dot ON
  83. TXT_UNDERL2_ON: [0x1b, 0x2d, 0x02], // Underline font 2-dot ON
  84. TXT_BOLD_OFF: [0x1b, 0x45, 0x00], // Bold font OFF
  85. TXT_BOLD_ON: [0x1b, 0x45, 0x01], // Bold font ON
  86. TXT_ITALIC_OFF: [0x1b, 0x35], // Italic font ON
  87. TXT_ITALIC_ON: [0x1b, 0x34], // Italic font ON
  88. TXT_FONT_A: [0x1b, 0x4d, 0x00], // Font type A
  89. TXT_FONT_B: [0x1b, 0x4d, 0x01], // Font type B
  90. TXT_FONT_C: [0x1b, 0x4d, 0x02], // Font type C
  91. TXT_ALIGN_LT: [0x1b, 0x61, 0x00], // Left justification
  92. TXT_ALIGN_CT: [0x1b, 0x61, 0x01], // Centering
  93. TXT_ALIGN_RT: [0x1b, 0x61, 0x02], // Right justification
  94. };
  95. /**
  96. * [BARCODE_FORMAT Barcode format]
  97. * @type {Object}
  98. */
  99. _.BARCODE_FORMAT = {
  100. BARCODE_TXT_OFF: [0x1d, 0x48, 0x00], // HRI barcode chars OFF
  101. BARCODE_TXT_ABV: [0x1d, 0x48, 0x01], // HRI barcode chars above
  102. BARCODE_TXT_BLW: [0x1d, 0x48, 0x02], // HRI barcode chars below
  103. BARCODE_TXT_BTH: [0x1d, 0x48, 0x03], // HRI barcode chars both above and below
  104. BARCODE_FONT_A: [0x1d, 0x66, 0x00], // Font type A for HRI barcode chars
  105. BARCODE_FONT_B: [0x1d, 0x66, 0x01], // Font type B for HRI barcode chars
  106. BARCODE_HEIGHT: function (height) { // Barcode Height [1-255]
  107. return [0x1d, 0x68, height];
  108. },
  109. BARCODE_WIDTH: function (width) { // Barcode Width [2-6]
  110. return [0x1d, 0x77, width];
  111. },
  112. BARCODE_HEIGHT_DEFAULT: [0x1d, 0x68, 0x64], // Barcode height default:100
  113. BARCODE_WIDTH_DEFAULT: [0x1d, 0x77, 0x01], // Barcode width default:1
  114. BARCODE_UPC_A: [0x1d, 0x6b, 0x00], // Barcode type UPC-A
  115. BARCODE_UPC_E: [0x1d, 0x6b, 0x01], // Barcode type UPC-E
  116. BARCODE_EAN13: [0x1d, 0x6b, 0x02], // Barcode type EAN13
  117. BARCODE_EAN8: [0x1d, 0x6b, 0x03], // Barcode type EAN8
  118. BARCODE_CODE39: [0x1d, 0x6b, 0x04], // Barcode type CODE39
  119. BARCODE_ITF: [0x1d, 0x6b, 0x05], // Barcode type ITF
  120. BARCODE_NW7: [0x1d, 0x6b, 0x06], // Barcode type NW7
  121. BARCODE_CODE93: [0x1d, 0x6b, 0x48], // Barcode type CODE93
  122. BARCODE_CODE128: [0x1d, 0x6b, 0x49], // Barcode type CODE128
  123. };
  124. /**
  125. * [IMAGE_FORMAT Image format]
  126. * @type {Object}
  127. */
  128. _.IMAGE_FORMAT = {
  129. S_RASTER_N: [0x1d, 0x76, 0x30, 0x00], // Set raster image normal size
  130. S_RASTER_2W: [0x1d, 0x76, 0x30, 0x01], // Set raster image double width
  131. S_RASTER_2H: [0x1d, 0x76, 0x30, 0x02], // Set raster image double height
  132. S_RASTER_Q: [0x1d, 0x76, 0x30, 0x03], // Set raster image quadruple
  133. };
  134. /**
  135. * [BITMAP_FORMAT description]
  136. * @type {Object}
  137. */
  138. _.BITMAP_FORMAT = {
  139. BITMAP_S8: [0x1b, 0x2a, 0x00],
  140. BITMAP_D8: [0x1b, 0x2a, 0x01],
  141. BITMAP_S24: [0x1b, 0x2a, 0x20],
  142. BITMAP_D24: [0x1b, 0x2a, 0x21]
  143. };
  144. /**
  145. * [GSV0_FORMAT description]
  146. * @type {Object}
  147. */
  148. _.GSV0_FORMAT = {
  149. GSV0_NORMAL: [0x1d, 0x76, 0x30, 0x00],
  150. GSV0_DW: [0x1d, 0x76, 0x30, 0x01],
  151. GSV0_DH: [0x1d, 0x76, 0x30, 0x02],
  152. GSV0_DWDH: [0x1d, 0x76, 0x30, 0x03]
  153. };
  154. /**
  155. * [BEEP description]
  156. * @type {string}
  157. */
  158. _.BEEP = [0x1b, 0x42]; // Printer Buzzer pre hex
  159. /**
  160. * [COLOR description]
  161. * @type {Object}
  162. */
  163. _.COLOR = {
  164. 0: [0x1b, 0x72, 0x00], // black
  165. 1: [0x1b, 0x72, 0x01] // red
  166. };
  167. /**
  168. * [exports description]
  169. * @type {[type]}
  170. */
  171. module.exports = _;