From 87c0681978a6c5e5380e506fb93f6c64c34af668 Mon Sep 17 00:00:00 2001 From: Max Kofler Date: Tue, 3 Dec 2024 13:12:24 +0100 Subject: [PATCH] adsGetNetIdForPLC: Solve too small buffer size for build 4026+ (#437) * adsGetNetIdForPLC: Solve too small buffer size for build 4026+ Some PLCs that run TwinCAT >4026 send more bytes than expected when requesting the AMS NetID. This patch allocates more buffer size to the response to solve an error where the function would error out for no appearant reason. * Add changelog entry for 57e3394 --------- Co-authored-by: Max Kofler --- CHANGELOG.md | 6 +++++- pyads/pyads_ex.py | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60d77d7..03c81fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added * [#384](https://github.com/stlehmann/pyads/pull/384) Enable processing of nested structures +### Changed + +* [#437](https://github.com/stlehmann/pyads/pull/437) Solve issue of too little buffer space allocated to receive for automatic AMS NetID query + ## 3.4.2 ### Changed -* [#402](https://github.com/stlehmann/pyads/pull/402) Universal DLL path for TwinCat 4026 and 4024 +* [#402](https://github.com/stlehmann/pyads/pull/402) Universal DLL path for TwinCat 4026 and 4024 ## 3.4.1 diff --git a/pyads/pyads_ex.py b/pyads/pyads_ex.py index 6a7e445..575a2ea 100644 --- a/pyads/pyads_ex.py +++ b/pyads/pyads_ex.py @@ -394,8 +394,10 @@ def adsGetNetIdForPLC(ip_address: str) -> str: data_header += struct.pack(">4s", b"\x00\x00\x00\x00") # Block of unknown data, addr = send_raw_udp_message( - ip_address, data_header, 395 - ) # PLC response is 395 bytes long + ip_address, data_header, 398 + ) + # PLC response should be 395 bytes long, but some PLCs running build 4026+ + # respond with more bytes, so this takes care of that rcvd_packet_header = data[ 0:12