Recently Browsing 0 members
No registered users viewing this page.
Here is an existing AS400 PCOM script that I have:
UDF Header Title: _PCOMM
UDF Header Version: 0.1.0
AutoIt Version: 220.127.116.11
Author: Jason S. - Jewelry Supply, Inc.
Script Function: PCOMM UDF Header
For use with IBM AS/400 - IBM OS/400 - IBM System i - IBM i application system.
This PCOMM UDF Header targets ASW - an ERP application suite written in IBM's RPG language (yuck!),
although it will work for any AS/400 system and is not ASW specific.
PCOMM allows injection of keystrokes into the datastream of
a running terminal/console application ("Green Screen" Console Emulator).
- Assumes Session 'A' but can be overriden using the aswConnect() function.
PCOMM allows observing of characters in the datastream of a running
terminal/console application ("Green Screen" Console Emulator).
- Assumes Session 'A' but can be overriden using the aswConnect() function.
Global $Session = "A"
; Specify session to connect to
$Session = $nSession
; Connect to ASW
; @param $nSession - Specify session to connect to. Ex: "A"
Func aswConnect($nSession = $Session)
$Obj_ConnMgr = ObjCreate("PCOMM.autECLConnMgr")
$OBJ_EmulSession = ObjCreate("PCOMM.autECLSession")
$Ps = $OBJ_EmulSession.autECLPS
$Oia = $OBJ_EmulSession.autECLOIA
; Send Data to ASW
; if $rownum and $colnum are not specified, defaults to the cmd line
Func aswSend($keys, $rownum = 20, $colnum = 7, $inhibit = 1)
$Ps.SendKeys($keys, $rownum, $colnum)
if $inhibit = 1 Then
While $Oia.InputInhibited <> 0
; Get Data from ASW
Func aswGet($row, $col, $length)
$info = $Ps.GetText($row,$col,$length)
; Check which page we are on
; @param $page - Page to see if we are on. Ex: "DMR30101" == Sales Order Maintenance page
Func checkScreen($page, $rownum = 1, $colnum = 72, $length = 8)
If StringInStr(aswGet($rownum, $colnum, $length), $page) Then
I would like to use it launch a connection to the AS400. I have an executable that I run with an hod file. Do I just need to run the exe and hod file then run the session connect function and send keys function to pass credentials?
So I'm trying to do some as400 automation and hit a wall when trying to get a COM object. The code on line 8 is failing, the as400.ws file opens with PCSWS.exe so I tried using that as the file path too but that didn't work either. Any and all help is greatly appreciated!
$file = "C:\Users\Rhidlor\Desktop\as400.ws" If Not FileExists($file) Then MsgBox(0, "Error", "Error finding file") Exit EndIf $object = ObjGet($file) If @error Then MsgBox(0, "Error", "Error getting object") Exit EndIf $object.SendKeys("05")
I am trying to open a as400 session but no luck. Here is my code.
; Run Notepad with the window maximized.
Run("C:\Program Files\IBM\Client Access\Emulator\Private\iSynergy.ws", "", @SW_SHOWMAXIMIZED)
; Wait for 4 seconds.
this is very specific. I'm an administrator for several IBM i Power mainframe servers that run i5/OS and people use the Client Access Software.
For now I've been using the Host Access Class Lib in my AutoIt Scripts on Client Access to automate most of my tasks.
The essential code lines are this:
After this you can use the methods listed here to remote-control your Client Access session. Much like a macro.
This worked fine for the Client Access software. Now IBM released their new IBM i Access Client Solutions and I can't get it to work with it.
Does anyone have any experience with this already by chance?
I'm actually really proud of myself today. I'm always keen on using AutoIT wherever I can, as I've been developing in it since the age of 14 and whenever I meet any new technical staff or developers at the different clients I visit it always gets a mention and a demonstration. So we had a minor problem today at one of our clients, whereby they had an existing Windows Service implemented with a config file but the source-code was missing, which limited the ability of our company to enhance the interface in any way.
Now considering the fact that I was paid to develop this I will refrain from divulging any company names or "secrets" as, of course, there are clauses in my contract that state that my work belongs to them. I am however a SAP ABAP developer by trade so anything that falls outside of the defined limits of this trade I can technically share, but regardless I'll keep the information limited.
So the requirement was to pull data from IBM Websphere, write it out to a file and post it into SAP through a custom built RFC. It turned out to be much less complicated than I imagined and through the research on these forums, I had discovered that similar things had been attempted but that nothing concrete had been written for AutoIT specifically (The MQ part, not the SAP part). So without further adieu I present my thinking.
I started out with the IBM Websphere dll using DllOpen and DllCall. After a few frustrating attempts at creating COM objects through the DLL Call. I finally discovered that there was another dll that I could register using regsrv32. It was called MQAX200.dll
Once this dll was registered on the system I could access the following piece of code;
EnvSet("MQSERVER", $iniServer) ;MQ Server Environment Variable $MQSess = ObjCreate("MQAX200.MQSession") $QMgr = ObjCreate("MQAX200.MQQueueManager") $QMgr = $MQSess.AccessQueueManager($iniQM) ;Queue Manager ConsoleWrite("Connected" & @CRLF)
After this was complete and I successfully tested my connection I added the following to read from MQ;
$Queue = $QMgr.AccessQueue($iniQueue, 2) ;Queue (2=MQOO_INPUT, 16=MQOO_OUTPUT) While 1 $GetMsg = $MQSess.AccessMessage $GetOptions = $MQSess.AccessGetMessageOptions $Queue.Get($GetMsg, $GetOptions) If $Queue.ReasonCode = 2033 Then ;When there aren't any new messages sleep for 2 seconds. Sleep(2000) Else #EndRegion Accessing MQ #Region Write File $MsgData = $GetMsg.MessageData ....
I then wrote this out to a file and attempted my SAP connection using the following code;
Dim $LoggedIn = False $oConnection = $LogonControl.NewConnection $oConnection.System = $System $oConnection.ApplicationServer = $AppServer $oConnection.SystemNumber = $SysNumb $oConnection.User = $User $oConnection.Password = $Password $oConnection.Client = $Client $oConnection.Language = $Language $LoggedIn = $oConnection.Logon(0, True) Return $LoggedIn
which resulted in failure as the SAP COM object wasn't registered on the system. After attempting to register the correct object without installing SAP GUI, I ended up with a slightly different solution for an executable supplied by SAP called startrfc.exe;
$foo = Run(@ComSpec & " /c " & $RFCExec & " -3 -h " & $AppServer & " -s " & $SysNumber & " -F " & $RFC & " -u " & $User & " -p " & $Password & " -c " & $Client & " -l " & $Language & " -E FNAME=" & $FilePath & " -E PNAME=" & $Program, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($foo) If @error Then ExitLoop ConsoleWrite($line) $LogFile = FileOpen(StringReplace($FilePath, "\In\","\Logs\"), 2) FileWrite($LogFile, $Line) FileClose($LogFile) FileMove($FilePath, StringReplace($FilePath, "\In\","\Out\")) WEnd While 1 $line = StderrRead($foo) If @error Then ExitLoop ConsoleWrite($line) $ErrFile = FileOpen(StringReplace($FilePath, "\In\","\Errors\E"), 2) FileWrite($ErrFile, $Line) FileClose($ErrFile) FileMove($FilePath, StringReplace($FilePath, "\In\","\Errors\")) WEnd
One last piece of code that you should keep in mind if you attempt this so that your program doesn't stop when a COM error is returned (MQ returns an error that indicates there is no data available on the queue as you see with the reason code check earlier);
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") ;Catch COM errors
In conclusion, I really enjoyed implementing something that'll be used for the foreseeable future at a powerful company and writing it in my favorite language. I hope you find some use in these snippets.
This will be running as a Windows Service from now on using srvany.exe.