class Device::Printer

Constants

BMP_FILE_ERROR
BMP_INVALID_WIDTH
BMP_LSEEK_FAILED
BMP_NOT_MONOCHROME
BMP_SUCCESS
DEFAULT_MULTI_HEIGHT
DEFAULT_MULTI_WIDTH
DEFAULT_SINGLE_HEIGHT
DEFAULT_SINGLE_WIDTH
ERR_DEV_BUSY
ERR_DEV_NOT_EXIST
ERR_FONT_NOT_EXIST
ERR_INVALID_PARAM
ERR_PRN_BUSY
ERR_PRN_OUTOFMEMORY
ERR_PRN_OVERHEAT
ERR_PRN_OVERVOLTAGE
ERR_PRN_PAPEROUT
ERR_PRN_WRONG_PACKAGE
RET_OK

Attributes

multi_height[RW]
multi_width[RW]
single_height[RW]
single_width[RW]

Public Class Methods

adapter() click to toggle source
# File lib/device/printer.rb, line 27
def self.adapter
  Device.adapter::Printer
end
check() click to toggle source

Check printer status, useful for paper check.

@return [Fixnum] RET_OK Success. @return [Fixnum] ERR_FONT_NOT_EXIST Font does not exist. @return [Fixnum] ERR_INVALID_PARAM Invalid parameter. @return [Fixnum] ERR_PRN_BUSY Printer is busy. @return [Fixnum] ERR_PRN_PAPEROUT Out of paper. @return [Fixnum] ERR_PRN_OVERHEAT Printer overheating.

# File lib/device/printer.rb, line 208
def self.check
  self.adapter.check
end
close() click to toggle source

Closes the printer.

@return [NilClass] Allways returns nil.

# File lib/device/printer.rb, line 86
def self.close
  self.adapter.close
end
font(path) click to toggle source

Selects print font.

@param path [String] Font path.

@return [Fixnum] RET_OK Success. @return [Fixnum] ERR_FONT_NOT_EXIST Font does not exist. @return [Fixnum] ERR_INVALID_PARAM Invalid parameter.

# File lib/device/printer.rb, line 97
def self.font(path)
  self.adapter.font(path)
end
level=(value) click to toggle source

Sets printing gray level.

@param value [Fixnum] Value to define 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.

@return [NilClass] Allways returns nil.

# File lib/device/printer.rb, line 114
def self.level=(value)
  self.adapter.level = value
end
open() click to toggle source

Check printer status, useful for paper check.

@return [Fixnum] Return number. @return [Fixnum] RET_OK Success. @return [Fixnum] ERR_FONT_NOT_EXIST Font does not exist. @return [Fixnum] ERR_INVALID_PARAM Invalid parameter. @return [Fixnum] ERR_DEV_BUSY Device is busy.

# File lib/device/printer.rb, line 72
def self.open
  self.adapter.open
end
paper?() click to toggle source

Check if printer has paper

@return [TrueClass] Has paper. @return [FalseClass] No paper.

# File lib/device/printer.rb, line 216
def self.paper?
  if self.check == ERR_PRN_PAPEROUT
    false
  else
    true
  end
end
paperfeed() click to toggle source

Feeds printing paper.

@return [NilClass] Allways returns nil.

# File lib/device/printer.rb, line 141
def self.paperfeed
  self.adapter.feed
end
print(string) click to toggle source

Write text on print buffer.

@param string [String] Text to be printed.

@return [NilClass] Allways returns nil.

print_barcode(code) click to toggle source

Print barcode as bmp image

@param code [String] barcode number

@return [Integer] 0 Success @return [Integer] -1 Fail

print_big(string) click to toggle source

Write text on print buffer changing the size only for this print.

Big size is  (24, 64, 64, 64)

@param string [String] Text to be printed.

@return [NilClass] Allways returns nil.

print_bmp(path) click to toggle source

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.

@param path [String] Path to bmp file.

@return [Integer] 0 success.

puts(string) click to toggle source

Write text on print buffer.

@param string [String] Text to be printed.

@return [NilClass] Allways returns nil.

# File lib/device/printer.rb, line 160
def self.puts(string)
  self.adapter.puts(string)
end
reset() click to toggle source

Restore the printer default settings and clear the print buffer data.

@return [NilClass] Allways returns nil.

# 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) click to toggle source

Define size, in pixel, of printing

@param singlecode_width [Fixnum] The width control of single code font. (For non-monospaced font, width of each character may not meet the settings).

The value ranges from 8 to 64.

@param singlecode_height [Fixnum] The height control of single code font.

The value ranges from 8 to 64.

@param multicode_width [Fixnum] The width control of multiple code font.

The value ranges from 12 to 64.

@param multicode_height [Fixnum] The height control of multiple code font

The value ranges from 12 to 64.

@return [NilClass] Allways returns nil.

# 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) click to toggle source

Initialize Printer device.

@param singlecode_width [Fixnum] The width control of single code font.

(For non-monospaced font, width of each character may not meet the settings).
The value ranges from 8 to 64.

@param singlecode_height [Fixnum] The height control of single code font.

The value ranges from 8 to 64.

@param multicode_width [Fixnum] The width control of multiple code font.

The value ranges from 12 to 64.

@param multicode_height [Fixnum] The height control of multiple code font

The value ranges from 12 to 64.

@return [Fixnum] Return number. @return [Fixnum] RET_OK Success. @return [Fixnum] ERR_FONT_NOT_EXIST Font does not exist. @return [Fixnum] ERR_INVALID_PARAM Invalid parameter. @return [Fixnum] ERR_DEV_BUSY Device is busy.

# 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