thermalp 1.1.1
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/Printer.rb +245 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 50844b59efd2bca81a922ac4965755cf935f794e
|
|
4
|
+
data.tar.gz: f3e61d9b055f8fac5b57ddb7e784b180edb602d2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d3df12115a40cf9794f04ed01a233e0349f1ee0abc9c78cd7cecc72281bf5a4bf1a6496363866a62910582e7b0d2100b665a6ff547de5e28d60a7993abea8c15
|
|
7
|
+
data.tar.gz: 3e97513c316d5dbb3258664bfebd57bed09ba42a8c627ec216d527a3c47ee07f038de24481b00d882ae67b6e2354950c03852607c79fc534c076a75310545378
|
data/lib/Printer.rb
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
class Printer
|
|
2
|
+
require 'thread'
|
|
3
|
+
require 'socket'
|
|
4
|
+
require 'timeout'
|
|
5
|
+
|
|
6
|
+
#printer IP adress
|
|
7
|
+
@ip
|
|
8
|
+
|
|
9
|
+
# printer port, defaults to 9100
|
|
10
|
+
@port
|
|
11
|
+
|
|
12
|
+
# auto_flush = true ---> sends instruction by instruction
|
|
13
|
+
# default -> true
|
|
14
|
+
@auto_flush
|
|
15
|
+
|
|
16
|
+
# Queue of instructions
|
|
17
|
+
@queue
|
|
18
|
+
|
|
19
|
+
# constructor initializes printers basic info
|
|
20
|
+
#
|
|
21
|
+
# Parameters:
|
|
22
|
+
# ip: printer's IP address
|
|
23
|
+
# port: printer's listening port, default -> 9100
|
|
24
|
+
# auto_flush: boolean value to determine if should immediately send instructions to printer
|
|
25
|
+
# or saves in buffer and flush them later
|
|
26
|
+
# default -> true
|
|
27
|
+
def initialize(ip, port="9100", auto_flush=true)
|
|
28
|
+
@ip = ip
|
|
29
|
+
@port = port
|
|
30
|
+
@queue = Queue.new
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Sets label dimensions in mm
|
|
34
|
+
#
|
|
35
|
+
# Parameters:
|
|
36
|
+
# width: label width (in mm)
|
|
37
|
+
# height: label height
|
|
38
|
+
# unit: width unit (mm, inch, dot), default -> inch
|
|
39
|
+
def set_label_dimensions width, height, unit = ""
|
|
40
|
+
instruction ("SIZE " + width.to_s + " " + unit.to_s + ", " + height.to_s + " " + unit.to_s)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Set printing direction (Choose one of the Predefined directions in DIrection.rb)
|
|
44
|
+
#
|
|
45
|
+
# Parameters:
|
|
46
|
+
# is_top_to_bottom: Boolean determines whether printing direction is top to bottom or bottom to up (from the printer's prespective)
|
|
47
|
+
# is_mirrored: Boolean specifies if text should be printed mirrored (not human readable)
|
|
48
|
+
def set_printing_direction is_top_to_bottom, is_mirrored
|
|
49
|
+
direction = ""
|
|
50
|
+
if is_top_to_bottom
|
|
51
|
+
direction += "0"
|
|
52
|
+
else
|
|
53
|
+
direction += "1"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
direction += ","
|
|
57
|
+
|
|
58
|
+
if is_mirrored
|
|
59
|
+
direction += "1"
|
|
60
|
+
else
|
|
61
|
+
direction += "0"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
instruction ("DIRECTION " + direction)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Specify the printed text denisty
|
|
68
|
+
#
|
|
69
|
+
# Parameters:
|
|
70
|
+
# darkness: 0..15
|
|
71
|
+
# 0: specifies the lightest level
|
|
72
|
+
# 15: specifies the darkest level
|
|
73
|
+
def set_printing_darkness darkness = 8
|
|
74
|
+
instruction ("DENSITY " + darkness.to_s)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Set gap between labels (the empty area between two labels)
|
|
78
|
+
#
|
|
79
|
+
# Parameters:
|
|
80
|
+
# distance: Float value determines the gap between two labels
|
|
81
|
+
# offset: The offset distance of the gab, default -> 0
|
|
82
|
+
# unit: unit of gap amount (mm, inch, dot), default -> inch
|
|
83
|
+
def set_gap distance, offset = 0, unit = ""
|
|
84
|
+
instruction ("GAP " + distance.to_s + " " + unit.to_s + ", " + offset.to_s + " " + unit.to_s)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Enforce printer to re-callibrate to detect gap size
|
|
88
|
+
# This command is executed immediately and ignores "auto_flush" value
|
|
89
|
+
def callibrate
|
|
90
|
+
send_instruction "GAPDETECT"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Writes specified text (in content param)
|
|
94
|
+
#
|
|
95
|
+
# Parameters:
|
|
96
|
+
# x: The x-coordinate of the text
|
|
97
|
+
#
|
|
98
|
+
# y: The y-coordinate of the text
|
|
99
|
+
#
|
|
100
|
+
# font: String represents font name
|
|
101
|
+
# 0: Monotye CG Triumvirate Bold Condensed, font width and height is stretchable
|
|
102
|
+
# 1: 8 x 12 fixed pitch dot font
|
|
103
|
+
# 2: 12 x 20 fixed pitch dot font
|
|
104
|
+
# 3: 16 x 24 fixed pitch dot font
|
|
105
|
+
# 4: 24 x 32 fixed pitch dot font
|
|
106
|
+
# 5: 32 x 48 dot fixed pitch font
|
|
107
|
+
# 6: 14 x 19 dot fixed pitch font OCR-B
|
|
108
|
+
# 7: 21 x 27 dot fixed pitch font OCR-B
|
|
109
|
+
# 8: 14 x25 dot fixed pitch font OCR-A
|
|
110
|
+
# ROMAN.TTF: Monotye CG Triumvirate Bold Condensed, font width and height proportion is fixed.
|
|
111
|
+
#
|
|
112
|
+
# rotation: Integer for the rotation angle of text, accepted values:
|
|
113
|
+
# 0: No rotation
|
|
114
|
+
# 90: degrees, in clockwise direction
|
|
115
|
+
# 180: degrees, in clockwise direction
|
|
116
|
+
# 270: degrees, in clockwise direction
|
|
117
|
+
#
|
|
118
|
+
# x_multiplication: Float value for horizontal multiplication, up to 10x, Acceptable values: 1~10
|
|
119
|
+
# For "ROMAN.TTF" true type font, this parameter is ignored.
|
|
120
|
+
# For font "0", this parameter is used to specify the width (point) of true type
|
|
121
|
+
# font. 1 point=1/72 inch.
|
|
122
|
+
#
|
|
123
|
+
# y_multiplication: Vertical multiplication, up to 10x
|
|
124
|
+
# Available factors: 1~10
|
|
125
|
+
# For true type font, this parameter is used to specify the height (point) of
|
|
126
|
+
# true type font. 1 point=1/72 inch.
|
|
127
|
+
# For *.TTF font, x-multiplication and y-multiplication support floating value. (V6.91 EZ)
|
|
128
|
+
#
|
|
129
|
+
# alignment: Optional. Specify the alignment of text. (V6.73 EZ)
|
|
130
|
+
# 0 : Default (Left)
|
|
131
|
+
# 1 : Left
|
|
132
|
+
# 2 : Center
|
|
133
|
+
# 3 : Right
|
|
134
|
+
#
|
|
135
|
+
# content: Content of text string
|
|
136
|
+
def text x, y, font = "0", rotation, x_multiplication, y_multiplication, alignment, content
|
|
137
|
+
instruction ('TEXT ' + x.to_s + ', ' + y.to_s + ', "' + font.to_s + '", ' + rotation.to_s + ', ' + x_multiplication.to_s + ', ' + y_multiplication.to_s + ', ' + alignment.to_s + ', "' + content.to_s + '"')
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Writes barcode
|
|
141
|
+
#
|
|
142
|
+
# Parameters:
|
|
143
|
+
# x: The x-coordinate of the barcode
|
|
144
|
+
#
|
|
145
|
+
# y: The y-coordinate of the barcode
|
|
146
|
+
#
|
|
147
|
+
# type: String specifying barcode type, accepted values:
|
|
148
|
+
# 128, 128M, EAN128, 25, 25C, 39, 39C, 93, EAN13, EAN13+2, EAN13+5, EAN8, EAN8+2, EAN8+5, CODA, POST, UPCA, UPCA+2, UPA+5, UPCE, UPCE+2, UPE+5, MSI, MSIC, PLESSEY, CPOST, ITF14, EAN14, 11, TELEPEN, TELEPENN, PLANET, CODE49, DPI, DPL, LOGMARS
|
|
149
|
+
#
|
|
150
|
+
# height: Barcode height (in dots)
|
|
151
|
+
#
|
|
152
|
+
# human_readable: human readability and alignment, accepted values:
|
|
153
|
+
# 0: not readable
|
|
154
|
+
# 1: human readable aligns to left
|
|
155
|
+
# 2: human readable aligns to center
|
|
156
|
+
# 3: human readable aligns to right
|
|
157
|
+
#
|
|
158
|
+
# rotation: Barcode rotation, accepted values:
|
|
159
|
+
# 0 : No rotation
|
|
160
|
+
# 90 : Rotate 90 degrees clockwise
|
|
161
|
+
# 180 : Rotate 180 degrees clockwise
|
|
162
|
+
# 270 : Rotate 270 degrees clockwise
|
|
163
|
+
#
|
|
164
|
+
# narrow: Width of narrow element (in dots)
|
|
165
|
+
#
|
|
166
|
+
# wide: Width of wide element (in dots)
|
|
167
|
+
#
|
|
168
|
+
# alignment: Specify the alignment of barcode, accepted values:
|
|
169
|
+
# 0 : default (Left)
|
|
170
|
+
# 1 : Left
|
|
171
|
+
# 2 : Center
|
|
172
|
+
# 3 : Right
|
|
173
|
+
#
|
|
174
|
+
# content: String containing content of barcode
|
|
175
|
+
#
|
|
176
|
+
def barcode x, y, type, height, human_readable, rotation, narrow, wide, alignment=0, content
|
|
177
|
+
instruction ('BARCODE ' + x.to_s + ', ' + y.to_s + ', "' + type.to_s + '", ' + height.to_s + ', ' + human_readable.to_s + ', ' + rotation.to_s + ', ' + narrow.to_s + ', ' + wide.to_s + ', ' + alignment.to_s + ', "' + content.to_s + '"')
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Sends the printing command to the printer. This method must be called at the end of any command sequence, if not printer will not print anything
|
|
181
|
+
def print number_of_copies = "1"
|
|
182
|
+
instruction ("PRINT 1," + number_of_copies.to_s)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def get_instructions_queue
|
|
186
|
+
return nil if @queue.empty?
|
|
187
|
+
return @queue
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
private
|
|
191
|
+
# Sends the instruction directly to printer if and only if auto_flush is true
|
|
192
|
+
# Otherwise it saves it in printing buffer
|
|
193
|
+
#
|
|
194
|
+
# Parameters:
|
|
195
|
+
# instruction_string: String containing single instruction
|
|
196
|
+
def instruction instruction_string
|
|
197
|
+
if @auto_flush
|
|
198
|
+
send_instruction instruction_string
|
|
199
|
+
else
|
|
200
|
+
@queue << instruction_string
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# Sends Single instruction to printer
|
|
205
|
+
#
|
|
206
|
+
# Raises Timeout::Error if couldn't connect to printer for 5 seconds
|
|
207
|
+
#
|
|
208
|
+
# Parameters:
|
|
209
|
+
# single_instruction: String containing a single instruction
|
|
210
|
+
def send_instruction single_instruction
|
|
211
|
+
timeout(5) do
|
|
212
|
+
# open socket on printer's ip and port
|
|
213
|
+
socket = TCPSocket.open(@ip, @port)
|
|
214
|
+
|
|
215
|
+
# send instruction
|
|
216
|
+
socket.puts single_instruction
|
|
217
|
+
|
|
218
|
+
# close socket
|
|
219
|
+
socket.close
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
# Flush all buffered instructions (stored in @queue) in order
|
|
225
|
+
def flush
|
|
226
|
+
if @queue.empty?
|
|
227
|
+
return self
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
timeout(10) do
|
|
231
|
+
# open socket on printer's ip and port
|
|
232
|
+
socket = TCPSocket.open(@ip, @port)
|
|
233
|
+
|
|
234
|
+
# send instructions one by one
|
|
235
|
+
socket.puts single_instruction
|
|
236
|
+
|
|
237
|
+
while !@queue.empty? do
|
|
238
|
+
socket.puts @queue.pop(true)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# close socket
|
|
242
|
+
socket.close
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: thermalp
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Mohamed Kamal
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Thermal and/or barcode printers kit for printers connected over NETWORK
|
|
14
|
+
only, this gem DOES NOT WORK for USB connected printers
|
|
15
|
+
email: arshimido@hotmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/Printer.rb
|
|
21
|
+
homepage: https://github.com/mohamed-kamal/thermalp
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - '>='
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.0.3
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: Thermal and/or barcode printers kit for NETWORK connected printers
|
|
45
|
+
test_files: []
|
|
46
|
+
has_rdoc:
|