Search in sources :

Example 11 with PlcSubscriptionResponse

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

the class OpcuaSubscriptionHandleTest method subscribeMultiple.

@Test
public void subscribeMultiple() throws Exception {
    String field1 = "UInteger";
    String identifier1 = UINTEGER_IDENTIFIER_READ_WRITE;
    String field2 = "Integer";
    String identifier2 = INTEGER_IDENTIFIER_READ_WRITE;
    LOGGER.info("Starting subscription {}  and {} test", field1, field2);
    // Create Subscription
    PlcSubscriptionRequest.Builder builder = opcuaConnection.subscriptionRequestBuilder();
    builder.addChangeOfStateField(field1, identifier1);
    builder.addChangeOfStateField(field2, identifier2);
    PlcSubscriptionRequest request = builder.build();
    // Get result of creating subscription
    PlcSubscriptionResponse response = request.execute().get();
    final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(field1);
    // Create handler for returned value
    subscriptionHandle.register(plcSubscriptionEvent -> {
        assert plcSubscriptionEvent.getResponseCode(field1).equals(PlcResponseCode.OK);
        assert plcSubscriptionEvent.getResponseCode(field2).equals(PlcResponseCode.OK);
    });
    // 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 12 with PlcSubscriptionResponse

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

the class OpcuaSubscriptionHandleTest method subscribeInt32.

@Test
public void subscribeInt32() throws Exception {
    String field = "Int32";
    String identifier = INT32_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 13 with PlcSubscriptionResponse

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

the class OpcuaSubscriptionHandleTest method subscribeSByte.

@Test
public void subscribeSByte() throws Exception {
    String field = "SByte";
    String identifier = SBYTE_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 14 with PlcSubscriptionResponse

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

the class OpcuaSubscriptionHandleTest method subscribeInteger.

@Test
public void subscribeInteger() throws Exception {
    String field = "Integer";
    String identifier = INTEGER_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 15 with PlcSubscriptionResponse

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

the class OpcuaSubscriptionHandleTest method subscribeByte.

@Test
public void subscribeByte() throws Exception {
    String field = "Byte";
    String identifier = BYTE_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