class StarEthernet::Printer

Attributes

host[R]
status[R]

Public Class Methods

new(host) click to toggle source
# File lib/star_ethernet/printer.rb, line 12
def initialize(host)
  @host = host
  @status = StarEthernet::Status.new(self)
end

Public Instance Methods

current_status() click to toggle source
# File lib/star_ethernet/printer.rb, line 96
def current_status
  @status.current_status
end
fetch_status(purpose = '') click to toggle source
# File lib/star_ethernet/printer.rb, line 78
def fetch_status(purpose = '')
  begin
    socket = socket(StarEthernet.configuration.status_acquisition_port)
    socket.print(StarEthernet::Command.status_acquisition)
    asb_status = socket.read(StarEthernet.configuration.asb_status_size)
    @status.set_status(asb_status, purpose)
    socket.close
    @status.current_status
  rescue => e
      raise StarEthernet::StatusFetchFailed.new(e.full_message)
    end
end
print(data) click to toggle source
reboot() click to toggle source
# File lib/star_ethernet/printer.rb, line 91
def reboot
  telnet.cmd('String' => '98', 'Match' => /(.)*Selection: /)
  telnet.cmd('String' => '2', 'Match' => /(.)*Selection: /)
end
send_command(data) click to toggle source
# File lib/star_ethernet/printer.rb, line 68
def send_command(data)
  socket = socket(StarEthernet.configuration.raw_socket_print_port)
  if StarEthernet.configuration.nsb
    nbs_status = socket.read(StarEthernet.configuration.asb_status_size)
    @status.set_status(nbs_status)
  end
  socket.print(data)
  socket.close
end
set_custom_socket(&socket) click to toggle source
# File lib/star_ethernet/printer.rb, line 106
def set_custom_socket(&socket)
  @custom_socket = socket
end
socket(port) click to toggle source
# File lib/star_ethernet/printer.rb, line 100
def socket(port)
  @custom_socket ?
    @custom_socket.call(@host, port) :
    TCPSocket.new(host, port)
end
telnet() click to toggle source
# File lib/star_ethernet/printer.rb, line 110
def telnet
  telnet = Net::Telnet.new('Host' => @host, 'Port' => StarEthernet.configuration.telnet_port)
  telnet.waitfor(/(.)*login: /)
  telnet.cmd('String' => 'root', 'Match' => /(.)*Password: /)
  telnet.cmd('String' => 'public', 'Match' => /(.)*Selection: /)
  telnet
end