Am I doing something wrong?

Topics: Developer Forum
Dec 18, 2009 at 12:34 AM

I'm an experienced programmer, but for the life of me I can't get this library working. Can someone please steer me in the right direction?

I downloaded the source from http://open3270.codeplex.com/SourceControl/list/changesets, and am using the solution in the /trunk/ folder. I am trying to run the demo project, but the default server listed there (Library of Congress) is no longer valid, so I'm trying to use clemson.clemson.edu, port 23.

The problem is that after the line emulator.Connect("clemson.clemson.edu", 23, null), I can't get ANYTHING to work. Everything ends up in exceptions:

emulator.Refresh(true, 20000)
emulator.Dump()
string currentScreen = emulator.CurrentScreenXML.Dump()

All of these statements result in exceptions of varying messages. If I want to connect to clemson.clemson.edu, what are the basic steps I need to take? I just need something to get me started, and I can take it from there.

Thanks!

Dec 18, 2009 at 1:16 PM

I am pasting in my sample Connect method.  Hopefully this will give you some idea of what to do...

I am going to remove the impertinent lines specific to my setup

emulator = new TNEmulator();
emulator.Config.FastScreenMode = false;
emulator.Config.DefaultTimeout = 3000;
emulator.Config.TermType = "IBM-3278-2-E";
emulator.Config.HostPort = 23;
emulator.Config.HostName = "a.tn.ailife.com";
emulator.Config.ThrowExceptionOnLockedScreen = true;
emulator.Debug = false;
emulator.Config.HostLU = "PRODSYS";
emulator.Connect();
if (emulator.IsConnected())
{
 if (emulator.WaitForText(1, 0, "Signon to CICS on the MAINFRAME", 3000))
 {
     emulator.SendText("username");
     emulator.SendKey(true, "TAB");
     emulator.SendText("password");
     emulator.SendKey(true, "ENTER");
     if (emulator.WaitForText(1, 0, "TSS", 1000))
     {
  tempHolder = emulator.GetRow(0).Trim();
  Log("Something wrong with login: " + tempHolder, Ail.Framework.Logging.PriorityEnumeration.DEBUG);
  if (tempHolder.Contains("TSS7101E Password is Incorrect") ||
      tempHolder.Contains("TSS7141E Use of Accessor ID Suspended") ||
      tempHolder.Contains("TSS7160E") ||
      tempHolder.Contains("TSS7172E Your Accessor ID is Already in Use On Terminal") ||
      tempHolder.Contains("TSS7110E Password Has Expired"))
  {
      Logoff();
      throw new Exception(tempHolder);
  }
     }
     if (emulator.WaitForText(1, 13, "SGN", 1000))
     {
  tempHolder = emulator.GetRow(13).Trim();
  if (tempHolder.Contains("SGN003A  New Password REQUIRED.  Enter your password and a new password.") ||
      tempHolder.Contains("SGN005A  Invalid Userid and/or Password.  Please reenter both.") ||
      tempHolder.Contains("SGN010A  Contact HELP DESK, Access to terminal/facility denied.") ||
      tempHolder.Contains("SGN011A  Userid is ALREADY in use, at another terminal."))
  {
      Logoff();
      throw new Exception(tempHolder);
  }
     }
     retVal = emulator.WaitForText(21, 0, "is complete.", 3000);
 }
 else
     Disconnect();
}

Dec 18, 2009 at 1:58 PM

Also, I am trying the demo using your clemson example.  I notice it keeps dropping the connection.  If you walk through debugging it, you'll notice that it the underlying telnet will have dropped while it is trying to update your screen (DumpXML).  No idea why, unless it has something to do with the config that clemson requires.  I have been using this library for over a year now against my company's mainframe and I did write a front-end wrapper class to call the emulator with because I also ran into some odd issues.  I basically wrapped all of the commands like WaitForText and SendText etc with a check to see if the connection is still up, like so:

protected virtual bool WaitForText(int x, int y, string text, int timeoutMS)
        {
            if (IsConnected())
            {
                try
                {
                    return emulator.WaitForText(x, y, text, timeoutMS);
                }
                catch
                {
                    return this.WaitForText(x, y, text, timeoutMS);
                }
            }
            else
                return false;
        } 

Dec 18, 2009 at 2:52 PM

Ok, so I get long-winded.  I was not able to get the clemson one to work right, so I went online and found a place where you can setup a mainframe account for free: http://www.efglobe.com/cgi-bin/mainframe/mainuser

I created a user, got the hostname and did my initial setup of my account using a real 3270 emulator.  I then went back and modified the demo to connect to this mainframe instead, and changed their WaitForText to match the entry line of this mainframe's first screen, passed it the expected values, etc.  Anyway, the point is, I had no trouble at all logging into this mainframe and reading the screen and passing data.  So, I wish I could help you with clemson, but they must have some oddball timeout or something, no idea how/why that doesn't work.

Please go create an account ont he mainframe I mentioned in the link above and then try the library and let me know if you have any issues.

Dec 18, 2009 at 3:55 PM

Hey jcoffee, thanks SO much for your help! I appreciate all the time you are putting forward in helping me.

I set up an account at the site you mentioned, for testing purposes. However, I am still having trouble doing even the simplest tasks:

            TNEmulator emulator = new TNEmulator();

            emulator.Config.FastScreenMode = false;
            emulator.Config.DefaultTimeout = 3000;
            emulator.Config.TermType = "IBM-3278-2-E";
            emulator.Config.HostPort = 23;
            emulator.Config.HostName = "fandezhi.efglobe.com";
            emulator.Config.ThrowExceptionOnLockedScreen = true;
            emulator.Debug = false;
            emulator.Connect();

            string currentScreen = emulator.CurrentScreenXML.Dump();

On the emulator.CurrentScreenXML.Dump(), I get an exception saying:

Index and length must refer to a location within the string.
Parameter name: length

I am getting so frustrated with why this isn't working for me. Am I using a buggy version of the emulator? I downloaded the latest source (June 23) from http://open3270.codeplex.com/SourceControl/list/changesets.

Thanks again jcoffee!

Dec 18, 2009 at 4:22 PM

OK, apparently, I had misinterpreted the purpose of the Dump() method. I thought it would give a string representation of the current screen, which it obviously doesn't. I have gone ahead and figured out another way to do this.

I have one last question, jcoffee: I see that the emulator has a SetField() method. Is there any easy way to have the emulator return a list of fields on the page? For example, if there is a field that says "Username:", is there any good way of obtaining this?

Dec 18, 2009 at 4:39 PM

One last question :)

Once I connected to the test server (see above), I am running this code:

            if (emulator.IsConnected) {
                if (emulator.WaitForText(1,0, "Mainframe Operating System", 10000)) {
                    emulator.SendText("TSO");
                    emulator.SendKeyFromText(true, "Enter");

                    if (emulator.WaitForText(1, 0, " IKJ56700A ENTER USERID", 10000)) {
                        emulator.SendText("****");
                    }
                }
            }

The code works fine until the second WaitForText() command, at which point I get an exception saying the connection was lost. Do you know why this is happening? Is there something I need to be doing here?

Dec 18, 2009 at 9:13 PM
ylibrach wrote:

OK, apparently, I had misinterpreted the purpose of the Dump() method. I thought it would give a string representation of the current screen, which it obviously doesn't. I have gone ahead and figured out another way to do this.

I have one last question, jcoffee: I see that the emulator has a SetField() method. Is there any easy way to have the emulator return a list of fields on the page? For example, if there is a field that says "Username:", is there any good way of obtaining this?

 Yeah, Dump() only sends data to debug, so I highly recommend all development make use of debug = true and specify a log file.  Also, if you do not have an alternative tail program, use http://tailformwin32.sourceforge.net to "tail" (like the unix/linux command) the log file.  This will allow you to watch the debug log file in real-time and actually see the mainframe screens.  I recommend make a call to Dump() before you send data to a screen, before you send a submit key, and afterward, just to make sure everything is going as expected.  at least until you get the hang of it and are confident there are no problems.  I usually set this up so that while testers are working through my code, I can view the log file and see what they were doing when an error happens.

 

Anyway, use ShowFields() to enumerate the fields, assuming the mainframe screens you are accessing are "formatted" screens.  A lot fo the ones I use at my company are not, so i have to manually search for data on the screen every single time, which really stinks, but hey, it is what it is.

Dec 18, 2009 at 9:20 PM
ylibrach wrote:

One last question :)

Once I connected to the test server (see above), I am running this code:

            if (emulator.IsConnected) {
                if (emulator.WaitForText(1,0, "Mainframe Operating System", 10000)) {
                    emulator.SendText("TSO");
                    emulator.SendKeyFromText(true, "Enter");

                    if (emulator.WaitForText(1, 0, " IKJ56700A ENTER USERID", 10000)) {
                        emulator.SendText("****");
                    }
                }
            }

The code works fine until the second WaitForText() command, at which point I get an exception saying the connection was lost. Do you know why this is happening? Is there something I need to be doing here?

 Yeah, this is odd.  I did the exact same thing and sure enough, it dropped waiting for the next screen.  Perhaps one of the other guys who has also been using this library and contributing to it can comment, as I have been using this against the mainframe at my office and have never experienced this kind of issue.  For now, the best I can offer is to step through the code and find out what call it is making when the connection is dropped, perhaps there is some kind of trigger/event that is dropping the connection and we can modify the setting that affects it.  Perhaps it is the default timeout, but I cannot be certain.

Feb 8, 2010 at 7:49 PM

Following up on this, did you come back since I posted a few updates to the code and incorporate them into your local source?  I found a bug in that Dump() code, as well as I had a very similar issue with the connection dropping and resolved that as well.  if you are not sure, look for my posts where i pasted in my changes, as well as check the update log, i sent the changes in to be merged into the downloadable source.

Apr 8, 2010 at 7:53 PM

Not sure if anyone is still reading these, but I'm having the same problem. The system I'm trying to connect to has an intro screen where you have to type in an application name. A screen then flashes "LOGON IN PROCESS, PLEASE WAIT" and then refreshes to a login screen for the application when using an emulator.

The library says it lost the connection when waiting for the login screen text. That screen refresh seems to confuse it. I don't know enough about 3270 emulation to know what is isn't doing right. I did apply the patch mentioned, but it doesn't affect this issue.

If I can get past this issue, it looks like this library will do everything I need to do the screen scraping I need.

 

Nov 17, 2010 at 6:39 PM
jcoffee wrote:

Following up on this, did you come back since I posted a few updates to the code and incorporate them into your local source?  I found a bug in that Dump() code, as well as I had a very similar issue with the connection dropping and resolved that as well.  if you are not sure, look for my posts where i pasted in my changes, as well as check the update log, i sent the changes in to be merged into the downloadable source.

 

I keep getting "Error sending key: The TN3270 connection was lost" when I send the key "PF01", the initial screen of my terminal requires to press F1 on the keyboard, do you have an updated code that you could share with us?
Thank you

 

Nov 17, 2010 at 6:39 PM
Edited Nov 17, 2010 at 6:40 PM

I keep getting "Error sending key: The TN3270 connection was lost" when I send the key "PF01", the initial screen of my terminal requires to press F1 on the keyboard, do you have an updated code that you could share with us?
Thank you

Nov 17, 2010 at 7:49 PM

When I try to use the sample code here on the DezHi Mainframe System I get the following DisconnectReason: "No data received in telnet.OnReceivedData, disconnecting"

The Code:

if (emulator.IsConnected) {
if (emulator.WaitForText(1,0, "Mainframe Operating System", 10000)) {
emulator.SendText("TSO");
emulator.SendKeyFromText(true, "Enter");

if (emulator.WaitForText(1, 0, " IKJ56700A ENTER USERID", 10000)) {
emulator.SendText("****");
}
}
}

Nov 17, 2010 at 8:09 PM
theplague,
Not sure which version of code you are using. If you want, I can send you the source I am working from, though I have it compiled and do not really touch the source any more.
JC
_____________________________________________________
This message contains information which is privileged and confidential and is solely for the use of the
intended recipient. If you are not the intended recipient, be aware that any review, disclosure,
copying, distribution, or use of the contents of this message is strictly prohibited. If you have
received this in error, please destroy it immediately and notify us at PrivacyAct@torchmarkcorp.com.
Nov 17, 2010 at 8:28 PM
jcoffee wrote:
theplague,
 
Not sure which version of code you are using. If you want, I can send you the source I am working from, though I have it compiled and do not really touch the source any more.
 
JC
_____________________________________________________
This message contains information which is privileged and confidential and is solely for the use of the
intended recipient. If you are not the intended recipient, be aware that any review, disclosure,
copying, distribution, or use of the contents of this message is strictly prohibited. If you have
received this in error, please destroy it immediately and notify us at PrivacyAct@torchmarkcorp.com.

If you could that would be awesome, this sample code with that test mainframe were supposed to be an easy combination to test the library but I can't seem to do any task with it except for connect and disconnect, everything else timesout, drops the connection or doesn't do anything, do you have access to my email to send the code?
Thanks

 

Coordinator
Nov 18, 2010 at 1:18 PM

jcoffee, please send me your source. I'd like to sort out this issue.

Email to my username at gmail.

Nov 18, 2010 at 1:37 PM
I am thinking, based upon the side discussions I have had, that the source is nto the problem. Everyone who is askign how to make it work has been having the same issue, they get a dropped connection, and I believe all of them are trying to connect to that public mainframe. I am going to do a test app today to see if i can connect with my code, and then report back my fidnings. If I cannot get it to work with the public mainframe using good solid code that I have in production apps here at work, then we can rule out the source as being buggy. It would tell us that there is either a setting that needs to be tweaked to connect to that particular mainframe, or that perhaps there is somethign this code is lacking for every situation. Not sure, as this has worked for me and been using it for more than a year easily.


From: igitur [mailto:notifications@codeplex.com]
Sent: Thursday, November 18, 2010 8:19 AM
To: Jason Coffee
Subject: Re: Am I doing something wrong? [Open3270:78500]

From: igitur

jcoffee, please send me your source. I'd like to sort out this issue.

Email to my username at gmail.

Read the full discussion online.

To add a post to this discussion, reply to this email (Open3270@discussions.codeplex.com@discussions.codeplex.com)

To start a new discussion for this project, email Open3270@discussions.codeplex.com@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

_____________________________________________________
This message contains information which is privileged and confidential and is solely for the use of the
intended recipient. If you are not the intended recipient, be aware that any review, disclosure,
copying, distribution, or use of the contents of this message is strictly prohibited. If you have
received this in error, please destroy it immediately and notify us at PrivacyAct@torchmarkcorp.com.
Dec 10, 2010 at 8:59 PM

I retried some testing today.  No matter which menu option i choose from DeZhi, it always returns the message that it tried a receive and got no data, and therefore disconnects the connection.  On a whim I removed the ability to drop the connection, but it is not grabbing data after the intial entry on that first screen.  I don't know much about this particular mainframe, and am having tons of success on my company's mainframe.  I know that is a bit of a cop out, but I just don't have more time to find out why it doesn't receive data from DeZhi.  anyone else have any luck with it, or a different public mainframe to test against?

Mar 14, 2012 at 1:46 PM

Hi jcoffee, I was looking at the code you pasted back in 2009. I have a situation where i am getting disconnected when the "ENTER" key command is being processed. The exception being thrown is:

HostException 'The TN3270 connection was lost' No data received in telnet.OnReceivedDate, disconnecting

Now, I am under the impression that it may have something to do with the way the password is being sent, because when i enter a wrong password it gives the same exception or maybe its something else altogether. Would you have any suggestions on what may be going worng here?

just as a side note,  when I use attachmate(to connect to the mainframe), the password being entered is masked with spaces. Does that make any difference?

Mar 14, 2012 at 1:48 PM
ktrip wrote:

Hi jcoffee, I was looking at the code you pasted back in 2009. I have a situation where i am getting disconnected when the "ENTER" key command is being processed. The exception being thrown is:

HostException 'The TN3270 connection was lost' No data received in telnet.OnReceivedDate, disconnecting

Now, I am under the impression that it may have something to do with the way the password is being sent, because when i enter a wrong password it gives the same exception or maybe its something else altogether. Would you have any suggestions on what may be going worng here?

just as a side note,  when I use attachmate(to connect to the mainframe), the password being entered is masked with spaces. Does that make any difference?


As a matter of fact I would appreciate anybody's input on this. Thank you.

Mar 14, 2012 at 1:50 PM

Ktrip,

No, the password on most mainframes is masked with spaces (for obvious security reasons). Are you only getting this message at the login, and not able to get beyond? Are you dumping everything to a log file so you can see what is going on? I usually use a tail program to watch my log file in real time.

Regardless, whatever detail you can would be helpful


_____________________________________________________
This message contains information which is privileged and confidential and is solely for the use of the
intended recipient. If you are not the intended recipient, be aware that any review, disclosure,
copying, distribution, or use of the contents of this message is strictly prohibited. If you have
received this in error, please destroy it immediately and notify us at PrivacyAct@torchmarkcorp.com. ­­
Mar 14, 2012 at 2:36 PM

 I didnt expect you to reply this quickly, thank you.

I am able to move from the home screen (which takes an input and then the enter key) to the login screen and there i enter the ID and pass, on giving the enter key command it disconnects giving the previously mentioned exception. I am using the emulator.currentScreenXML.dump() to monitor what the screens are. So, the only to screens that I have been able to test this on is the home screen which moves to the login screen and then i get the exception.

Mar 14, 2012 at 2:39 PM

I think this is an issue others may have posted about previously. However, it may be related to the settings you are using for that particular mainframe. Make sure those settings match how you have them in Attachmate.

From: ktrip [email removed]
Sent: Wednesday, March 14, 2012 9:37 AM
To: Jason Coffee
Subject: Re: Am I doing something wrong? [Open3270:78500]

From: ktrip

I didnt expect you to reply this quickly, thank you.

I am able to move from the home screen (which takes an input and then the enter key) to the login screen and there i enter the ID and pass, on giving the enter key command it disconnects giving the previously mentioned exception. I am using the emulator.currentScreenXML.dump() to monitor what the screens are. So, the only to screens that I have been able to test this on is the home screen which moves to the login screen and then i get the exception.


_____________________________________________________
This message contains information which is privileged and confidential and is solely for the use of the
intended recipient. If you are not the intended recipient, be aware that any review, disclosure,
copying, distribution, or use of the contents of this message is strictly prohibited. If you have
received this in error, please destroy it immediately and notify us at PrivacyAct@torchmarkcorp.com. ­­
Mar 14, 2012 at 2:42 PM

I am also not at liberty to share any log files as they contain information which is confidential as far as i am concerned, although please let me know any particualr information you might need. I will try to explain it to as clearly as possible. Thank you again.

Mar 14, 2012 at 2:44 PM

I did already check with the attachmate settings, maybe i missed something. Have you faced any such errors?

Mar 14, 2012 at 2:55 PM

I do not want or need to see your log files. You do. The point I am making is, verify your settings match those that you use in Attachmate, then either run in debug and get into the nitty gritty details to see what is actually happening, or watch the log files to see if it gives you any indication of what it is doing just before it disconnects. Otherwise, there just isn’t enough info to go on. I have been using the library for years, and it just works.

From: ktrip [email removed]
Sent: Wednesday, March 14, 2012 9:43 AM
To: Jason Coffee
Subject: Re: Am I doing something wrong? [Open3270:78500]

From: ktrip

I am also not at liberty to share any log files as they contain information which is confidential as far as i am concerned, although please let me know any particualr information you might need. I will try to explain it to as clearly as possible. Thank you again.


_____________________________________________________
This message contains information which is privileged and confidential and is solely for the use of the
intended recipient. If you are not the intended recipient, be aware that any review, disclosure,
copying, distribution, or use of the contents of this message is strictly prohibited. If you have
received this in error, please destroy it immediately and notify us at PrivacyAct@torchmarkcorp.com. ­­
Mar 14, 2012 at 2:59 PM

Two of the settings that look different are:

Enable ATTN key as IAC Break (this is checked under "TN3270 specific" options)

Use TN3270E when supported (this is checked under TN3270 enhanced protocol)

If that helps in any way then please let me know. Thank you.

Mar 14, 2012 at 3:04 PM

Believe  me, i have been trying to debug this for some time now. The problem is I dont know much about mainframes to know what exactly to look for here. Do you have nay suggestions on what I should be looking for? Thanks again.

Feb 20, 2013 at 3:18 AM
Edited Feb 20, 2013 at 3:37 AM
jcoffee,

While I know it is very late in the scheme of things but I was getting the "No data received in telnet.OnReceivedData, disconnecting" issue that theplague and ktrip were receiving and by some luck and the use of debug, I found that I was able to get past the issue by adding the following just after the emulator object is created.
emulator.Config.ThrowExceptionOnLockedScreen = false;
Once I did this I was able to move forward. I realize that many have probably already found this but I thought I'd post it for any that might end up looking, hopefully saving someone sometime.