ruby-escpos 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ruby-escpos.rb +146 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b8c1ba0864461c5156cce5ceece501ee2de5de24
|
4
|
+
data.tar.gz: a6aee089beadc829137976a1d8b36ec5a177a42c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 462246e1cbed5634ec4c53c6907b7db09bf90811864cc0cecdee28531d0f2a558d41886b82791cbc87c5fe5021f8863822d111d0692e8b83c676f5177d01b559
|
7
|
+
data.tar.gz: 450dbce1cd20b5921835ebbb9c3f08ad07f200819bf247f48be3152e356a849905f7241c03d28a20f86c988f1dc5c9641da17788be10bc1901c209e0d813ce71
|
data/lib/ruby-escpos.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
class RubyEscPos
|
2
|
+
attr_accessor :buffer
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@buffer = ''
|
6
|
+
end
|
7
|
+
|
8
|
+
def new_line(lines = 1)
|
9
|
+
text nil, lines
|
10
|
+
end
|
11
|
+
|
12
|
+
def set(align = TXT_ALIGN_LT, font = TXT_FONT_A, font_type = FONT_TYPE_NORMAL, width = 1, height = 1, density = nil)
|
13
|
+
write align
|
14
|
+
|
15
|
+
if height == 2 && width == 2
|
16
|
+
write TXT_NORMAL
|
17
|
+
write TXT_4SQUARE
|
18
|
+
elsif height == 2 && width != 2
|
19
|
+
write TXT_NORMAL
|
20
|
+
write TXT_2HEIGHT
|
21
|
+
elsif width == 2 && height != 2
|
22
|
+
write TXT_NORMAL
|
23
|
+
write TXT_2WIDTH
|
24
|
+
else
|
25
|
+
write TXT_NORMAL
|
26
|
+
end
|
27
|
+
|
28
|
+
if font_type == FONT_TYPE_BOLD
|
29
|
+
write TXT_BOLD_ON
|
30
|
+
write TXT_UNDERL_OFF
|
31
|
+
elsif font_type == FONT_TYPE_UNDERLINE
|
32
|
+
write TXT_BOLD_OFF
|
33
|
+
write TXT_UNDERL_ON
|
34
|
+
elsif font_type == FONT_TYPE_UNDERLINE_2
|
35
|
+
write TXT_BOLD_OFF
|
36
|
+
write TXT_UNDERL2_ON
|
37
|
+
elsif font_type == FONT_TYPE_BOLD_UNDERLINE
|
38
|
+
write TXT_BOLD_ON
|
39
|
+
write TXT_UNDERL_ON
|
40
|
+
elsif font_type == FONT_TYPE_BOLD_UNDERLINE_2
|
41
|
+
write TXT_BOLD_ON
|
42
|
+
write TXT_UNDERL2_ON
|
43
|
+
else
|
44
|
+
write TXT_BOLD_OFF
|
45
|
+
write TXT_UNDERL_OFF
|
46
|
+
end
|
47
|
+
|
48
|
+
write font
|
49
|
+
write density if density
|
50
|
+
end
|
51
|
+
|
52
|
+
def barcode(code, bc = BARCODE_UPC_A, pos = BARCODE_TXT_BLW, font = BARCODE_FONT_A, width, height)
|
53
|
+
write TXT_ALIGN_CT
|
54
|
+
write pos
|
55
|
+
write font
|
56
|
+
write bc
|
57
|
+
write code
|
58
|
+
end
|
59
|
+
|
60
|
+
def text(txt, new_lines = 1)
|
61
|
+
@buffer += txt if txt
|
62
|
+
|
63
|
+
(1..new_lines).each do
|
64
|
+
@buffer += "\n"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def cut(cut_type = PAPER_FULL_CUT)
|
69
|
+
write "\n\n\n\n\n\n"
|
70
|
+
write cut_type
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def write(data)
|
76
|
+
if data.is_a? String
|
77
|
+
@buffer += data
|
78
|
+
elsif data.is_a? Array
|
79
|
+
#@buffer += data.join
|
80
|
+
#@buffer += data.map { |b| sprintf(", 0x%02X", b) }.join
|
81
|
+
#@buffer += data.map { |x| x.hex }.pack('c*')
|
82
|
+
@buffer += data.pack('U*')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Feed control sequences
|
87
|
+
CTL_LF = [ 0x0a ] # Print and line feed
|
88
|
+
CTL_FF = [ 0x0c ] # Form feed
|
89
|
+
CTL_CR = [ 0x0d ] # Carriage return
|
90
|
+
CTL_HT = [ 0x09 ] # Horizontal tab
|
91
|
+
CTL_VT = [ 0x0b ] # Vertical tab
|
92
|
+
|
93
|
+
# Printer hardware
|
94
|
+
HW_INIT = [ 0x1b, 0x40 ] # Clear data in buffer and reset modes
|
95
|
+
HW_SELECT = [ 0x1b, 0x3d, 0x01 ] # Printer select
|
96
|
+
HW_RESET = [ 0x1b, 0x3f, 0x0a, 0x00 ] # Reset printer hardware
|
97
|
+
|
98
|
+
# Cash Drawer
|
99
|
+
CD_KICK_2 = [ 0x1b, 0x70, 0x00 ] # Sends a pulse to pin 2 = []
|
100
|
+
CD_KICK_5 = [ 0x1b, 0x70, 0x01 ] # Sends a pulse to pin 5 = []
|
101
|
+
|
102
|
+
# Paper
|
103
|
+
PAPER_FULL_CUT = [ 0x1d, 0x56, 0x00 ] # Full cut paper
|
104
|
+
PAPER_PART_CUT = [ 0x1d, 0x56, 0x01 ] # Partial cut paper
|
105
|
+
|
106
|
+
# Text format
|
107
|
+
TXT_NORMAL = [ 0x1b, 0x21, 0x00 ] # Normal text
|
108
|
+
TXT_2HEIGHT = [ 0x1b, 0x21, 0x10 ] # Double height text
|
109
|
+
TXT_2WIDTH = [ 0x1b, 0x21, 0x20 ] # Double width text
|
110
|
+
TXT_4SQUARE = [ 0x1b, 0x21, 0x30 ] # Quad area text
|
111
|
+
TXT_UNDERL_OFF = [ 0x1b, 0x2d, 0x00 ] # Underline font OFF
|
112
|
+
TXT_UNDERL_ON = [ 0x1b, 0x2d, 0x01 ] # Underline font 1-dot ON
|
113
|
+
TXT_UNDERL2_ON = [ 0x1b, 0x2d, 0x02 ] # Underline font 2-dot ON
|
114
|
+
TXT_BOLD_OFF = [ 0x1b, 0x45, 0x00 ] # Bold font OFF
|
115
|
+
TXT_BOLD_ON = [ 0x1b, 0x45, 0x01 ] # Bold font ON
|
116
|
+
TXT_FONT_A = [ 0x1b, 0x4d, 0x00 ] # Font type A
|
117
|
+
TXT_FONT_B = [ 0x1b, 0x4d, 0x01 ] # Font type B
|
118
|
+
TXT_ALIGN_LT = [ 0x1b, 0x61, 0x00 ] # Left justification
|
119
|
+
TXT_ALIGN_CT = [ 0x1b, 0x61, 0x01 ] # Centering
|
120
|
+
TXT_ALIGN_RT = [ 0x1b, 0x61, 0x02 ] # Right justification
|
121
|
+
|
122
|
+
# Barcode format
|
123
|
+
BARCODE_TXT_OFF = [ 0x1d, 0x48, 0x00 ] # HRI barcode chars OFF
|
124
|
+
BARCODE_TXT_ABV = [ 0x1d, 0x48, 0x01 ] # HRI barcode chars above
|
125
|
+
BARCODE_TXT_BLW = [ 0x1d, 0x48, 0x02 ] # HRI barcode chars below
|
126
|
+
BARCODE_TXT_BTH = [ 0x1d, 0x48, 0x03 ] # HRI barcode chars both above and below
|
127
|
+
BARCODE_FONT_A = [ 0x1d, 0x66, 0x00 ] # Font type A for HRI barcode chars
|
128
|
+
BARCODE_FONT_B = [ 0x1d, 0x66, 0x01 ] # Font type B for HRI barcode chars
|
129
|
+
BARCODE_HEIGHT = [ 0x1d, 0x68, 0x64 ] # Barcode Height = [1-255]
|
130
|
+
BARCODE_WIDTH = [ 0x1d, 0x77, 0x03 ] # Barcode Width = [2-6]
|
131
|
+
BARCODE_UPC_A = [ 0x1d, 0x6b, 0x00 ] # Barcode type UPC-A
|
132
|
+
BARCODE_UPC_E = [ 0x1d, 0x6b, 0x01 ] # Barcode type UPC-E
|
133
|
+
BARCODE_EAN13 = [ 0x1d, 0x6b, 0x02 ] # Barcode type EAN13
|
134
|
+
BARCODE_EAN8 = [ 0x1d, 0x6b, 0x03 ] # Barcode type EAN8
|
135
|
+
BARCODE_CODE39 = [ 0x1d, 0x6b, 0x04 ] # Barcode type CODE39
|
136
|
+
BARCODE_ITF = [ 0x1d, 0x6b, 0x05 ] # Barcode type ITF
|
137
|
+
BARCODE_NW7 = [ 0x1d, 0x6b, 0x06 ] # Barcode type NW7
|
138
|
+
|
139
|
+
# Font types
|
140
|
+
FONT_TYPE_BOLD = "B"
|
141
|
+
FONT_TYPE_UNDERLINE = "U"
|
142
|
+
FONT_TYPE_UNDERLINE_2 = "U2"
|
143
|
+
FONT_TYPE_BOLD_UNDERLINE = "BU"
|
144
|
+
FONT_TYPE_BOLD_UNDERLINE_2 = "BU2"
|
145
|
+
FONT_TYPE_NORMAL = "N"
|
146
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-escpos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frederick Lemire-Collu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby library to manipulate ESC/POS Printers
|
14
|
+
email: frederick@buildrevision.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ruby-escpos.rb
|
20
|
+
homepage: http://rubygems.org/gems/ruby-escpos
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Ruby ESC/POS
|
44
|
+
test_files: []
|