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);
}
}
Aggregations