Skip to content

Commit

Permalink
adsGetNetIdForPLC: Solve too small buffer size for build 4026+
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Max Kofler committed Dec 2, 2024
1 parent f486a72 commit 57e3394
Showing 1 changed file with 4 additions and 2 deletions.
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 57e3394

Please sign in to comment.