Search in sources :

Example 16 with PlcSubscriptionRequest

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();
}
Also used : PlcSubscriptionRequest(org.apache.plc4x.java.api.messages.PlcSubscriptionRequest) PlcSubscriptionResponse(org.apache.plc4x.java.api.messages.PlcSubscriptionResponse) OpcuaPlcDriverTest(org.apache.plc4x.java.opcua.OpcuaPlcDriverTest)

Example 17 with PlcSubscriptionRequest

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();
}
Also used : PlcSubscriptionRequest(org.apache.plc4x.java.api.messages.PlcSubscriptionRequest) PlcSubscriptionResponse(org.apache.plc4x.java.api.messages.PlcSubscriptionResponse) OpcuaPlcDriverTest(org.apache.plc4x.java.opcua.OpcuaPlcDriverTest)

Example 18 with PlcSubscriptionRequest

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();
}
Also used : PlcSubscriptionRequest(org.apache.plc4x.java.api.messages.PlcSubscriptionRequest) PlcSubscriptionResponse(org.apache.plc4x.java.api.messages.PlcSubscriptionResponse) OpcuaPlcDriverTest(org.apache.plc4x.java.opcua.OpcuaPlcDriverTest)

Example 19 with PlcSubscriptionRequest

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();
}
Also used : PlcSubscriptionRequest(org.apache.plc4x.java.api.messages.PlcSubscriptionRequest) PlcSubscriptionResponse(org.apache.plc4x.java.api.messages.PlcSubscriptionResponse) OpcuaPlcDriverTest(org.apache.plc4x.java.opcua.OpcuaPlcDriverTest)

Example 20 with PlcSubscriptionRequest

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();
}
Also used : PlcSubscriptionRequest(org.apache.plc4x.java.api.messages.PlcSubscriptionRequest) PlcSubscriptionResponse(org.apache.plc4x.java.api.messages.PlcSubscriptionResponse) OpcuaPlcDriverTest(org.apache.plc4x.java.opcua.OpcuaPlcDriverTest)

Aggregations

PlcSubscriptionRequest (org.apache.plc4x.java.api.messages.PlcSubscriptionRequest)23 PlcSubscriptionResponse (org.apache.plc4x.java.api.messages.PlcSubscriptionResponse)23 OpcuaPlcDriverTest (org.apache.plc4x.java.opcua.OpcuaPlcDriverTest)16 PlcDriverManager (org.apache.plc4x.java.PlcDriverManager)5 PlcConnection (org.apache.plc4x.java.api.PlcConnection)5 PlcSubscriptionHandle (org.apache.plc4x.java.api.model.PlcSubscriptionHandle)5 PlcRuntimeException (org.apache.plc4x.java.api.exceptions.PlcRuntimeException)4 Scanner (java.util.Scanner)2 PlcResponseCode (org.apache.plc4x.java.api.types.PlcResponseCode)2 InfluxDBClient (com.influxdb.client.InfluxDBClient)1 WriteApi (com.influxdb.client.WriteApi)1 Point (com.influxdb.client.write.Point)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ByteBuffer (java.nio.ByteBuffer)1 Duration (java.time.Duration)1 java.util (java.util)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1