Search in sources :

Example 1 with CANOpenSDOField

use of org.apache.plc4x.java.canopen.field.CANOpenSDOField in project plc4x by apache.

the class CANOpenProtocolLogic method read.

public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
    CompletableFuture<PlcReadResponse> response = new CompletableFuture<>();
    if (readRequest.getFieldNames().size() != 1) {
        response.completeExceptionally(new IllegalArgumentException("SDO requires single field to be read"));
        return response;
    }
    PlcField field = readRequest.getFields().get(0);
    if (!(field instanceof CANOpenField)) {
        response.completeExceptionally(new IllegalArgumentException("Only CANOpenField instances are supported"));
        return response;
    }
    if (!(field instanceof CANOpenSDOField)) {
        response.completeExceptionally(new IllegalArgumentException("Only CANOpenSDOField instances are supported"));
        return response;
    }
    ;
    readInternally(readRequest, (CANOpenSDOField) field, response);
    return response;
}
Also used : PlcReadResponse(org.apache.plc4x.java.api.messages.PlcReadResponse) DefaultPlcReadResponse(org.apache.plc4x.java.spi.messages.DefaultPlcReadResponse) CompletableFuture(java.util.concurrent.CompletableFuture) CANOpenField(org.apache.plc4x.java.canopen.field.CANOpenField) CANOpenSDOField(org.apache.plc4x.java.canopen.field.CANOpenSDOField) PlcField(org.apache.plc4x.java.api.model.PlcField)

Example 2 with CANOpenSDOField

use of org.apache.plc4x.java.canopen.field.CANOpenSDOField in project plc4x by apache.

the class CANOpenProtocolLogic method write.

public CompletableFuture<PlcWriteResponse> write(PlcWriteRequest writeRequest) {
    CompletableFuture<PlcWriteResponse> response = new CompletableFuture<>();
    if (writeRequest.getFieldNames().size() != 1) {
        response.completeExceptionally(new IllegalArgumentException("You can write only one field at the time"));
        return response;
    }
    PlcField field = writeRequest.getFields().get(0);
    if (!(field instanceof CANOpenField)) {
        response.completeExceptionally(new IllegalArgumentException("Only CANOpenField instances are supported"));
        return response;
    }
    if (field instanceof CANOpenSDOField) {
        writeInternally((DefaultPlcWriteRequest) writeRequest, (CANOpenSDOField) field, response);
        return response;
    }
    if (field instanceof CANOpenPDOField) {
        writeInternally((DefaultPlcWriteRequest) writeRequest, (CANOpenPDOField) field, response);
        return response;
    }
    response.completeExceptionally(new IllegalArgumentException("Only CANOpenSDOField instances are supported"));
    return response;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) CANOpenPDOField(org.apache.plc4x.java.canopen.field.CANOpenPDOField) CANOpenField(org.apache.plc4x.java.canopen.field.CANOpenField) CANOpenSDOField(org.apache.plc4x.java.canopen.field.CANOpenSDOField) PlcField(org.apache.plc4x.java.api.model.PlcField) PlcWriteResponse(org.apache.plc4x.java.api.messages.PlcWriteResponse) DefaultPlcWriteResponse(org.apache.plc4x.java.spi.messages.DefaultPlcWriteResponse)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)2 PlcField (org.apache.plc4x.java.api.model.PlcField)2 CANOpenField (org.apache.plc4x.java.canopen.field.CANOpenField)2 CANOpenSDOField (org.apache.plc4x.java.canopen.field.CANOpenSDOField)2 PlcReadResponse (org.apache.plc4x.java.api.messages.PlcReadResponse)1 PlcWriteResponse (org.apache.plc4x.java.api.messages.PlcWriteResponse)1 CANOpenPDOField (org.apache.plc4x.java.canopen.field.CANOpenPDOField)1 DefaultPlcReadResponse (org.apache.plc4x.java.spi.messages.DefaultPlcReadResponse)1 DefaultPlcWriteResponse (org.apache.plc4x.java.spi.messages.DefaultPlcWriteResponse)1