Class: Device::Print

Inherits:
Object
  • Object
show all
Defined in:
lib/device/print.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/print.rb', line 21

def self.adapter
  Device.adapter::Print
end

.checkObject

Check printer status, useful for paper check.



172
173
174
# File 'lib/device/print.rb', line 172

def self.check
  self._check
end

.closeNilClass

Closes the printer.

Returns:

  • (NilClass)

    Allways returns nil.



72
73
74
# File 'lib/device/print.rb', line 72

def self.close
  self.adapter.close
end

.font=(path) ⇒ Object

Selects print font.

Parameters:

  • filename (String)

    Font filename.



83
84
85
# File 'lib/device/print.rb', line 83

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.



100
101
102
# File 'lib/device/print.rb', line 100

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

.openFixnum

Check printer status, useful for paper check.

Returns:

  • (Fixnum)

    Return number.



58
59
60
# File 'lib/device/print.rb', line 58

def self.open
  self.adapter.open
end

.paper?TrueClass, FalseClass

Check if printer has paper

Returns:

  • (TrueClass)

    Has paper.

  • (FalseClass)

    No paper.



180
181
182
183
184
185
186
# File 'lib/device/print.rb', line 180

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

.paperfeedNilClass

Feeds printing paper.

Returns:

  • (NilClass)

    Allways returns nil.



127
128
129
# File 'lib/device/print.rb', line 127

def self.paperfeed
  self.adapter.feed
end

Write text on print buffer.

Parameters:

  • string (String)

    Text to be printed.

Returns:

  • (NilClass)

    Allways returns nil.



136
137
138
# File 'lib/device/print.rb', line 136

def self.print(string)
  self.adapter.print(string)
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.



160
161
162
# File 'lib/device/print.rb', line 160

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.



145
146
147
# File 'lib/device/print.rb', line 145

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.



65
66
67
# File 'lib/device/print.rb', line 65

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.



117
118
119
120
121
122
# File 'lib/device/print.rb', line 117

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.



43
44
45
46
47
48
# File 'lib/device/print.rb', line 43

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