0

i am using a third party library to create software for a java controlled PLC.

the 3th party library requires you to define all needed Inputs and outputs etc. Then you click generate and it will generate a massive load of getters/setters and properties that use the library.

the problem is that everything is generated in one single java class. and it looks very messy.

for example (it looks something like this, tried to keep it very simple)

TestClass.Java ->

public class TestClass extends BComponent implements Runnable {

/**AUTO GENERATED IO's*/
public static final Property bBool_1 = newProperty(//settings)
public boolean Get_bool_1(){//return value }    
public boolean Set_bool_1(){//set value}

public static final Property bBool_2 = newProperty(//settings)
public boolean Get_bool_2(){//return value }    
public boolean Set_bool_2(){//set value}

/**END OF AUTO GENERATED CODE*/

/**The above will repeats a lot depending on how many in/outputs you defined*/

public void run(){
//below all these IO's the code is written (which looks like a mess)
    }
}

What i would like to do is to split up all IO (getters and setters etc) and put them in a different class. I tried to do it with a Interface but i got a bit lost as i am still new to java.

example:

IoInterface.java -> (where all auto generated IO needs to go)

public class IoInterface extends BComponent implements Runnable {

/**AUTO GENERATED IO's*/
public static final Property bBool_1 = newProperty(//settings)
public boolean Get_bool_1(){//return value }    
public boolean Set_bool_1(){//set value}

public static final Property bBool_2 = newProperty(//settings)
public boolean Get_bool_2(){//return value }    
public boolean Set_bool_2(){//set value}

/**END OF AUTO GENERATED CODE*/
}

TestClass.Java -> (where all logic will be implemented)

public class TestClass extends BComponent implements Runnable{

public void run(){

if (getBool_xx){ 
//doSomething
        }
    }
}

i cant explain it better then that the code has to think its on the came class so i dont have to make an instance and call each individual like this : "instanceOfIoInterface.getBool_xx"

In the end i want to acces both classes IoInterface -> testclass and testClass->IoInterface

any help would be appreciated!

mittens13
  • 17
  • 7
  • 4
    make sure the method you want to call is static. That way, no instance is needed. – Stultuske Jan 28 '21 at 14:01
  • 1
    Maybe the thirdparty library has some configuration parameter to generate interfaces like that? If you make it manually, the next time you (or maybe your colleague) will re-run the thirdparty it will become a mess to understand how to apply the new change, The best thing IMO is generating the source code during the build process before the regular compilation takes place. But its an opinion of SW engineer, I know nothing about PLCs :) – Mark Bramnik Jan 28 '21 at 14:08
  • thanks for the reply ill start reading on static methods ! @MarkBramnik youre probably right about that, the problem is that nearly no documentation is available about the library so its mostly trial and error for now – mittens13 Jan 28 '21 at 14:12

0 Answers0