Skip to content

Conversation

@MohamedGobran
Copy link

Summary

Fixes WriteMultiVars function that incorrectly applied padding after the last data item when it had an odd number of bytes, causing write failures.

Changes

  • Fixed padding condition in WriteMultiVars to only pad between items, not after the last item
  • Added .gitignore file for common build artifacts

Problem

The original code:

if (ItemDataSize % 2 != 0)

Applied padding to ALL odd-sized items, including the last one, corrupting the packet.

Solution

if ((ItemDataSize % 2 != 0) && (c < ItemsCount - 1))

Only applies padding between items.

Protocol Reference

According to reverse-engineered S7 protocol documentation:

"The Data Item structures must begin on even bytes so if their length is an odd number and there is a following Data Item then they are padded with a zero byte."

Source: The Siemens S7 Communication - Part 2 Job Requests and Ack Data

The key requirement is padding only when there is a following Data Item - not after the last item.

Prevents adding padding byte after the final item which corrupts
the packet structure and causes write failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant