use of org.apache.plc4x.java.api.messages.PlcSubscriptionRequest in project plc4x by apache.
the class OpcuaSubscriptionHandleTest method subscribeBool.
@Test
public void subscribeBool() throws Exception {
String field = "Bool";
String identifier = BOOL_IDENTIFIER_READ_WRITE;
LOGGER.info("Starting subscription {} test", field);
// Create Subscription
PlcSubscriptionRequest.Builder builder = opcuaConnection.subscriptionRequestBuilder();
builder.addChangeOfStateField(field, identifier);
PlcSubscriptionRequest request = builder.build();
// Get result of creating subscription
PlcSubscriptionResponse response = request.execute().get();
final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(field);
// Create handler for returned value
subscriptionHandle.register(plcSubscriptionEvent -> {
assert plcSubscriptionEvent.getResponseCode(field).equals(PlcResponseCode.OK);
LOGGER.info("Received a response from {} test {}", field, plcSubscriptionEvent.getPlcValue(field).toString());
});
// Wait for value to be returned from server
Thread.sleep(1200);
subscriptionHandle.stopSubscriber();
}
use of org.apache.plc4x.java.api.messages.PlcSubscriptionRequest in project plc4x by apache.
the class OpcuaSubscriptionHandleTest method subscribeDouble.
@Test
public void subscribeDouble() throws Exception {
String field = "Double";
String identifier = DOUBLE_IDENTIFIER_READ_WRITE;
LOGGER.info("Starting subscription {} test", field);
// Create Subscription
PlcSubscriptionRequest.Builder builder = opcuaConnection.subscriptionRequestBuilder();
builder.addChangeOfStateField(field, identifier);
PlcSubscriptionRequest request = builder.build();
// Get result of creating subscription
PlcSubscriptionResponse response = request.execute().get();
final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(field);
// Create handler for returned value
subscriptionHandle.register(plcSubscriptionEvent -> {
assert plcSubscriptionEvent.getResponseCode(field).equals(PlcResponseCode.OK);
LOGGER.info("Received a response from {} test {}", field, plcSubscriptionEvent.getPlcValue(field).toString());
});
// Wait for value to be returned from server
Thread.sleep(1200);
subscriptionHandle.stopSubscriber();
}
use of org.apache.plc4x.java.api.messages.PlcSubscriptionRequest in project plc4x by apache.
the class OpcuaSubscriptionHandleTest method subscribeUInt16.
@Test
public void subscribeUInt16() throws Exception {
String field = "Uint16";
String identifier = UINT16_IDENTIFIER_READ_WRITE;
LOGGER.info("Starting subscription {} test", field);
// Create Subscription
PlcSubscriptionRequest.Builder builder = opcuaConnection.subscriptionRequestBuilder();
builder.addChangeOfStateField(field, identifier);
PlcSubscriptionRequest request = builder.build();
// Get result of creating subscription
PlcSubscriptionResponse response = request.execute().get();
final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(field);
// Create handler for returned value
subscriptionHandle.register(plcSubscriptionEvent -> {
assert plcSubscriptionEvent.getResponseCode(field).equals(PlcResponseCode.OK);
LOGGER.info("Received a response from {} test {}", field, plcSubscriptionEvent.getPlcValue(field).toString());
});
// Wait for value to be returned from server
Thread.sleep(1200);
subscriptionHandle.stopSubscriber();
}
use of org.apache.plc4x.java.api.messages.PlcSubscriptionRequest in project plc4x by apache.
the class OpcuaSubscriptionHandleTest method subscribeFloat.
@Test
public void subscribeFloat() throws Exception {
String field = "Float";
String identifier = FLOAT_IDENTIFIER_READ_WRITE;
LOGGER.info("Starting subscription {} test", field);
// Create Subscription
PlcSubscriptionRequest.Builder builder = opcuaConnection.subscriptionRequestBuilder();
builder.addChangeOfStateField(field, identifier);
PlcSubscriptionRequest request = builder.build();
// Get result of creating subscription
PlcSubscriptionResponse response = request.execute().get();
final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(field);
// Create handler for returned value
subscriptionHandle.register(plcSubscriptionEvent -> {
assert plcSubscriptionEvent.getResponseCode(field).equals(PlcResponseCode.OK);
LOGGER.info("Received a response from {} test {}", field, plcSubscriptionEvent.getPlcValue(field).toString());
});
// Wait for value to be returned from server
Thread.sleep(1200);
subscriptionHandle.stopSubscriber();
}
use of org.apache.plc4x.java.api.messages.PlcSubscriptionRequest in project plc4x by apache.
the class OpcuaSubscriptionHandleTest method subscribeDoesNotExists.
@Test
public void subscribeDoesNotExists() throws Exception {
String field = "DoesNotExists";
String identifier = DOES_NOT_EXIST_IDENTIFIER_READ_WRITE;
LOGGER.info("Starting subscription {} test", field);
// Create Subscription
PlcSubscriptionRequest.Builder builder = opcuaConnection.subscriptionRequestBuilder();
builder.addChangeOfStateField(field, identifier);
PlcSubscriptionRequest request = builder.build();
// Get result of creating subscription
PlcSubscriptionResponse response = request.execute().get();
final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(field);
// Create handler for returned value
subscriptionHandle.register(plcSubscriptionEvent -> {
// This should never be called,
assert false;
LOGGER.info("Received a response from {} test {}", field, plcSubscriptionEvent.getPlcValue(field).toString());
});
// Wait for value to be returned from server
Thread.sleep(1200);
subscriptionHandle.stopSubscriber();
}
Aggregations