use of org.apache.plc4x.java.api.messages.PlcReadResponse 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;
}
use of org.apache.plc4x.java.api.messages.PlcReadResponse in project plc4x by apache.
the class PlcConnectionAdapterTest method checkRead.
private <T> void checkRead(MockConnection connection, PlcReadRequest request, T value) throws InterruptedException, ExecutionException {
// this is really a tests of our mock tooling but knowing it's behaving as expected
// will help identify problems in the adapter/supplier/consumer
PlcField plcField = request.getFields().get(0);
// TODO: smart value conversion
connection.setPlcValue(plcField, new PlcLong(0L));
CompletableFuture<PlcReadResponse> cf = connection.read(request);
assertThat(cf.isDone(), is(true));
PlcReadResponse response = cf.get();
// TODO: fixme
// assertThat(value, equalTo(response.getResponseItems().get(0).getValues().get(0)));
}
use of org.apache.plc4x.java.api.messages.PlcReadResponse in project plc4x by apache.
the class ManualProfinetIoTest method main.
public static void main(String[] args) throws Exception {
final PlcConnection connection = new PlcDriverManager().getConnection("profinet://192.168.24.31");
final PlcReadRequest readRequest = connection.readRequestBuilder().addItem("test", "").build();
final PlcReadResponse plcReadResponse = readRequest.execute().get();
System.out.println(plcReadResponse);
}
use of org.apache.plc4x.java.api.messages.PlcReadResponse in project plc4x by apache.
the class Plc4xReadClient method main.
public static void main(String[] args) throws Exception {
try (final PlcConnection connection = new PlcDriverManager().getConnection("plc4x://localhost?remote-connection-string=simulated%3A%2F%2Flocalhost")) {
final PlcReadRequest.Builder requestBuilder = connection.readRequestBuilder();
requestBuilder.addItem("test-BOOL", "RANDOM/foo:BOOL");
requestBuilder.addItem("test-BYTE", "RANDOM/foo:BYTE");
requestBuilder.addItem("test-WORD", "RANDOM/foo:WORD");
requestBuilder.addItem("test-DWORD", "RANDOM/foo:DWORD");
requestBuilder.addItem("test-USINT", "RANDOM/foo:USINT");
requestBuilder.addItem("test-UINT", "RANDOM/foo:UINT");
requestBuilder.addItem("test-UDINT", "RANDOM/foo:UDINT");
requestBuilder.addItem("test-ULINT", "RANDOM/foo:ULINT");
requestBuilder.addItem("test-SINT", "RANDOM/foo:SINT");
requestBuilder.addItem("test-INT", "RANDOM/foo:INT");
requestBuilder.addItem("test-DINT", "RANDOM/foo:DINT");
requestBuilder.addItem("test-LINT", "RANDOM/foo:LINT");
requestBuilder.addItem("test-REAL", "RANDOM/foo:REAL");
requestBuilder.addItem("test-LREAL", "RANDOM/foo:LREAL");
requestBuilder.addItem("test-CHAR", "RANDOM/foo:CHAR");
requestBuilder.addItem("test-WCHAR", "RANDOM/foo:WCHAR");
final PlcReadRequest readRequest = requestBuilder.build();
final PlcReadResponse readResponse = readRequest.execute().get();
System.out.println(readResponse);
}
}
use of org.apache.plc4x.java.api.messages.PlcReadResponse in project plc4x by apache.
the class SimulatedConnection method read.
@Override
public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
Map<String, ResponseItem<PlcValue>> fields = new HashMap<>();
for (String fieldName : readRequest.getFieldNames()) {
SimulatedField field = (SimulatedField) readRequest.getField(fieldName);
Optional<PlcValue> valueOptional = device.get(field);
ResponseItem<PlcValue> fieldPair;
boolean present = valueOptional.isPresent();
fieldPair = present ? new ResponseItem<>(PlcResponseCode.OK, valueOptional.get()) : new ResponseItem<>(PlcResponseCode.NOT_FOUND, null);
fields.put(fieldName, fieldPair);
}
PlcReadResponse response = new DefaultPlcReadResponse(readRequest, fields);
return CompletableFuture.completedFuture(response);
}
Aggregations