Skip to content

Getting started

Start here

Use this page for your first TOYOPUC Computerlink read and write from Python.

Step What you do
1 Install plc-comm-toyopuc.
2 Choose one exact canonical profile string.
3 Connect to 192.168.250.100:1025 over TCP.
4 Read P1-D0000.
5 Write only to a known-safe test word or bit.

Prerequisites

Item Requirement
Python Python 3.10 or later.
PLC network Your PLC is reachable at 192.168.250.100.
TCP port Computerlink TCP examples use 1025.
UDP port Computerlink UDP examples use 1035.
Canonical profile A profile such as toyopuc:plus:extended.

Install

pip install plc-comm-toyopuc

Choose profile

Start with toyopuc:plus:extended only when your PLC is a TOYOPUC-Plus target. Use profiles for the exact list.

from toyopuc import ToyopucPlcProfiles


def main() -> None:
    profile = ToyopucPlcProfiles.from_name("toyopuc:plus:extended")
    print(profile.name)


if __name__ == "__main__":
    main()

First read

import asyncio

from toyopuc import ToyopucConnectionOptions, open_and_connect, read_typed


async def main() -> None:
    options = ToyopucConnectionOptions(
        host="192.168.250.100",
        port=1025,
        transport="tcp",
        plc_profile="toyopuc:plus:extended",
    )

    async with await open_and_connect(options) as client:
        value = await read_typed(client, "P1-D0000", "U")
        print(f"P1-D0000 = {value}")


asyncio.run(main())

UDP connection

TCP and UDP are never inferred. For UDP, configure the PC IP address and a fixed PC port in the PLC's Other Node Table, then set local_port to that same port. This example assumes the PLC peer port is 12000:

import asyncio

from toyopuc import ToyopucConnectionOptions, open_and_connect, read_typed


async def main() -> None:
    options = ToyopucConnectionOptions(
        host="192.168.250.100",
        port=1035,
        transport="udp",
        plc_profile="toyopuc:plus:extended",
        local_port=12000,
    )

    async with await open_and_connect(options) as client:
        value = await read_typed(client, "P1-D0000", "U")
        print(f"P1-D0000 = {value}")


asyncio.run(main())

First write

These controlled-test examples restore only confirmed writes, in reverse order. An outcome-unknown write stops further writes and propagates its original error; inspect and reconcile the PLC state before proceeding. A readback failure after a confirmed write still attempts restoration. A restoration failure is reported and stops the remaining restoration steps.

Use a known-safe test word. Do not write to production outputs or motion-related registers while testing.

import asyncio

from toyopuc.errors import ToyopucOperationOutcomeUnknownError
from toyopuc import ToyopucConnectionOptions, open_and_connect, read_typed, write_typed


async def main() -> None:
    options = ToyopucConnectionOptions(
        host="192.168.250.100",
        port=1025,
        transport="tcp",
        plc_profile="toyopuc:plus:extended",
    )

    async with await open_and_connect(options) as client:
        original = await read_typed(client, "P1-D0001", "U")
        write_confirmed = False
        outcome_unknown = False
        try:
            await write_typed(client, "P1-D0001", "U", 1234)
            write_confirmed = True
            value = await read_typed(client, "P1-D0001", "U")
            print(f"P1-D0001 = {value}")
        except ToyopucOperationOutcomeUnknownError:
            outcome_unknown = True
            raise
        finally:
            if not outcome_unknown:
                if write_confirmed:
                    await write_typed(client, "P1-D0001", "U", original)


asyncio.run(main())

Confirm success

Check Expected result
Connection No timeout from open_and_connect.
Read P1-D0000 returns one integer value.
Write The readback from P1-D0001 matches your test value.
Address text Basic families use P1-, P2-, or P3- prefixes.

If it does not work

Use the shared Computerlink Troubleshooting & Codes page for connection, addressing, write, relay, and PLC error-code checks.

Symptom Check
Timeout Confirm host 192.168.250.100, TCP port 1025, and PLC network settings.
Profile error Use only exact canonical strings from profiles.
Address error Use P1-D0000, not D0000, for basic area families.
Dword reads look wrong Use P1-D0100:D or dtype "D"; P1-D0100.D means bit 13.
FR work-area write does not persist Call commit_fr_block_by_device() separately with the first address of the intended FR block.

This library

Source plc-comm-computerlink-python
Package PyPI: plc-comm-toyopuc
Changelog CHANGELOG.md
Report a problem Issues