X3270 Connection and Programming

5.8k views Asked by At

I'm looking at using a X3270 terminal emulator. I have http://x3270.bgp.nu/ looked over this source material and still don't see how to start using the tool or configure it.

I'm wonder how I can open a terminal and connect. Another question is how could I integrate this into a python program?

edit: here is a snippet:

em = Emulator()     
em.connect(ip)
em.send_string('*user name*')
em.exec_command('Tab')
em.send_string('*user password*')
em.send_enter()
em.send_enter()
em.wait_for_field()
em.save_screen("{0}screenshot".format(*path*))

looking at the save screen i see that the cursor hasn't moved? I can move the cursor using

em.move_to(7,53)

but after that i don't get any text sent through. Any Ideas?

2

There are 2 answers

0
zarchasmpgmr On BEST ANSWER

Please read my comment above first - it would be helpful to have more detail as to what you need to do.

After considering that…have you looked at the py3270 package at https://pypi.python.org/pypi/py3270/0.1.5 ? The summary says it talks to x3270.

1
AnonCow On

Here's what I do; it works 100% of the time:

from py3270 import *
import sys, os

host = "%s" % sys.argv[1].upper()
try:
    e = Emulator()
    e.connect(host)
    e.wait_for_field()
except WaitError:
    print "py3270.connect(%s) failed" % (host)
    sys.exit(1)

print "--- connection made to %s ---" % (host)`

If you haven't got a network connection to your host, that wait_for_field() call is going to wait for a full 120 seconds. No matter what I do, I don't seem to be able to affect the length of that timeout.

But your user doesn't have to wait that long, just have him kill your script with a KeyboardInterrupt. Hopefully, your user will grow accustomed to success equaling the display of that "--- connection made ..." message so he'll know he's in trouble when/if the host doesn't respond.

And that's a point I need to make: you don't connect to a terminal (as you described), rather you connect to a host. That host can be either a VTAM connection or some kind of LPAR, usually TSO or z/VM, sometimes CICS or IMS, that VTAM will take you to. Each kind of host has differing prompts & screen content you might need to test for, and sometimes those contents are different depending on whose system you're trying to connect to. Your script becomes the "terminal", depending on what you want to show your user.

What you need to do next depends on what kind of system you're trying to talk to. Through VTAM? (Need to select a VTAM application first?) To z/VM? TSO? Are you logging on or DIALing? What's the next keystroke/field you have to use when you're working with a graphic x3270/c3270 terminal? You need to know that in order to choose your next command.

Good luck!