Class: TE3270::Emulators::X3270
- Inherits:
-
Object
- Object
- TE3270::Emulators::X3270
- Defined in:
- lib/te3270/emulators/x3270.rb
Overview
This class has the code necessary to communicate with the terminal emulator called EXTRA! X-treme. You can use this emulator by providing the :extra
parameter to the constructor of your screen object or by passing the same value to the emulator_for
method on the TE3270
module.
Instance Attribute Summary collapse
-
#executable_command ⇒ Object
writeonly
Sets the attribute executable_command.
-
#host ⇒ Object
writeonly
Sets the attribute host.
-
#max_wait_time ⇒ Object
writeonly
Sets the attribute max_wait_time.
-
#port ⇒ Object
writeonly
Sets the attribute port.
-
#trace ⇒ Object
writeonly
Sets the attribute trace.
Instance Method Summary collapse
-
#connect {|_self| ... } ⇒ Object
Creates a method to connect to x3270.
-
#disconnect ⇒ Object
Disconnects the x3270 System connection.
-
#get_string(row, column, length) ⇒ String
Extracts text of specified length from a start point.
-
#put_string(str, row, column) ⇒ Object
Puts string at the coordinates specified.
-
#screenshot(filename) ⇒ Object
Creates a method to take screenshot of the active screen.
-
#send_keys(keys) ⇒ Object
Sends keystrokes to the host, including function keys.
-
#text ⇒ String
Returns the text of the active screen.
-
#wait_for_host(seconds) ⇒ Object
Waits for the host to not send data for a specified number of seconds.
-
#wait_for_string(str, row, column) ⇒ Object
Wait for the string to appear at the specified location.
-
#wait_until_cursor_at(row, column) ⇒ Object
Waits until the cursor is at the specified location.
Instance Attribute Details
#executable_command=(value) ⇒ Object (writeonly)
Sets the attribute executable_command
12 13 14 |
# File 'lib/te3270/emulators/x3270.rb', line 12 def executable_command=(value) @executable_command = value end |
#host=(value) ⇒ Object (writeonly)
Sets the attribute host
12 13 14 |
# File 'lib/te3270/emulators/x3270.rb', line 12 def host=(value) @host = value end |
#max_wait_time=(value) ⇒ Object (writeonly)
Sets the attribute max_wait_time
12 13 14 |
# File 'lib/te3270/emulators/x3270.rb', line 12 def max_wait_time=(value) @max_wait_time = value end |
#port=(value) ⇒ Object (writeonly)
Sets the attribute port
12 13 14 |
# File 'lib/te3270/emulators/x3270.rb', line 12 def port=(value) @port = value end |
#trace=(value) ⇒ Object (writeonly)
Sets the attribute trace
12 13 14 |
# File 'lib/te3270/emulators/x3270.rb', line 12 def trace=(value) @trace = value end |
Instance Method Details
#connect {|_self| ... } ⇒ Object
Creates a method to connect to x3270. This method expects a block in which certain platform specific values can be set. Extra can take the following parameters.
-
executable_command - this value is required and should be the name of the ws3270 executable
-
host - this is required and is the (DNS) name of the host to connect to
-
max_wait_time - max time to wait in wait_for_string (defaults to 10 if not specified)
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/te3270/emulators/x3270.rb', line 31 def connect @max_wait_time = 10 @trace = false @port = 23 yield self if block_given? raise 'The executable command must be set in a block when calling connect with the X3270 emulator.' if @executable_command.nil? raise 'The host must be set in a block when calling connect with the X3270 emulator.' if @host.nil? start_x3270_system end |
#disconnect ⇒ Object
Disconnects the x3270 System connection
45 46 47 48 |
# File 'lib/te3270/emulators/x3270.rb', line 45 def disconnect @x3270_input.close @x3270_output.close end |
#get_string(row, column, length) ⇒ String
Extracts text of specified length from a start point.
58 59 60 61 62 63 64 65 66 |
# File 'lib/te3270/emulators/x3270.rb', line 58 def get_string row, column, length x_send "ascii(#{row-1},#{column-1},#{length})" result_string = "" while line = x_read do break if line == 'ok' result_string = result_string + line[6..-1] if line[0..5] == 'data: ' end result_string end |
#put_string(str, row, column) ⇒ Object
Puts string at the coordinates specified.
75 76 77 78 |
# File 'lib/te3270/emulators/x3270.rb', line 75 def put_string(str, row, column) x_send_no_rsp "MoveCursor(#{row-1},#{column-1})" x_send_no_rsp 'string "' + str.to_s.gsub('"', '\\"') + '"' end |
#screenshot(filename) ⇒ Object
Creates a method to take screenshot of the active screen. If you have set the :visible
property to false it will be made visible prior to taking the screenshot and then changed to invisible after.
137 138 139 140 |
# File 'lib/te3270/emulators/x3270.rb', line 137 def screenshot(filename) File.delete(filename) if File.exists?(filename) x_send_no_rsp "printtext(file,#{filename})" end |
#send_keys(keys) ⇒ Object
Sends keystrokes to the host, including function keys.
85 86 87 88 89 90 91 92 |
# File 'lib/te3270/emulators/x3270.rb', line 85 def send_keys(keys) key = keys[1..-2] if m=/^(Pf|Pa)(\d+)$/.match(key) key = "#{m[1]}(#{m[2]})" end x_send_no_rsp key x_send_no_rsp "wait(output)" end |
#text ⇒ String
Returns the text of the active screen
147 148 149 |
# File 'lib/te3270/emulators/x3270.rb', line 147 def text get_string(1,1,24*80) end |
#wait_for_host(seconds) ⇒ Object
Waits for the host to not send data for a specified number of seconds
116 117 118 |
# File 'lib/te3270/emulators/x3270.rb', line 116 def wait_for_host(seconds) x_send_no_rsp "Wait(#{seconds},Output)" end |
#wait_for_string(str, row, column) ⇒ Object
Wait for the string to appear at the specified location
101 102 103 104 105 106 107 108 109 |
# File 'lib/te3270/emulators/x3270.rb', line 101 def wait_for_string(str, row, column) total_time = 0.0 sleep_time = 0.5 while get_string(row, column, str.length) != str do sleep sleep_time total_time = total_time + sleep_time break if total_time >= @max_wait_time end end |
#wait_until_cursor_at(row, column) ⇒ Object
Waits until the cursor is at the specified location.
126 127 128 |
# File 'lib/te3270/emulators/x3270.rb', line 126 def wait_until_cursor_at(row, column) x_send_no_rsp "MoveCursor(#{row-1},#{column-1})" end |