use of org.apache.plc4x.java.canopen.listener.Callback in project plc4x by apache.
the class Main method main.
public static void main(String[] args) throws Exception {
PlcDriverManager driverManager = new PlcDriverManager();
CANOpenDriverContext.CALLBACK.addCallback(new Callback() {
@Override
public void receive(CANOpenFrame frame) {
// System.err.println("Received frame " + frame);
}
});
PlcConnection connection = driverManager.getConnection("canopen:javacan://vcan0?nodeId=11");
// UUID.randomUUID().toString();
String value = "abcdef";
CompletableFuture<? extends PlcWriteResponse> response = connection.writeRequestBuilder().addItem("foo", "SDO:13:0x2000/0x0:VISIBLE_STRING", value).build().execute();
response.whenComplete((writeReply, writeError) -> {
System.out.println("====================================");
if (writeError != null) {
System.out.println("Error ");
writeError.printStackTrace();
} else {
System.out.println("Result " + writeReply.getResponseCode("foo") + " " + value);
PlcReadRequest.Builder builder = connection.readRequestBuilder();
builder.addItem("foo", "SDO:13:0x2000/0x0:VISIBLE_STRING");
CompletableFuture<? extends PlcReadResponse> future = builder.build().execute();
future.whenComplete((readReply, readError) -> {
System.out.println("====================================");
if (readError != null) {
System.out.println("Error ");
readError.printStackTrace();
} else {
System.out.println("Result " + readReply.getString("foo"));
}
});
}
});
// while (true) {
// }
}
Aggregations