Skip to content

Add write methods for input buffers to SafeBufferAccess#43

Merged
thiagoralves merged 1 commit into
developmentfrom
devin/1765125902-fix-write-int-input
Dec 7, 2025
Merged

Add write methods for input buffers to SafeBufferAccess#43
thiagoralves merged 1 commit into
developmentfrom
devin/1765125902-fix-write-int-input

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Add write methods for input buffers to SafeBufferAccess

Summary

This PR adds four missing write methods to the SafeBufferAccess facade class that allow writing to PLC input buffers:

  • write_byte_input(buffer_idx, value, thread_safe=True)
  • write_int_input(buffer_idx, value, thread_safe=True)
  • write_dint_input(buffer_idx, value, thread_safe=True)
  • write_lint_input(buffer_idx, value, thread_safe=True)

These methods are required by the Modbus master plugin, which needs to write data it reads from remote slave devices INTO the PLC's input buffers. While inputs are traditionally read-only from a PLC program's perspective, external communication plugins like Modbus master legitimately need to populate these buffers.

This fixes the error: 'SafeBufferAccess' object has no attribute 'write_int_input'

The implementation delegates to the existing buffer_accessor.write_buffer() method, which already supports input buffer writes. The diff also includes formatting changes applied by pre-commit hooks (black, isort, ruff).

Review & Testing Checklist for Human

  • Test with Modbus master plugin configured to read holding registers (FC 3) from a slave device and verify the values appear correctly in PLC input buffers (%IW, %ID, %IL)
  • Verify the "SafeBufferAccess object has no attribute 'write_int_input'" error no longer appears in logs during Modbus master operation
  • Run a longer duration test (similar to the original 2-hour test) to confirm stability

Notes

The new methods follow the exact same pattern as existing write_*_output and write_*_memory methods, making this a low-risk change. The underlying buffer accessor already supported this functionality - only the facade was missing the methods.

Link to Devin run: https://app.devin.ai/sessions/c0ab2357ad504b7ba3826ec9e9a16955
Requested by: Thiago Alves (@thiagoralves)

Add write_byte_input, write_int_input, write_dint_input, and write_lint_input
methods to allow Modbus master plugin to update PLC input buffers with data
read from remote slave devices.

This fixes the 'SafeBufferAccess object has no attribute write_int_input' error
that was causing the Modbus master to fail when updating IEC input buffers for
word/dword/ldword types.

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@thiagoralves thiagoralves requested a review from Copilot December 7, 2025 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds four write methods (write_byte_input, write_int_input, write_dint_input, write_lint_input) to the SafeBufferAccess facade class to enable Modbus master plugins to write data into PLC input buffers, resolving the 'SafeBufferAccess' object has no attribute 'write_int_input' error.

Key Changes:

  • Added four new write methods for input buffers (byte, int, dint, lint)
  • Applied code formatting changes (import reordering, line length adjustments)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thiagoralves thiagoralves merged commit f62e9b6 into development Dec 7, 2025
1 check passed
@thiagoralves thiagoralves deleted the devin/1765125902-fix-write-int-input branch December 7, 2025 17:25
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.

2 participants