Apache PLC4X S7 error: The number of requested items doesn’t match the number of returned items

I am a bit new in PLC4X and programming in general. 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 in 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 or maybe the simulator is at fault (I only changed some of the values I can read). Thank you

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);
            }
        }
    }

    private void logResponses(PlcReadResponse response) {
        LOG.info("boolean1: " + response.getBoolean("boolean1"));
        LOG.info("boolean2: " + response.getBoolean("boolean2"));
        LOG.info("boolean3: " + response.getBoolean("boolean3"));
        LOG.info("boolean4: " + response.getBoolean("boolean4"));
        LOG.info("boolean5: " + response.getBoolean("boolean5"));
        LOG.info("boolean6: " + response.getBoolean("boolean6"));
        LOG.info("boolean7: " + response.getBoolean("boolean7"));
        LOG.info("boolean8: " + response.getBoolean("boolean8"));
        LOG.info("sint1: " + response.getInteger("sint1"));
        LOG.info("sint2: " + response.getInteger("sint2"));
        LOG.info("sint3: " + response.getInteger("sint3"));
        LOG.info("sint4: " + response.getInteger("sint4"));
        LOG.info("usint1: " + response.getInteger("usint1"));
        LOG.info("usint2: " + response.getInteger("usint2"));
        LOG.info("int1: " + response.getInteger("int1"));
        LOG.info("int2: " + response.getInteger("int2"));
        LOG.info("int3: " + response.getInteger("int3"));
        LOG.info("int4: " + response.getInteger("int4"));
        LOG.info("int5: " + response.getInteger("int5"));
        LOG.info("real1: " + response.getFloat("real1"));
        LOG.info("real2: " + response.getFloat("real2"));
        LOG.info("real3: " + response.getFloat("real3"));
        LOG.info("string1: " + response.getString("string1"));
    }

New contributor

deleteJavascript is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật