Hi all,
I made a method in the InstallationContribution that fetches the custom PMC functions a user implements and adds them as functions in the functionmodel and the urscript. I tested it and it worked good. After this I made a few extra functions in a Python backend which is in the same project. When I recompiled this it seems the Scripsender & Scriptcommand classes seem to have stopped working.
I want to make sure I am not missing something in my code? Am I using the Scriptcommand and sender correctly?
Here is my crude method:
public void addFunctionsForAssignment() {
SQLite sql = new SQLite();
//selects all the columns from read table and puts it in seperate arraylists
ArrayList<String> listForNames = sql.selectColumnFromTable(getFileName(), Tables.READ, "pmc_name", "string");
ArrayList<String> listForAddressTypes = sql.selectColumnFromTable(getFileName(), Tables.READ, "address_type", "string");
ArrayList<String> listForDataTypes = sql.selectColumnFromTable(getFileName(), Tables.READ, "data_type", "string");
ArrayList<String> listForDataNumbers = sql.selectColumnFromTable(getFileName(), Tables.READ, "data_number", "string");
FunctionModel functionModel = apiProvider.getInstallationAPI().getFunctionModel();
final ScriptCommand executeCommand = new ScriptCommand();
final ScriptSender sender = new ScriptSender();
//for each name retrieved
//loop below adds all the pmc functions defined in installpage as a function inside the script
//this allows it to be used as an assignment in the program tree
//example: var_1 = open_door()
for (int i = 0; i <= (listForNames.size()-1); i++){
//assigns the values that belong together to the String vars
String nameFromList = listForNames.get(i);
String addressTypeFromList = listForAddressTypes.get(i);
String dataTypeFromList = listForDataTypes.get(i);
String dataNumbersFromList = listForDataNumbers.get(i);
System.out.println("JULI1"+nameFromList);
nameFromList = nameFromList.replace(":", "_"); //need to replace WR:EXAMPLE to WR_EXAMPLE or else syntax error
System.out.println("JULI2"+nameFromList);;
nameFromList = nameFromList.replace(" ", "_"); //need to replace WR:EXAMPLE to WR_EXAMPLE or else syntax error
System.out.println("JULI3"+nameFromList);;
String functionName = String.format("def %s():", nameFromList); // results in def RD_EXAMPLE():
String backendCall = String.format("\t return cnc.rdpmc(%s, %s, %s)", addressTypeFromList, dataTypeFromList, dataNumbersFromList);
executeCommand.setAsPrimaryProgram();
executeCommand.appendLine(functionName);
executeCommand.appendLine(backendCall);
executeCommand.appendLine("end");
sender.sendScriptCommand(executeCommand); //adds the lines from executeCommand to the urscript
System.out.println("JULI4"+functionName);
System.out.println("JULI5"+backendCall);
System.out.println("JULI6"+executeCommand);
//created the following:
//def RD_EXAMPLE():
// return cnc.rdpmc(atype, dtype, dnumber)
//end
try {
functionModel.addFunction(nameFromList); //adds the function to the functionmodel
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
//adds the lines to the executeCommand
executeCommand.appendLine("def readpmc(address, dataType, dataNumber):"); // Like ScriptWriter writer.appendline()
executeCommand.appendLine("\t return cnc.rdpmc(address, dataType, dataNumber)");
executeCommand.appendLine("end");
sender.sendScriptCommand(executeCommand); //adds the lines from executeCommand to the urscript
try {
System.out.println("Generating function!");
functionModel.addFunction("readpmc", "address", "dataType", "dataNumber");
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}