Uploaded image for project: 'Apache PLC4X'
  1. Apache PLC4X
  2. PLC4X-291

DefaultPlcSubscriptionField cannot be cast to class OpcuaField

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.8.0
    • 0.9.0
    • API
    • None

    Description

      @Test
      public void shoudlWorkWithSubscriptionRequest() throws PlcConnectionException, InterruptedException {
      
        var plcConnection = new PlcDriverManager().getConnection("opcua:tcp://localhost:62541/Quickstarts/ReferenceServer")
            
        // Connection OK : lets subscribe
        var subBuilder = plcConnection.subscriptionRequestBuilder();
      
        subBuilder.addChangeOfStateField("machine1", "ns=2;s=Fabrication_Id_1:STRING");
      
        var subscriptionRequest = subBuilder.build();
        var subResponse = subscriptionRequest.execute();
      
        subResponse.whenComplete(
            (response, ex) -> {
                System.out.println("Result : "+ response + " - "+ex);
                
              for (String subscriptionName : response.getFieldNames()) {
                final var subscriptionHandle = response.getSubscriptionHandle(subscriptionName);
                subscriptionHandle.register(System.out::println);
              }
            });
        
        Thread.sleep(1000000000);
      }
      

      The code above always return this specific exception in the whenComplete callback:

      java.lang.ClassCastException: class org.apache.plc4x.java.spi.model.DefaultPlcSubscriptionField cannot be cast to class org.apache.plc4x.java.opcua.protocol.OpcuaField (org.apache.plc4x.java.spi.model.DefaultPlcSubscriptionField and org.apache.plc4x.java.opcua.protocol.OpcuaField are in unnamed module of loader 'app')
      

       

      Dependencies used in this maven project are :

      <dependency> <groupId>org.apache.plc4x</groupId> <artifactId>plc4j-api</artifactId> <version>0.8.0</version> </dependency> <dependency> <groupId>org.apache.plc4x</groupId> <artifactId>plc4j-driver-opcua</artifactId> <version>0.8.0</version> <scope>runtime</scope> </dependency>
      

       

      Diagnosis :

      It appears that DefaultPlcSubscriptionField is composed of a PlcField/OpcuaField on api side, but expected as an direct OpcuaField on driver side.
      I do not have the general knowledge of the design of this repository so i'm not confident enough to propose you a pull request.

      Fix proposal :
      -> Add already existing getField from DefaultPlcSubscriptionField in PlcSubscriptionField interface and assume the composition strategy for PlcSubscriptionField + Modify OpcuaTcpPlcConnection to get real field from this new method ( may have an impact on other driver implementation too !)

      I stay available to give you some more information.

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ASouquieres Souquières Adam
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: