I am trying to automate IBM PComm Application using HACL Java library classes . I have succeeded in establishing connection to the pcom session as well as set /get cursor position and extracting text from the current cursor position on the application's screen. But unable to put / send text at a desired cursor position on the screen. Kindly help in resolving this issue .Please find the code for establishing connection and fetch text from the screen as below :
import java.util.Properties;
import com.ibm.eNetwork.ECL.ECLConnMgr;
import com.ibm.eNetwork.ECL.ECLConnection;
import com.ibm.eNetwork.ECL.ECLErr;
import com.ibm.eNetwork.ECL.ECLField;
import com.ibm.eNetwork.ECL.ECLFieldList;
import com.ibm.eNetwork.ECL.ECLPS;
import com.ibm.eNetwork.ECL.ECLSession;
import org.ohio.iOhioScreen;
public class Pcom {
public static void main(String[] args) throws ECLErr {
try{
System.loadLibrary("pcseclj");
Properties prop = new Properties();
// prop.put("SESSION_VT_LOCAL_ECHO ", "true");
prop.put("SESSION_HOST", "C:\\Mainframe\\A.ws"); // works OK
prop.put("SESSION_WIN_STATE", "MAX");
prop.put("SESSION_VT_KEYPAD ", "SESSION_VT_KEYPAD_APPL");
prop.put("SESSION_VT_LOCAL_ECHO", "SESSION_VT_LOCAL_ECHO_ON");
ECLSession session = new ECLSession(prop);
session.StartCommunication(); //works OK
Thread.sleep(5000);
session.connect(); //works OK
ECLFieldList fieldList = session.GetPS().GetFieldList();
session.GetPS().SetCursorPos(18, 044); //works OK
/session.GetPS().SetString("some_text"); // does not work
for(int i=0;i<fieldList.size();i++){ //works OK
//System.out.println("field ======================= "+fieldList.GetFirstField(i).getAttribute());
ECLPS ps=session.GetPS();
System.out.println(session.GetName()); //works Ok
session.GetPS().SetCursorPos(17, 44); //works OK
session.GetPS().SendKeys("some_text",17,44); // does not work ,17,44 are co ordinate positions pn screen
System.out.println(session.GetConnType()); // works ok
ps.SendKeys("some_text"); //does not work
/* ------------ does not work-------------
fieldList.FindField(17, 44).SetText("some_text");
fieldList.FindField(17, 44).SetString("some_text");
fieldList.FindField(18, 44).setString("some_text");
*/
System.out.println(fieldList.FindField(17, 44).GetLength()); // works ok
System.out.println(fieldList.FindField(17, 28).getString()); //works ok
}
catch(Exception e)
{
System.out.println(e);
}
}
}
I had similar issue before while automating PCOMM with Cucumber to make some automated regression test framework "middleware" for green screen in BDD style.
Thing is that SetCursorPos does not send new cursor position to the Host System (we use IBM i). Telnet5250 protocol is quite complicated but in few words you have two separate buffers - one on the client system (Terminal Emulator) and second on the Host System (telnet server). Usually they are sychronized, but in some circumstances they are not which leads to undefined behavior.
Litle hack is to send up and down arrow keys like this:
This will force PComm to send new cursor position to server and sync screen buffers.