Hey Chris,
thanks for the hint... I did so, you can find the branch now here
https://github.com/apache/incubator-plc4x/tree/opm-plcentitymanager
And I noticed that it ould perhaps be nice to give TL;DR; Demo on the List.
So a simple usage example (can be found in the PlcEntityManagerTest) would be
to call
PlcEntityManager manager = new PlcEntityManager();
ConnectedEntity connect = manager.connect(ConnectedEntity.class);
See below for the POJO.
Then, all subsequent calls to one of the getters of the POJO result in fetching
the value from the PLC.
All calls to any other method of the POJO first, fetch all values from the PLC
and update the fields and then proceed the method.
So, e.g. the call
connect.toString()
would print all current values from the mapped fields.
Best
Julian
Appendix: The ConnectedEntity POJO looks like that:
@PlcEntity("s7://localhost:5555/0/0")
public static class ConnectedEntity {
@PlcField("%DB1.DW111:BYTE")
private byte byteVar;
@PlcField("%DB1.DW111:SHORT")
private short shortVar;
@PlcField("%DB1.DW111:INT")
private int intVar;
@PlcField("%DB1.DW111:LONG")
private long longVar;
@PlcField("%DB1.DW111:STRING")
private Long boxedLongVar;
@PlcField("%DB1.DW111:STRING")
private String stringVar;
public ConnectedEntity() {
// Default
}
public byte getByteVar() {
return byteVar;
}
public short getShortVar() {
return shortVar;
}
public int getIntVar() {
return intVar;
}
public long getLongVar() {
return longVar;
}
public String getStringVar() {
return stringVar;
}
public void someMethod() {
System.out.println("I do nothing");
}
@Override
public String toString() {
return "ConnectedEntity{" +
"byteVar=" + byteVar +
", shortVar=" + shortVar +
", intVar=" + intVar +
", longVar=" + longVar +
", boxedLongVar=" + boxedLongVar +
", stringVar='" + stringVar + '\'' +
'}';
}
}
Am 04.10.18, 09:19 schrieb "Christofer Dutz" <[email protected]>:
Hi Julian,
could you please push your branch to the plc4x repo too (You are a
committer now) ... cause this simplifies any form of "compare with branch"
thing ;-)
Chris
Am 04.10.18, 08:42 schrieb "Julian Feinauer" <[email protected]>:
Hey all,
I just finished the first (working) implementation of the
Object-Plc-Mapping (OPM).
This is a JPA Like functionality on top of plc4x which allows to issue
requests against plc4x by calling Methods on POJOs!
Basically, it uses 3 classes.
* PlcEntityManager: This is the main class. A call on read(…) or
connect(…) does all the necessary magic
* PlcEntity (Annotation): A Pojo needs this annotation to be used
with read(…) or connect(…) above
* PlcField (Annotation): Fields in the Pojo that are annotated with
this field are fetched from the plc
Some simple tests (with mocking) can be found in PlcEntityManagerTest.
I would be really happy for some feedback on the basic semantics (which
annotations, where to put them, …) or even some testing.
If the feedback on this is positive I would like issue a PR for this.
Current Code can be found in my Repo in the opm-plcentitymanager branch
under
https://github.com/JulianFeinauer/incubator-plc4x/tree/opm-plcentitymanager
Best
Julian