Search in sources :

Example 1 with CANOpenPDO

use of org.apache.plc4x.java.canopen.readwrite.CANOpenPDO in project plc4x by apache.

the class CANOpenProtocolLogic method writeInternally.

private void writeInternally(DefaultPlcWriteRequest writeRequest, CANOpenPDOField field, CompletableFuture<PlcWriteResponse> response) {
    PlcValue writeValue = writeRequest.getPlcValues().get(0);
    try {
        String fieldName = writeRequest.getFieldNames().iterator().next();
        WriteBufferByteBased writeBuffer = new WriteBufferByteBased(DataItem.getLengthInBytes(writeValue, field.getCanOpenDataType(), writeValue.getLength()), ByteOrder.LITTLE_ENDIAN);
        DataItem.staticSerialize(writeBuffer, writeValue, field.getCanOpenDataType(), writeValue.getLength(), ByteOrder.LITTLE_ENDIAN);
        final CANOpenPDOPayload payload = new CANOpenPDOPayload(new CANOpenPDO(writeBuffer.getData()));
        context.sendToWire(new CANOpenFrame((short) field.getNodeId(), field.getService(), payload));
        response.complete(new DefaultPlcWriteResponse(writeRequest, Collections.singletonMap(fieldName, PlcResponseCode.OK)));
    } catch (Exception e) {
        response.completeExceptionally(e);
    }
}
Also used : PlcValue(org.apache.plc4x.java.api.value.PlcValue) CANOpenPDO(org.apache.plc4x.java.canopen.readwrite.CANOpenPDO) DefaultPlcWriteResponse(org.apache.plc4x.java.spi.messages.DefaultPlcWriteResponse) CANOpenPDOPayload(org.apache.plc4x.java.canopen.readwrite.CANOpenPDOPayload) CANOpenAbortException(org.apache.plc4x.java.canopen.transport.CANOpenAbortException) PlcRuntimeException(org.apache.plc4x.java.api.exceptions.PlcRuntimeException) CANOpenFrame(org.apache.plc4x.java.canopen.readwrite.CANOpenFrame)

Aggregations

PlcRuntimeException (org.apache.plc4x.java.api.exceptions.PlcRuntimeException)1 PlcValue (org.apache.plc4x.java.api.value.PlcValue)1 CANOpenFrame (org.apache.plc4x.java.canopen.readwrite.CANOpenFrame)1 CANOpenPDO (org.apache.plc4x.java.canopen.readwrite.CANOpenPDO)1 CANOpenPDOPayload (org.apache.plc4x.java.canopen.readwrite.CANOpenPDOPayload)1 CANOpenAbortException (org.apache.plc4x.java.canopen.transport.CANOpenAbortException)1 DefaultPlcWriteResponse (org.apache.plc4x.java.spi.messages.DefaultPlcWriteResponse)1