Search in sources :

Example 16 with PlcSubscriptionResponse

use of org.apache.plc4x.java.api.messages.PlcSubscriptionResponse in project plc4x by apache.

the class OpcuaSubscriptionHandleTest method subscribeInt16.

@Test
public void subscribeInt16() throws Exception {
    String field = "Int16";
    String identifier = INT16_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 PlcSubscriptionResponse

use of org.apache.plc4x.java.api.messages.PlcSubscriptionResponse 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 18 with PlcSubscriptionResponse

use of org.apache.plc4x.java.api.messages.PlcSubscriptionResponse 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 19 with PlcSubscriptionResponse

use of org.apache.plc4x.java.api.messages.PlcSubscriptionResponse 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 20 with PlcSubscriptionResponse

use of org.apache.plc4x.java.api.messages.PlcSubscriptionResponse 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)

Aggregations

PlcSubscriptionResponse (org.apache.plc4x.java.api.messages.PlcSubscriptionResponse)27 PlcSubscriptionRequest (org.apache.plc4x.java.api.messages.PlcSubscriptionRequest)23 OpcuaPlcDriverTest (org.apache.plc4x.java.opcua.OpcuaPlcDriverTest)16 PlcConnection (org.apache.plc4x.java.api.PlcConnection)8 PlcSubscriptionHandle (org.apache.plc4x.java.api.model.PlcSubscriptionHandle)6 PlcDriverManager (org.apache.plc4x.java.PlcDriverManager)5 PlcRuntimeException (org.apache.plc4x.java.api.exceptions.PlcRuntimeException)4 ResponseItem (org.apache.plc4x.java.spi.messages.utils.ResponseItem)3 PlcStruct (org.apache.plc4x.java.spi.values.PlcStruct)3 File (java.io.File)2 URL (java.net.URL)2 Scanner (java.util.Scanner)2 PlcResponseCode (org.apache.plc4x.java.api.types.PlcResponseCode)2 DefaultPlcSubscriptionResponse (org.apache.plc4x.java.spi.messages.DefaultPlcSubscriptionResponse)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