kangkeng Posted June 28, 2011 Share Posted June 28, 2011 Hi Folks,I recently spent quite some time figuring out how to get AutoIT working with the HLLAPI api on a 5250 emulator. Hopefully, this code snippet will help someone else in the future. If you have no idea what HLLAPI or a 5250 emulator is, you probably don't need this expandcollapse popup#include <Array.au3> $returncode="" $function=1 $dataString="" $dataLength=0 ; NB: Your 5250 session must be started before this will work $dll = DllOpen("ehlapi32.dll") ; change this to whatever dll your client provides $result = connectSession("A") ; Connect to session "A". Usually displayed on the terminal session window title if $result<>0 Then mb("Connection to open 5250 Session Failed (have you opened a session?)") Exit EndIf $result = getScreen() ; get the entire screen $nice=format80($result) $result = getStatusLine() ; get the status line $nice=$nice & format80($result) setNowait() ; don't wait during status checks, for the system to become available $result=getStatus() ; get the status ; setTimewait() $nice=$nice & @CRLF & "Status: >" & $result & "<" MsgBox(1,"ret:" & $dll,$nice) ; sendReset() setInputFieldText("User", "kangkeng") setInputFieldText("Password","password") setInputFieldText("Menu","Salmon:)<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />") ; sendCR() $result=waitDone(1000) ; wait for system to come back in one second $loc = findField("user") $loc = getNextUField($loc) $text = getField($loc) ; get the text from a field given the location. mb(">" & $text & "<") if $result>0 then sendReset() ; mb("Wait:" & $result) DllClose($dll) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Begin lots of functions to wrap around the HLLAPI ; Func hllCall() return DllCall($dll, "none", "hllapi", "word*", $function, "str", $dataString, "word*", $dataLength, "word*", $returncode) EndFunc ; wait for system to come back in a couple of milliseconds. 0-OK otherwise status error number returned Func waitDone($milliseconds) $done=99; $begin = TimerInit() while ($done=99) $res = getStatus() if ($res=0) Then $done=0 sleep(100) $dif = TimerDiff($begin) if ($dif > $milliseconds) Then $done=$res WEnd return $done EndFunc ; convience function to find a label and set the entry field after it with a value. PADs blanks to max size of field Func setInputFieldText($partialString,$text) $loc = findField($partialString) $loc = getNextUField($loc) $size = getFieldLength($loc) ;mb($size) setField($loc,StringLeft($text & " ",$size)) EndFunc ; get the length of a field Func getFieldLength($loc) $function=32 $dataString="T " $dataLength=2 $returncode=$loc $res = hllCall() return $res[3] EndFunc ; get the location of the next entry field given a position Func getNextUField($loc) $function=31 $dataString="NU" $dataLength=2 $returncode=$loc $res = hllCall() return $res[3] EndFunc ; Get location of a particular substring in the entire screen Func findField($partialText) ; dump out whole screen first $res = getScreen() ; find the text in the result return StringInStr($res,$partialText) EndFunc ; set a certain field to a value Func setField($pos,$text) $function=33 $dataString=$text $dataLength=StringLen($text) $returncode=$pos return hllCall() EndFunc ; get the text of a field Func getField($pos) $function=34 $dataString="" $dataLength=300 $returncode=$pos $res = hllCall() return $res[2] EndFunc ; get the status of the screen Func getStatus() $function=4 $res = hllCall() return $res[4] EndFunc ; get the wait to no wait. i.e. calls to wait will immediately return if busy. Func setNowait() $function=9 $dataString="NWAIT" $dataLength=StringLen($dataString) return hllCall() EndFunc Func setTimewait() $function=9 $dataString="TWAIT" $dataLength=StringLen($dataString) return hllCall() EndFunc ; connect to a session Func connectSession($session) $function=1 $dataString=$session $res = hllCall() return $res[4] EndFunc ; get the entire screen in a string Func getScreen() $function=5 $res = hllCall() return $res[2] EndFunc ; get the status line Func getStatusLine() $function=13 $dataLength=110 $res = hllCall() return $res[2] EndFunc ; send a reset Func sendReset() return sendText("@R") EndFunc ; send a enter Func sendCR() return sendText("@E") EndFunc ; send text to screen Func sendText($text) $function=3 $dataString=$text $dataLength=StringLen($text) return hllCall() EndFunc ; ; Some generic Utility functions ; Func format80($string) $end="N" $count=0 $answer="" while ($end="N") $answer = $answer & StringMid($string,($count * 80) + 1,80) & @CRLF $count = $count + 1 if $count=25 Then $end="Y" WEnd return $answer EndFunc Func mb($string) ; quick and dirty message box msgbox(1,"a message",$string) EndFunc mLipok and MarkIT 2 Link to comment Share on other sites More sharing options...
apgenco Posted July 14, 2011 Share Posted July 14, 2011 Hi Friend, Excellent post and I have been searching for similar code for quite long. I have a requirement to automate tandem emulator (6530) and stuck with the code. Link to comment Share on other sites More sharing options...
willichan Posted May 3, 2012 Share Posted May 3, 2012 @kangkeng, Thanks for this! I have been wanting to automate some of my AS400 admin tasks for some time. This works great. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
junkew Posted January 18, 2018 Share Posted January 18, 2018 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
TheOne23 Posted June 10, 2020 Share Posted June 10, 2020 Hi Kangkeng, On your script how to you send a key like the "F10" key? Thank you. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 10, 2020 Developers Share Posted June 10, 2020 37 minutes ago, TheOne23 said: Hi Kangkeng, On your script how to you send a key like the "F10" key? Don't hold your breath for the answer as this OP hasn't been around the last 9 years. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now