Hello Kathy and pturmel.
Thank you very much for your answers. I will take a look at the video materials you linked, but I am not sure if they help me with my specific problem. pturmel, I am aware, that you need Java development knowledge, which is not the problem. In addition, I got a sample code from one of the inductive automation Sales Engineers.
Gateway:
public class GatewayHook extends AbstractGatewayModuleHook {
private final Logger logger = LoggerFactory.getLogger(getClass());
private GatewayContext gatewayContext;
@Override
public void setup(GatewayContext gatewayContext) {
this.gatewayContext = gatewayContext;
}
@Override
public void startup(LicenseState licenseState) {
}
@Override
public void shutdown() {
}
@Override
public void configureFunctionFactory(ExpressionFunctionManager factory) {
factory.addFunction(ConvertBase.FUNC_NAME, ConvertBase.CATEGORY, new ConvertBase(gatewayContext));
}
}
Convert Base:
public class ConvertBase implements Function {
public static String FUNC_NAME = "ConvertBase";
public static String CATEGORY = "FSQL_Tools";
private GatewayContext context;
public ConvertBase(GatewayContext context) {
this.context = context;
}
public static void main(String[] args) {
System.out.println(CATEGORY);
System.out.println();
}
@Override
public QualifiedValue execute(Expression[] expressions) throws ExpressionException {
QualifiedValue from = expressions[0].execute();
QualifiedValue to = expressions[1].execute();
QualifiedValue numberToConvert = expressions[2].execute();
Quality quality = DataQuality.worstOf(from.getQuality(), to.getQuality());
quality = DataQuality.worstOf(quality, numberToConvert.getQuality());
Integer inputInt = Integer.valueOf(numberToConvert.getValue().toString(), (Integer) from.getValue());
String output = Integer.toString(inputInt, (Integer) to.getValue());
return new BasicQualifiedValue(output, quality);
}
@Override
public void initArgs(Expression[] args) {
if (!validateNumArgs(args.length)) {
throw new RuntimeException("Function '" + FUNC_NAME + "(" + getArgDocString()
+ ")' does not work with " + args.length + " arguments.");
} else {
for (int i = 0; i < args.length; i++) {
if (!validateArgType(i, args[i].getType())) {
throw new RuntimeException("Type mismatch: Argument " + i + " for function '" + FUNC_NAME
+ "(" + getArgDocString() + ")' is an invalid type.");
}
}
}
}
protected boolean validateNumArgs(int num) {
return num == 3;
}
protected boolean validateArgType(int argNum, Class<?> type) {
boolean ret = false;
switch (argNum) {
case 0:
ret = type == Integer.class;
break;
case 1:
ret = type == Integer.class;
break;
case 2:
ret = type == String.class;
break;
}
return ret;
}
@Override
public Class<?> getType() {
return String.class;
}
@Override
public String getArgDocString() {
return "from, to, numberToConvert";
}
@Override
public Function copy() {
return this;
}
@Override
public void connect(BaseContext baseContext, InteractionListener interactionListener) {
}
@Override
public void disconnect() {
}
@Override
public void startup() {
}
@Override
public void shutdown() {
}
}
However, I wonder how to test if the code works as he told me it would. This leads back to my question, How to transform his code (which I have in Eclipse) to this curious "modl" file and tell Ignition to apply the changes?
Thank you very much for your help.