Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
0.8.0
-
None
-
None
-
Environment independent
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
- is duplicated by
-
PLC4X-291 DefaultPlcSubscriptionField cannot be cast to class OpcuaField
- Resolved