Skip to content

Implement complete pymcprotocol Type3E API compatibility#13

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/complete-pymcprotocol-api
Draft

Implement complete pymcprotocol Type3E API compatibility#13
Copilot wants to merge 4 commits intomainfrom
copilot/complete-pymcprotocol-api

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 30, 2025

The wrapper provided only simplified abstractions (read_data(), write_data(), disconnect()) instead of the full pymcprotocol Type3E API, limiting its utility as a proper wrapper library.

Changes

API Implementation

  • Added all 19 pymcprotocol Type3E methods to both Client and MockClient:
    • Batch operations: batchread_wordunits(), batchread_bitunits(), batchwrite_wordunits(), batchwrite_bitunits()
    • Random access: randomread(), randomwrite(), randomwrite_bitunits()
    • System operations: read_cputype(), echo_test(), setaccessopt()
    • Remote control: remote_run(), remote_stop(), remote_pause(), remote_reset(), remote_latchclear(), remote_unlock(), remote_lock()
    • Connection: close() as pymcprotocol-compatible alias

Implementation Details

  • Client delegates to external pymcprotocol.Type3E when available, falls back to mock mode otherwise
  • Legacy read_data()/write_data() now use batchread_wordunits()/batchwrite_wordunits() for external clients
  • Address range validation enforces 24-bit device numbers (0-16777215)

Testing & Documentation

  • 15 new tests covering all pymcprotocol methods (23 total, all passing)
  • Updated README with complete API reference
  • Added examples/pymcprotocol_compatible_usage.py

Usage

from pymcprotocol_wrapper import Client

# Now supports full pymcprotocol Type3E API
client = Client(plctype="Q")
client.connect(ip="192.168.1.10", port=5000)
client.setaccessopt(commtype="binary")

# Batch operations
client.batchwrite_wordunits("D100", [10, 20, 30])
values = client.batchread_wordunits("D100", 3)

# Random access
client.randomwrite(word_devices=["D200", "D300"], word_values=[200, 300])
words, dwords = client.randomread(word_devices=["D200", "D300"])

# Legacy API still works
client.write_data("D100", 123)
value = client.read_data("D100")

client.close()

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 192.168.1.1
    • Triggering command: /usr/bin/python3 python3 -m pytest tests/test_pymcprotocol_compat.py -v (packet block)
    • Triggering command: /usr/bin/python3 python3 -m pytest tests/ -v (packet block)
    • Triggering command: /usr/bin/python3 python3 -m pytest tests/ -v INVALID,NEW -j DROP (packet block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>pymcprotocol との整合</issue_title>
<issue_description>- wrapper として、高機能である事は必ずしも実際のプログラム作成時の目的には合致していない

  • 低水準な関数群の持つ問題を抽象化しても解決はしない場合がある。
  • まずはpymcprotocol 互換APIを完成させる。</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 30, 2025 18:35
Co-authored-by: strnh <874989+strnh@users.noreply.github.com>
Co-authored-by: strnh <874989+strnh@users.noreply.github.com>
…l client calls

Co-authored-by: strnh <874989+strnh@users.noreply.github.com>
Copilot AI changed the title [WIP] Complete pymcprotocol compatible API Implement complete pymcprotocol Type3E API compatibility Dec 30, 2025
Copilot AI requested a review from strnh December 30, 2025 18:45
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.

pymcprotocol との整合

2 participants