Class: Rescpos::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/rescpos/printer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip, port) ⇒ Printer

Returns a new instance of Printer.



5
6
7
8
# File 'lib/rescpos/printer.rb', line 5

def initialize(ip, port)
  @socket = TCPSocket.open(ip, port)
  @socket.send("\x1b\x40", Socket::MSG_OOB)
end

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



3
4
5
# File 'lib/rescpos/printer.rb', line 3

def socket
  @socket
end

Class Method Details

.open(ip, port) ⇒ Object



10
11
12
# File 'lib/rescpos/printer.rb', line 10

def self.open(ip, port)
  printer = new(ip, port)
end

Instance Method Details

#closeObject



14
15
16
# File 'lib/rescpos/printer.rb', line 14

def close
  @socket.close
end


18
19
20
21
22
# File 'lib/rescpos/printer.rb', line 18

def print(content, opts={:encoding => 'GBK'})
  content = Iconv.iconv("#{opts[:encoding]}//IGNORE","UTF-8//IGNORE", content)[0]
  @socket.send(content, Socket::MSG_OOB)
  cut
end


24
25
26
# File 'lib/rescpos/printer.rb', line 24

def print_report(report, opts={})
  print(report.render, opts)
end