class ButlerMainframe::Host
Private Instance Methods
sub_close_session()
click to toggle source
Ends the connection and closes the session
# File lib/mainframe/emulators/passport.rb, line 44 def sub_close_session @space.Close @action[:object].Quit @action[:object] = nil end
sub_create_object(options={})
click to toggle source
Create objects from emulator library
# File lib/mainframe/emulators/passport.rb, line 11 def sub_create_object(options={}) str_obj = 'PASSPORT.System' puts "#{Time.now.strftime "%H:%M:%S"} Creating object #{str_obj}..." if @debug == :full @action[:object] = WIN32OLE.new(str_obj) if sub_object_created? @space = @action[:object].Sessions(@session_tag) @screen = @space.Screen end end
sub_exec_command(cmd, options={})
click to toggle source
Execute keyboard command like PF1 or PA2 or ENTER …
# File lib/mainframe/emulators/passport.rb, line 51 def sub_exec_command(cmd, options={}) # Cast cmd to_s cause it could be passed as label @screen.SendKeys "<#{cmd.gsub /\s/, ''}>" @screen.WaitHostQuiet end
sub_fullname()
click to toggle source
# File lib/mainframe/emulators/passport.rb, line 39 def sub_fullname "#{sub_name} #{@space.FullName}" end
sub_get_cursor_axes()
click to toggle source
Get cursor coordinates
# File lib/mainframe/emulators/passport.rb, line 68 def sub_get_cursor_axes [@screen.Col, @screen.Row] end
sub_keyboard_locked()
click to toggle source
The keyboard can be locked for any of the following reasons:
-
The host has not finished processing your last command.
-
You attempted to type into a protected area of the screen.
-
You typed too many characters into a field in Insert mode.
# File lib/mainframe/emulators/passport.rb, line 105 def sub_keyboard_locked @space.KeyboardLocked < 0 end
sub_name()
click to toggle source
# File lib/mainframe/emulators/passport.rb, line 35 def sub_name "#{@action[:object].Name} #{@space.Name}" end
sub_object_created?()
click to toggle source
Check is session is started
# File lib/mainframe/emulators/passport.rb, line 22 def sub_object_created? res = @action[:object] && @action[:object].Sessions(@session_tag) puts "#{Time.now.strftime "%H:%M:%S"} Terminal successfully detected" if @debug == :full && res res end
sub_object_ready?()
click to toggle source
Check is session is operative
# File lib/mainframe/emulators/passport.rb, line 29 def sub_object_ready? res = @space.Connected == -1 puts "#{Time.now.strftime "%H:%M:%S"} Session ready" if @debug == :full && res res end
sub_scan_area(y1, x1, y2, x2)
click to toggle source
It reads a rectangle on the screen
# File lib/mainframe/emulators/passport.rb, line 63 def sub_scan_area(y1, x1, y2, x2) @screen.Area(y1, x1, y2, x2).Value end
sub_scan_row(y, x, len)
click to toggle source
It reads one line part of the screen
# File lib/mainframe/emulators/passport.rb, line 58 def sub_scan_row(y, x, len) @screen.GetString(y, x, len) end
sub_set_cursor_axes(y, x, options={})
click to toggle source
Move cursor to given coordinates
# File lib/mainframe/emulators/passport.rb, line 73 def sub_set_cursor_axes(y, x, options={}) options = { :wait => true }.merge(options) @screen.MoveTo(y, x) @screen.WaitForCursor(y, x) if options[:wait] end
sub_wait_for_string(text, y, x)
click to toggle source
Wait text at given coordinates and wait the session is available again
# File lib/mainframe/emulators/passport.rb, line 97 def sub_wait_for_string(text, y, x) @screen.WaitForString(text, y, x).Value == -1 end
sub_write_text(text, y, x, options={})
click to toggle source
Write text on the screen at given coordinates :check_protect => true add sensitivity to protected areas
# File lib/mainframe/emulators/passport.rb, line 83 def sub_write_text(text, y, x, options={}) options = { :check_protect => true }.merge(options) if options[:check_protect] # This method is sensitive to protected areas sub_set_cursor_axes(y, x) @screen.SendKeys(text) else @screen.PutString(text, y, x) end end
x_cmd(cmd, options={})
click to toggle source
To communicate with executable
# File lib/mainframe/emulators/x3270.rb, line 126 def x_cmd(cmd, options={}) puts "x_cmd in: #{options[:sensible_data] ? ('*' * cmd.size) : cmd}" if @debug == :full @action[:in].print "#{cmd}\n" @action[:in].flush str_res_ok = 'ok' ar_res = [str_res_ok, 'error'] line, str_out = '', '' while line = @action[:out].gets.chomp do puts "x_cmd out: '#{line}'" if @debug == :full break if ar_res.include? line str_out << "#{line[6..-1]}" if /^data:\s/ === line end line == str_res_ok ? str_out : raise(str_out) end
x_status()
click to toggle source
# File lib/mainframe/emulators/x3270.rb, line 143 def x_status @action[:in].print "Query(Cursor)\n" @action[:in].flush str_res_ok = 'ok' ar_res = [str_res_ok, 'error'] line, line_prev = nil, nil while line = @action[:out].gets.chomp do puts "x_cmd out: '#{line}'" if @debug == :full break if ar_res.include? line line_prev = line end line == str_res_ok ? line_prev : raise(line) end