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
# File lib/star_ethernet/printer.rb, line 17 def print(data) begin 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, 'receive nbs status') end socket.print(StarEthernet::Command.initialize_print_sequence) fetch_status('fetch etb status for checking counting up after initializing print sequence') if current_status.offline? raise StarEthernet::PrinterOffline.new(@status.full_messages) end socket.print(StarEthernet::Command.update_asb_etb_status) StarEthernet.configuration.retry_counts.times do |index| sleep StarEthernet.configuration.fetch_time_interval fetch_status('fetch etb status for reserve etb count before printing') break if @status.etb_incremented? if index == StarEthernet.configuration.retry_counts - 1 raise StarEthernet::EtbCountUpFailed.new(@status.full_messages) end end socket.print(StarEthernet::Command.start_document) socket.print(data) socket.print(StarEthernet::Command.update_asb_etb_status) socket.print(StarEthernet::Command.end_document) StarEthernet.configuration.retry_counts.times do |index| sleep StarEthernet.configuration.fetch_time_interval fetch_status('fetch etb status for checking print success') break if @status.etb_incremented? if index == StarEthernet.configuration.retry_counts - 1 raise StarEthernet::PrintFailed.new(@status.full_messages) end end ensure socket.close end end
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