Module: BrotherEscp::Sequence
- Defined in:
- lib/brother_escp/sequence.rb
Overview
This module take care of the commands and various esc sequences to send meta data to the printer
Constant Summary collapse
- SEQUENCES =
predefined sequence of commands for the printer
{ # Printer hardware HW_INIT: [0x1b, 0x40], # Clear data in buffer and reset modes HW_SET_ESCP_MODE: [0x1B, 0x69, 0x61, 0x00], # Sets the command mode to ESC/P # Select landscape orientation LANDSCAPE_ON: [0x1b, 0x69, 0x4c, 1], LANDSCAPE_OFF: [0x1b, 0x69, 0x4c, 0], # Line feed commands LINE_FEED: [0x1b, 0x33], # Specify page length PAGE_LENGTH: [0x1b, 0x28, 0x43, 2, 0], # Feed control sequences CTL_LF: [0x0a], # Print and line feed CTL_FF: [0x0c], # Form feed CTL_CR: [0x0d], # Carriage return CTL_HT: [0x09], # Horizontal tab CTL_VT: [0x0b], # Vertical tab }.freeze
Class Method Summary collapse
-
.crlf ⇒ Object
helper method to issue a carriage return / line feed sequence (go to the next line).
-
.line_feed_size(n) ⇒ Object
Helper method to set the line feed size.
-
.page_length(n) ⇒ Object
Helper method to set the page length.
-
.sequence(value) ⇒ Object
Format a sequence to the raw data needed by the printer.
Class Method Details
.crlf ⇒ Object
helper method to issue a carriage return / line feed sequence (go to the next line)
41 42 43 |
# File 'lib/brother_escp/sequence.rb', line 41 def crlf sequence [0x0d, 0x0a] end |
.line_feed_size(n) ⇒ Object
Helper method to set the line feed size
47 48 49 |
# File 'lib/brother_escp/sequence.rb', line 47 def line_feed_size(n) sequence(:LINE_FEED) + sequence(n) end |
.page_length(n) ⇒ Object
Helper method to set the page length
53 54 55 |
# File 'lib/brother_escp/sequence.rb', line 53 def page_length(n) sequence(:PAGE_LENGTH) + sequence([n % 256, n / 256]) end |
.sequence(value) ⇒ Object
Format a sequence to the raw data needed by the printer
34 35 36 37 38 |
# File 'lib/brother_escp/sequence.rb', line 34 def sequence(value) val = value.is_a?(Symbol) ? SEQUENCES[value] : value Array(val).pack('C*') end |