plc4x: [Bug]: [PLC4J] [EtherNet/IP] All values read are null for Allen-Bradley PLC with EtherNet/IP or Logix

What happened?

I wrote two programs according to the documentation on the official website of PLC4X to read Allen Bradley PLC, model Logix5571, but all the values read were null.

Here is the code. The result is that all four tag values in asPlcValue are null.

code for EtherNet/IP protocol:

    String connectionString = "eip://192.168.0.2:44818?slot=0&bigEndian=false";

    try (PlcConnection plcConnection = PlcDriverManager.getDefault().getConnectionManager().getConnection(connectionString)) {
        final PlcReadRequest.Builder readrequest = plcConnection.readRequestBuilder();

    //(3.1)
        readrequest.addTagAddress("tag1", "%A:DINT");
        readrequest.addTagAddress("tag2", "%B:INT");
        readrequest.addTagAddress("tag3", "%C:SINT");
        readrequest.addTagAddress("tag4", "%D:REAL");

        //(3.2)
        final PlcReadRequest rr = readrequest.build();
        //(3.3)
        final PlcReadResponse szlresponse = rr.execute().get();

        PlcValue asPlcValue = szlresponse.getAsPlcValue();

    } catch (PlcConnectionException e) {
        throw new RuntimeException(e);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

code for Logix protocol:

   String connectionString = "logix://192.168.0.2:44818?slot=0&bigEndian=false";

    try (PlcConnection plcConnection = PlcDriverManager.getDefault().getConnectionManager().getConnection(connectionString)) {
        PlcConnectionMetadata metadata = plcConnection.getMetadata();
        final PlcReadRequest.Builder readrequest = plcConnection.readRequestBuilder();

        //(3.1)
        readrequest.addTagAddress("tag1", "A:DINT");
        readrequest.addTagAddress("tag2", "B:INT");
        readrequest.addTagAddress("tag3", "C:SINT");
        readrequest.addTagAddress("tag4", "D:REAL");

        //(3.2)
        final PlcReadRequest rr = readrequest.build();
        //(3.3)
        final PlcReadResponse szlresponse = rr.execute().get();
        //(3.4)
        PlcValue asPlcValue = szlresponse.getAsPlcValue();
        log.info("Tags: " + asPlcValue);
    } catch (PlcConnectionException e) {
        throw new RuntimeException(e);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }`

here is the tags:

tags

Version

v0.12.0

Programming Languages

  • plc4j
  • plc4go
  • plc4c
  • plc4net

Protocols

  • AB-Ethernet
  • ADS /AMS
  • BACnet/IP
  • CANopen
  • DeltaV
  • DF1
  • EtherNet/IP
  • Firmata
  • KNXnet/IP
  • Modbus
  • OPC-UA
  • S7

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 52 (26 by maintainers)

Commits related to this issue

Most upvoted comments

I found that using version 0.11.0 to read data is slow, and the duration of returning data increases with the number of points. Then, I found the problem in issue #1373, so I rewrote the method. Now, reading values is relatively normal.

private CompletableFuture<PlcReadResponse> readWithoutMessageRouter(PlcReadRequest readRequest) {
   CompletableFuture<PlcReadResponse> future = new CompletableFuture<>();
   Map<String, ResponseItem<PlcValue>> values = new HashMap<>();
   List<CompletableFuture<Void>> internalFutures = new ArrayList<>();
   PathSegment classSegment = new LogicalSegment(new ClassID((byte) 0, (short) 6));
   PathSegment instanceSegment = new LogicalSegment(new InstanceID((byte) 0, (short) 1));

   DefaultPlcReadRequest request = (DefaultPlcReadRequest) readRequest;
   for (String tagName : request.getTagNames()) {
       CompletableFuture<Void> internalFuture = new CompletableFuture<>();
       RequestTransactionManager.RequestTransaction transaction = tm.startRequest();
       EipTag eipTag = (EipTag) request.getTag(tagName);
       String tag = eipTag.getTag();

       try {
           CipReadRequest req = new CipReadRequest(toAnsi(tag), 1);
           CipUnconnectedRequest requestItem = new CipUnconnectedRequest(classSegment, instanceSegment, req, (byte) this.configuration.getBackplane(), (byte) this.configuration.getSlot());
           List<TypeId> typeIds = new ArrayList<>(2);
           typeIds.add(nullAddressItem);
           typeIds.add(new UnConnectedDataItem(requestItem));
           CipRRData pkt = new CipRRData(sessionHandle, CIPStatus.Success.getValue(), DEFAULT_SENDER_CONTEXT, 0L, 0L, 0, typeIds);

           transaction.submit(() -> context.sendRequest(pkt)
                   .expectResponse(EipPacket.class, REQUEST_TIMEOUT)
                   .onTimeout(future::completeExceptionally)
                   .onError((p, e) -> future.completeExceptionally(e))
                   .check(p -> p instanceof CipRRData)
                   .unwrap(p -> (CipRRData) p)
                   .check(p -> p.getSessionHandle() == sessionHandle)
                   .handle(p -> {
                       List<TypeId> responseTypeIds = p.getTypeIds();
                       UnConnectedDataItem dataItem = (UnConnectedDataItem) responseTypeIds.get(1);
                       Map<String, ResponseItem<PlcValue>> readResponse = decodeSingleReadResponse(dataItem.getService(), tagName, eipTag);
                       values.putAll(readResponse);
                       internalFuture.complete(null);
                       transaction.endRequest();
                   }));
           internalFutures.add(internalFuture);
       } catch (SerializationException e) {
           future.completeExceptionally(e);
       }
   }

   CompletableFuture.allOf(internalFutures.toArray(new CompletableFuture[0])).thenRun(() -> {
       PlcReadResponse readResponse = new DefaultPlcReadResponse(readRequest, values);
       future.complete(readResponse);
   }).exceptionally(e -> {
       future.completeExceptionally(e);
       return null;
   });

   return future;
}

So if I look at your code, omit the “%” and the datatypes. Just “A”, “B”, “C”, or “D” should be enough.