Skip to content

Commit

Permalink
adsGetNetIdForPLC: Solve too small buffer size for build 4026+ (#437)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
maxkofler and Max Kofler authored Dec 3, 2024
1 parent f486a72 commit 87c0681
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions pyads/pyads_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 87c0681

Please sign in to comment.