class Memopri::Printer
Public Class Methods
new(host, port=16402)
click to toggle source
# File lib/memopri/printer.rb, line 8 def initialize(host, port=16402) @hostname = host @port = port @socket = TCPSocket.open(@hostname, @port) end
Public Instance Methods
_recv(len)
click to toggle source
# File lib/memopri/printer.rb, line 20 def _recv(len) return @socket.read(len) end
_send(cmd)
click to toggle source
# File lib/memopri/printer.rb, line 14 def _send(cmd) cmd = cmd.pack('C*') @socket.write(cmd) @socket.flush() end
print(data)
click to toggle source
# File lib/memopri/printer.rb, line 24 def print(data) cmd = [0x1b, 0x5a] _send(cmd) _recv(1) cmd = [0x05] _send(cmd) _recv(6) cmd = [0x06] _send(cmd) _recv(1) cmd = [0x1b, 0x49] _send(cmd) _recv(1) cmd = [0x05] _send(cmd) _recv(8) cmd = [0x06] _send(cmd) _recv(1) cmd = [0x1b, 0x50] _send(cmd) _recv(1) length = data.size cmd = [ 0x02, 0x80, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, (length/16) & 0x00FF, ((length/16) >> 8) & 0x00FF, (length) & 0x00FF, ((length) >> 8) & 0x00FF, 0x00, 0x00, ] _send(cmd) _recv(1) cmd = [0x1b, 0x56] _send(cmd) _recv(1) data.each_slice(64){|x| _send(x) _recv(1) } cmd = [0x1b, 0x42] _send(cmd) _recv(1) end