Class: Device::Printer
- Inherits:
-
Object
- Object
- Device::Printer
- Defined in:
- lib/device/printer.rb
Constant Summary collapse
- RET_OK =
0
- ERR_PRN_BUSY =
Printer busy
-3701 # Printer busy
- ERR_PRN_PAPEROUT =
Out of paper
-3702 # Out of paper
- ERR_PRN_WRONG_PACKAGE =
The format of print data packet error
-3703 # The format of print data packet error
- ERR_PRN_OVERHEAT =
Printer over heating
-3704 # Printer over heating
- ERR_PRN_OUTOFMEMORY =
The print data is too large, and exceeds the buffer length.
-3705 # The print data is too large, and exceeds the buffer length.
- ERR_PRN_OVERVOLTAGE =
Voltage is too high.
-3706 # Voltage is too high.
- ERR_INVALID_PARAM =
Invalid parameter.
-1003 # Invalid parameter.
- ERR_DEV_NOT_EXIST =
Device does not exist.
-1004 # Device does not exist.
- ERR_DEV_BUSY =
Device is busy.
-1005 # Device is busy.
- ERR_FONT_NOT_EXIST =
Font does not exist.
-1008 # Font does not exist.
- DEFAULT_SINGLE_WIDTH =
10
- DEFAULT_SINGLE_HEIGHT =
21
- DEFAULT_MULTI_WIDTH =
10
- DEFAULT_MULTI_HEIGHT =
21
- BMP_SUCCESS =
0
- BMP_FILE_ERROR =
-1
- BMP_NOT_MONOCHROME =
-3
- BMP_INVALID_WIDTH =
-4
- BMP_LSEEK_FAILED =
-5
Class Attribute Summary collapse
-
.multi_height ⇒ Object
Returns the value of attribute multi_height.
-
.multi_width ⇒ Object
Returns the value of attribute multi_width.
-
.single_height ⇒ Object
Returns the value of attribute single_height.
-
.single_width ⇒ Object
Returns the value of attribute single_width.
Class Method Summary collapse
- .adapter ⇒ Object
-
.check ⇒ Fixnum
Check printer status, useful for paper check.
-
.close ⇒ NilClass
Closes the printer.
-
.font(path) ⇒ Fixnum
Selects print font.
-
.level=(value) ⇒ NilClass
Sets printing gray level.
-
.open ⇒ Fixnum
Check printer status, useful for paper check.
-
.paper? ⇒ TrueClass, FalseClass
Check if printer has paper.
-
.paperfeed ⇒ NilClass
Feeds printing paper.
-
.print(string) ⇒ NilClass
Write text on print buffer.
-
.print_barcode(code) ⇒ Integer
Print barcode as bmp image.
-
.print_big(string) ⇒ NilClass
Write text on print buffer changing the size only for this print.
-
.print_bmp(path) ⇒ Integer
Print bmp file.
-
.puts(string) ⇒ NilClass
Write text on print buffer.
-
.reset ⇒ NilClass
Restore the printer default settings and clear the print buffer data.
-
.size(singlecode_width = DEFAULT_SINGLE_WIDTH, singlecode_height = DEFAULT_SINGLE_HEIGHT, multicode_width = DEFAULT_MULTI_WIDTH, multicode_height = DEFAULT_MULTI_HEIGHT) ⇒ NilClass
Define size, in pixel, of printing.
-
.start(singlecode_width = DEFAULT_SINGLE_WIDTH, singlecode_height = DEFAULT_SINGLE_HEIGHT, multicode_width = DEFAULT_MULTI_WIDTH, multicode_height = DEFAULT_MULTI_HEIGHT) ⇒ Fixnum
Initialize Printer device.
Class Attribute Details
.multi_height ⇒ Object
Returns the value of attribute multi_height.
32 33 34 |
# File 'lib/device/printer.rb', line 32 def multi_height @multi_height end |
.multi_width ⇒ Object
Returns the value of attribute multi_width.
32 33 34 |
# File 'lib/device/printer.rb', line 32 def multi_width @multi_width end |
.single_height ⇒ Object
Returns the value of attribute single_height.
32 33 34 |
# File 'lib/device/printer.rb', line 32 def single_height @single_height end |
.single_width ⇒ Object
Returns the value of attribute single_width.
32 33 34 |
# File 'lib/device/printer.rb', line 32 def single_width @single_width end |
Class Method Details
.adapter ⇒ Object
27 28 29 |
# File 'lib/device/printer.rb', line 27 def self.adapter Device.adapter::Printer end |
.check ⇒ Fixnum
Check printer status, useful for paper check.
208 209 210 |
# File 'lib/device/printer.rb', line 208 def self.check self.adapter.check end |
.close ⇒ NilClass
Closes the printer.
86 87 88 |
# File 'lib/device/printer.rb', line 86 def self.close self.adapter.close end |
.font(path) ⇒ Fixnum
Selects print font.
97 98 99 |
# File 'lib/device/printer.rb', line 97 def self.font(path) self.adapter.font(path) end |
.level=(value) ⇒ NilClass
Sets printing gray level.
Level =0, reserved, Level =1, default level, normal print slip, Level =2, reserved, Level =3, two-layer thermal printing, Level =4, two-layer thermal printing, higher gray level than 3, The default level is 1. The illegal value does not change current settings.
114 115 116 |
# File 'lib/device/printer.rb', line 114 def self.level=(value) self.adapter.level = value end |
.open ⇒ Fixnum
Check printer status, useful for paper check.
72 73 74 |
# File 'lib/device/printer.rb', line 72 def self.open self.adapter.open end |
.paper? ⇒ TrueClass, FalseClass
Check if printer has paper
216 217 218 219 220 221 222 |
# File 'lib/device/printer.rb', line 216 def self.paper? if self.check == ERR_PRN_PAPEROUT false else true end end |
.paperfeed ⇒ NilClass
Feeds printing paper.
141 142 143 |
# File 'lib/device/printer.rb', line 141 def self.paperfeed self.adapter.feed end |
.print(string) ⇒ NilClass
Write text on print buffer.
150 151 152 153 |
# File 'lib/device/printer.rb', line 150 def self.print(string) self.size(self.single_width, self.single_height, self.multi_width, self.multi_height) self.adapter.print(string) end |
.print_barcode(code) ⇒ Integer
Print barcode as bmp image
196 197 198 |
# File 'lib/device/printer.rb', line 196 def self.(code) self.adapter.(code) end |
.print_big(string) ⇒ NilClass
Write text on print buffer changing the size only for this print.
Big size is (24, 64, 64, 64)
170 171 172 173 |
# File 'lib/device/printer.rb', line 170 def self.print_big(string) self.size(16, 32, 16, 32) self.adapter.print(string) end |
.print_bmp(path) ⇒ Integer
Print bmp file.
Details: Bitmap data is generated as monochromatic, bmp format. Printing bitmap size limit up to 384 pixels in width, spocket with 180 pixels and the height is unlimited. If the bitmap width is larger than the limit of the printer, then it will be sliced on the right side. If the data packet is too long, then this function will remove the LOGO message.
186 187 188 |
# File 'lib/device/printer.rb', line 186 def self.print_bmp(path) self.adapter.print_bmp(path) end |
.puts(string) ⇒ NilClass
Write text on print buffer.
160 161 162 |
# File 'lib/device/printer.rb', line 160 def self.puts(string) self.adapter.puts(string) end |
.reset ⇒ NilClass
Restore the printer default settings and clear the print buffer data.
79 80 81 |
# File 'lib/device/printer.rb', line 79 def self.reset self.adapter.reset end |
.size(singlecode_width = DEFAULT_SINGLE_WIDTH, singlecode_height = DEFAULT_SINGLE_HEIGHT, multicode_width = DEFAULT_MULTI_WIDTH, multicode_height = DEFAULT_MULTI_HEIGHT) ⇒ NilClass
Define size, in pixel, of printing
(For non-monospaced font, width of each character may not meet the settings).
The value ranges from 8 to 64.
131 132 133 134 135 136 |
# File 'lib/device/printer.rb', line 131 def self.size(singlecode_width=DEFAULT_SINGLE_WIDTH, singlecode_height=DEFAULT_SINGLE_HEIGHT, multicode_width=DEFAULT_MULTI_WIDTH, multicode_height=DEFAULT_MULTI_HEIGHT) self.adapter.size(singlecode_width, singlecode_height, multicode_width, multicode_height) end |
.start(singlecode_width = DEFAULT_SINGLE_WIDTH, singlecode_height = DEFAULT_SINGLE_HEIGHT, multicode_width = DEFAULT_MULTI_WIDTH, multicode_height = DEFAULT_MULTI_HEIGHT) ⇒ Fixnum
Initialize Printer device.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/device/printer.rb', line 52 def self.start(singlecode_width=DEFAULT_SINGLE_WIDTH, singlecode_height=DEFAULT_SINGLE_HEIGHT, multicode_width=DEFAULT_MULTI_WIDTH, multicode_height=DEFAULT_MULTI_HEIGHT) self.single_width = singlecode_width self.single_height = singlecode_height self.multi_width = multicode_width self.multi_height = multicode_height self.adapter.start(singlecode_width, singlecode_height, multicode_width, multicode_height) end |