Search in sources :

Example 1 with Callback

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) {
// }
}
Also used : Callback(org.apache.plc4x.java.canopen.listener.Callback) PlcReadRequest(org.apache.plc4x.java.api.messages.PlcReadRequest) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) PlcConnection(org.apache.plc4x.java.api.PlcConnection) CANOpenFrame(org.apache.plc4x.java.canopen.readwrite.CANOpenFrame)

Aggregations

PlcDriverManager (org.apache.plc4x.java.PlcDriverManager)1 PlcConnection (org.apache.plc4x.java.api.PlcConnection)1 PlcReadRequest (org.apache.plc4x.java.api.messages.PlcReadRequest)1 Callback (org.apache.plc4x.java.canopen.listener.Callback)1 CANOpenFrame (org.apache.plc4x.java.canopen.readwrite.CANOpenFrame)1