You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by "kladas (via GitHub)" <gi...@apache.org> on 2024/07/10 06:54:56 UTC

[D] S7 error: The number of requested items doesn't match the number of returned items

GitHub user kladas created a discussion: S7 error: The number of requested items doesn't match the number of returned items

Original post: https://stackoverflow.com/questions/78724013/apache-plc4x-s7-error-the-number-of-requested-items-doesnt-match-the-number-of

Hello everyone. I want to read data from a snap7 Python simulator I have set up locally (source: https://python-snap7.readthedocs.io/en/1.3/API/server.html) with a service written in Java 17 (Spring Boot 2.5.0). My goal is to read about 1000 tags per second, or as fast as possible.

I am using PLC4X 0.12.0, and I have followed the instructions from the documentation and can read values normally up to a point. If I add more than 18 tagAddresses to the same connection, the application hangs, and I get the exception:

> o.a.p.j.s.r.protocol.S7ProtocolLogic     : org.apache.plc4x.java.api.exceptions.PlcProtocolException: The number of requested items doesn't match the number of returned items

I can solve it by breaking down my list of tag addresses in batches, and then it works, but I was wondering if I was doing something wrong, or if this is intentional, maybe the simulator is at fault (I only changed some of the values I can read). I tried changing some settings in the simulator server code to check if it restricts packets sent somehow but no luck (fiddled with max pdu length, max connections, mpi rate, max bus rate, server size etc)


This is my wireshark capture (The packets that interest are from port 1102 from which the simulator runs. For them to show as S7 I used right click on packet -> decode as ->click on current -> choose TPKT)

[wireshark1.zip](https://github.com/user-attachments/files/16156499/wireshark1.zip)

Thank you for your time and help.

My code:

```
@Component
public class S7Poller {

    private static final Logger LOG = LoggerFactory.getLogger(S7Poller.class);

    private PlcConnection connection;

    private static final LinkedHashMap<String, String> tagAddresses = new LinkedHashMap<>();

    @PostConstruct
    public void init() {
        try {
            connection = new DefaultPlcDriverManager()
               .getConnection("s7://localhost:1102?local-rack=0&local-slot=1");
        } catch (PlcConnectionException e) {
            e.printStackTrace();
            System.err.println("Error connecting to the PLC: " + e.getMessage());
        }
    }

    @Scheduled(cron = "${cron}")
    public void readPLC() {
        if (connection != null) {
            try {
                PlcReadRequest.Builder readRequest = connection.readRequestBuilder();

                readRequest.addTagAddress("boolean1", "%DB1.DBX0:0:BOOL");
                readRequest.addTagAddress("boolean2", "%DB1.DBX0:1:BOOL");
                readRequest.addTagAddress("boolean3", "%DB1.DBX0:2:BOOL");
                readRequest.addTagAddress("boolean4", "%DB1.DBX0:3:BOOL");
                readRequest.addTagAddress("boolean5", "%DB1.DBX0:4:BOOL");
                readRequest.addTagAddress("boolean6", "%DB1.DBX0:5:BOOL");
                readRequest.addTagAddress("boolean7", "%DB1.DBX0:6:BOOL");
                readRequest.addTagAddress("boolean8", "%DB1.DBX0:7:BOOL");
                readRequest.addTagAddress("sint1", "%DB1.DBB10:SINT");
                readRequest.addTagAddress("sint2", "%DB1.DBB11:SINT");
                readRequest.addTagAddress("sint3", "%DB1.DBB12:SINT");
                readRequest.addTagAddress("sint4", "%DB1.DBB13:SINT");
                readRequest.addTagAddress("usint1", "%DB1.DBB20:USINT");
                readRequest.addTagAddress("usint2", "%DB1.DBB21:USINT");
                readRequest.addTagAddress("int1", "%DB1.DBW30:INT");
                readRequest.addTagAddress("int2", "%DB1.DBW32:INT");
                readRequest.addTagAddress("int3", "%DB1.DBW34:INT");
                readRequest.addTagAddress("int4", "%DB1.DBW36:INT");
                readRequest.addTagAddress("int5", "%DB1.DBW38:INT");
                readRequest.addTagAddress("real1", "%DB1.DBD60:REAL");
                readRequest.addTagAddress("real2", "%DB1.DBD76:REAL");
                readRequest.addTagAddress("real3", "%DB1.DBD92:REAL");
                readRequest.addTagAddress("string1", "%DB1.DBX100:STRING");


                PlcReadRequest rr = readRequest.build();
                PlcReadResponse response = rr.execute().get();

                logResponses(response);

            } catch (ExecutionException | InterruptedException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
    }
 }
```

GitHub link: https://github.com/apache/plc4x/discussions/1699

----
This is an automatically sent email for dev@plc4x.apache.org.
To unsubscribe, please send an email to: dev-unsubscribe@plc4x.apache.org


Re: [D] S7 error: The number of requested items doesn't match the number of returned items

Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
GitHub user chrisdutz added a comment to the discussion: S7 error: The number of requested items doesn't match the number of returned items

PLC4Go is broken for quite some time now ... when changes to mspec were pushed for Java and nobody took care of fixing Go, we simply disabled some things in Go ... I would currently not use the S7 driver in Go (I think).

GitHub link: https://github.com/apache/plc4x/discussions/1699#discussioncomment-10010542

----
This is an automatically sent email for dev@plc4x.apache.org.
To unsubscribe, please send an email to: dev-unsubscribe@plc4x.apache.org


Re: [D] S7 error: The number of requested items doesn't match the number of returned items

Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
GitHub user chrisdutz added a comment to the discussion: S7 error: The number of requested items doesn't match the number of returned items

I just had a quick look and I can see that the request asks for 21 items, however the response only contains 20 ... so the response of PLC4X is actually correct. 

Just not sure if this is an implementation-error on your python s7 simulator (which I do suspect is the case) or if we haven't implemented a special case.

GitHub link: https://github.com/apache/plc4x/discussions/1699#discussioncomment-10006894

----
This is an automatically sent email for dev@plc4x.apache.org.
To unsubscribe, please send an email to: dev-unsubscribe@plc4x.apache.org


Re: [D] S7 error: The number of requested items doesn't match the number of returned items

Posted by "LeventSA (via GitHub)" <gi...@apache.org>.
GitHub user LeventSA added a comment to the discussion: S7 error: The number of requested items doesn't match the number of returned items

I have the same problem with kladas with real PLC S7 1200 using PLC4Go

GitHub link: https://github.com/apache/plc4x/discussions/1699#discussioncomment-10010505

----
This is an automatically sent email for dev@plc4x.apache.org.
To unsubscribe, please send an email to: dev-unsubscribe@plc4x.apache.org