/* REXX | | Name: StartUp | | Purpose: Startup a 3270 session using the hllapi interface | | Tested with: | o PCOMM 5.5 | o Regina Rexx 3.1beta11 | o REXXUTIL via RegUtil: http://home.interlog.com/~ptjm/ | (Needed for SysSleep function for Windows) | o Windows XP Professional | | Based on code from this excellent intro to hllapi: | http://www.os2ezine.com/v3n13/hllapi.htm | | Sample usage: Icon on Windows desktop has this "Target" command: | C:\Regina\regina.exe startup.txt myuserid mypassword sessionid profile | | Note: Do not leave password on an unsecured PC! You may want to change | this exec to prompt for a password! */ say 'Startup session exec starting' arg userid password sessionid profilename icmd error = 0 if userid = '' then do say 'Missing required userid operand' error = error + 1 end if password = '' then do say 'Missing required password operand' error = error + 1 end if sessionid = '' then do say 'Missing required sessionid operand' error = error + 1 end if profilename = '' then do say 'Missing required profilename operand' error = error + 1 end if error <> 0 then do if error == 1 then s = '' else s = 's' say 'Missing operand's', Number missing: ' error say ' ' say 'Syntax: STARTUP USERID PASSWORD SESSIONID PROFILENAME initial-command' say ' ' say 'Note: the initial-command is optional' exit 12 end /* | Load RexxUtil package so we can call SysSleep function */ Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' Call SysLoadFuncs /* | Get HLLAPI interface */ if rxfuncquery('hllapi') then do call rxfuncadd 'hllapi','saahlapi','hllapisrv' say "rxfuncadd occured, good!" end else do say "rxfuncquery for hllapi failed" exit 12 end /* | Equate Keyboard Mnemonics. See page 153 of | ftp://ftp.software.ibm.com/software/network/pcomm/publications/pcomm_55/pcep.pdf */ enter_key = "@E" reset_key = "@R" /* | Ensure we clean up on errors */ signal on failure name CLEANUP signal on halt name CLEANUP signal on syntax name CLEANUP /* | Initial calls to get things going */ rc = hllapi('Start_session', profilename,'X' ,sessionid) say 'Start_session to profile' profilename , 'Session ID ' sessionid ' RC='rc rc=SysSleep(1) rc = hllapi('Set_session_parms', 'CONPHYS') say 'Set_session_parms RC='rc rc=SysSleep(1) /* The call for Start_communication may not be needed on your system */ rc = hllapi('Start_communication', sessionid) say "Start_communication rc="rc rc=SysSleep(1) rc = hllapi('Connect', sessionid) say 'Connect to Session ID 'sessionid' RC='rc select when rc == 5 then rc = hllapi('sendkey', reset_key) when rc == 0 then NOP otherwise say 'Terminating due to connect error' signal CLEANUP end rc=SysSleep(1) /* | Automated logon sequence starts here */ rc=hllapi('Search_ps', "IKJ56700A", 1) if rc = 0 then do say 'Anticipated first screen not found. Data:' say ' ' data=hllapi("Copy_PS") say substr(data,1,256) signal CLEANUP end else say 'Found initial screen, sending userid' call sendwait userid||enter_key,"Password" say 'Sending Password' rc=hllapi("sendkey",password||enter_key) call sendwait enter_key,"***" call sendwait enter_key,"***" if icmd <> "" then do rc=hllapi("sendkey",icmd||enter_key) say 'Sent inital command' icmd end say 'Session' sessionid 'should be ready for your use' rc=SysSleep(1) /* | Terminate */ exit /* | Play nice, reset the session on errors */ CLEANUP: say "At cleanup" call hllapi("reset_system") exit /* | Send a command and wait for a response */ SendWait: keys=arg(1) lookfor=arg(2) rc = hllapi('sendkey', keys) rc = hllapi('wait') do until rc > 0 rc=SysSleep(1) rc=hllapi("Search_ps", lookfor, 1) end return /* | END END END END END -- of Startup.rex */