Class: TE3270::Emulators::X3270

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#executable_command=(value) ⇒ Object (writeonly)

Sets the attribute executable_command

Parameters:

  • value

    the value to set the attribute executable_command to.



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

Parameters:

  • value

    the value to set the attribute host to.



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

Parameters:

  • value

    the value to set the attribute max_wait_time to.



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

Parameters:

  • value

    the value to set the attribute port to.



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

Parameters:

  • value

    the value to set the attribute trace to.



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)

Examples:

Example x3270 object constructor with a block

screen_object = MyScreenObject.new(:x3270)
screen_object.connect do |emulator|
  emulator.executable_command = 'path_to_executable'
  emulator.host = 'host.example.com'
  emulator.port = 23
  emulator.max_wait_time = 5
end

Yields:

  • (_self)

Yield Parameters:



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

#disconnectObject

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.

Parameters:

  • row (Fixnum)

    the x coordinate of location on the screen.

  • column (Fixnum)

    the y coordinate of location on the screen.

  • length (Fixnum)

    the length of string to extract

Returns:

  • (String)


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.

Parameters:

  • str (String)

    the string to set

  • row (Fixnum)

    the x coordinate of the location on the screen.

  • column (Fixnum)

    the y coordinate of the location on the screen.



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.

Parameters:

  • filename (String)

    the path and name of the screenshot file to be saved



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.

Parameters:

  • keys (String)

    keystokes up to 255 in length



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

#textString

Returns the text of the active screen

Returns:

  • (String)


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

Parameters:

  • seconds (Fixnum)

    the maximum number of seconds to wait



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

Parameters:

  • str (String)

    the string to wait for

  • row (Fixnum)

    the x coordinate of location

  • column (Fixnum)

    the y coordinate of 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.

Parameters:

  • row (Fixnum)

    the x coordinate of the location

  • column (Fixnum)

    the y coordinate of the 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