Class: Device::Printer

Inherits:
Object
  • Object
show all
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 =
12
DEFAULT_SINGLE_HEIGHT =
24
DEFAULT_MULTI_WIDTH =
24
DEFAULT_MULTI_HEIGHT =
24

Class Method Summary collapse

Class Method Details

.adapterObject



21
22
23
# File 'lib/device/printer.rb', line 21

def self.adapter
  Device.adapter::Printer
end

.checkFixnum

Check printer status, useful for paper check.

Returns:

  • (Fixnum)

    RET_OK Success.

  • (Fixnum)

    ERR_FONT_NOT_EXIST Font does not exist.

  • (Fixnum)

    ERR_INVALID_PARAM Invalid parameter.

  • (Fixnum)

    ERR_PRN_BUSY Printer is busy.

  • (Fixnum)

    ERR_PRN_PAPEROUT Out of paper.

  • (Fixnum)

    ERR_PRN_OVERHEAT Printer overheating.



182
183
184
# File 'lib/device/printer.rb', line 182

def self.check
  self._check
end

.closeNilClass

Closes the printer.

Returns:

  • (NilClass)

    Allways returns nil.



70
71
72
# File 'lib/device/printer.rb', line 70

def self.close
  self.adapter.close
end

.font=(path) ⇒ Fixnum

Selects print font.

Parameters:

  • path (String)

    Font path.

Returns:

  • (Fixnum)

    RET_OK Success.

  • (Fixnum)

    ERR_FONT_NOT_EXIST Font does not exist.

  • (Fixnum)

    ERR_INVALID_PARAM Invalid parameter.



81
82
83
# File 'lib/device/printer.rb', line 81

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.

Parameters:

  • value (Fixnum)

    Value to define level

Returns:

  • (NilClass)

    Allways returns nil.



98
99
100
# File 'lib/device/printer.rb', line 98

def self.level=(value)
  self.adapter.level = value
end

.openFixnum

Check printer status, useful for paper check.

Returns:

  • (Fixnum)

    Return number.

  • (Fixnum)

    RET_OK Success.

  • (Fixnum)

    ERR_FONT_NOT_EXIST Font does not exist.

  • (Fixnum)

    ERR_INVALID_PARAM Invalid parameter.

  • (Fixnum)

    ERR_DEV_BUSY Device is busy.



56
57
58
# File 'lib/device/printer.rb', line 56

def self.open
  self.adapter.open
end

.paper?TrueClass, FalseClass

Check if printer has paper

Returns:

  • (TrueClass)

    Has paper.

  • (FalseClass)

    No paper.



190
191
192
193
194
195
196
# File 'lib/device/printer.rb', line 190

def self.paper?
  if self.check == ERR_PRN_PAPEROUT
    false
  else
    true
  end
end

.paperfeedNilClass

Feeds printing paper.

Returns:

  • (NilClass)

    Allways returns nil.



125
126
127
# File 'lib/device/printer.rb', line 125

def self.paperfeed
  self.adapter.feed
end

Write text on print buffer.

Parameters:

  • string (String)

    Text to be printed.

Returns:

  • (NilClass)

    Allways returns nil.



134
135
136
# File 'lib/device/printer.rb', line 134

def self.print(string)
  self.adapter.print(string)
end

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

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

Parameters:

  • string (String)

    Text to be printed.

Returns:

  • (NilClass)

    Allways returns nil.



153
154
155
156
157
# File 'lib/device/printer.rb', line 153

def self.print_big(string)
  size(24, 48, 48, 48)
  self.adapter.print(string)
  size
end

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.

Parameters:

  • path (String)

    Path to bmp file.

Returns:

  • (NilClass)

    Allways returns nil.



170
171
172
# File 'lib/device/printer.rb', line 170

def self.print_bmp(path)
  self.adapter.print_bmp(path)
end

.puts(string) ⇒ NilClass

Write text on print buffer.

Parameters:

  • string (String)

    Text to be printed.

Returns:

  • (NilClass)

    Allways returns nil.



143
144
145
# File 'lib/device/printer.rb', line 143

def self.puts(string)
  self.adapter.puts(string)
end

.resetNilClass

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

Returns:

  • (NilClass)

    Allways returns nil.



63
64
65
# File 'lib/device/printer.rb', line 63

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.

Parameters:

  • singlecode_width (Fixnum) (defaults to: DEFAULT_SINGLE_WIDTH)

    The width control of single code font.

  • singlecode_height (Fixnum) (defaults to: DEFAULT_SINGLE_HEIGHT)

    The height control of single code font. The value ranges from 8 to 64.

  • multicode_width (Fixnum) (defaults to: DEFAULT_MULTI_WIDTH)

    The width control of multiple code font. The value ranges from 12 to 64.

  • multicode_height (Fixnum) (defaults to: DEFAULT_MULTI_HEIGHT)

    The height control of multiple code font The value ranges from 12 to 64.

Returns:

  • (NilClass)

    Allways returns nil.



115
116
117
118
119
120
# File 'lib/device/printer.rb', line 115

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.

Parameters:

  • singlecode_width (Fixnum) (defaults to: DEFAULT_SINGLE_WIDTH)

    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.

  • singlecode_height (Fixnum) (defaults to: DEFAULT_SINGLE_HEIGHT)

    The height control of single code font. The value ranges from 8 to 64.

  • multicode_width (Fixnum) (defaults to: DEFAULT_MULTI_WIDTH)

    The width control of multiple code font. The value ranges from 12 to 64.

  • multicode_height (Fixnum) (defaults to: DEFAULT_MULTI_HEIGHT)

    The height control of multiple code font The value ranges from 12 to 64.

Returns:

  • (Fixnum)

    Return number.

  • (Fixnum)

    RET_OK Success.

  • (Fixnum)

    ERR_FONT_NOT_EXIST Font does not exist.

  • (Fixnum)

    ERR_INVALID_PARAM Invalid parameter.

  • (Fixnum)

    ERR_DEV_BUSY Device is busy.



42
43
44
45
46
47
# File 'lib/device/printer.rb', line 42

def self.start(singlecode_width=DEFAULT_SINGLE_WIDTH,
               singlecode_height=DEFAULT_SINGLE_HEIGHT,
               multicode_width=DEFAULT_MULTI_WIDTH,
               multicode_height=DEFAULT_MULTI_HEIGHT)
  self.adapter.start(singlecode_width, singlecode_height, multicode_width, multicode_height)
end