Skip to main content

A basic PCOM implementation in Python

Project description

PCOM

A very basic Unitronics PCOM protocol implementation for Python 3.

How to use

from pcom import commands
from pcom.plc import EthernetPlc

with EthernetPlc(address=('192.168.5.43', 1616)) as plc:
    # Read realtime clock
    c = commands.ReadRtc()
    res = plc.send(c)
    print(res)

    # Set realtime clock
    c = commands.SetRtc(value=datetime.now())
    plc.send(c)

    # Set MB 300 through 304
    values = [True, False, True, True, False]
    c = commands.SetBits(code=commands.SetBits.MEMORY, address=300, values=values)
    plc.send(c)


See the commands Python package for available commands.

Datatable commands are in the commands.datatables package. To work with a datatable, its structure has to be defined. Here's an example:

from pcom import commands
from pcom.plc import EthernetPlc


with EthernetPlc(address=('192.168.5.47', 1616)) as plc:
    table_structure = commands.datatables.DatatableStructure("My table", offset=19000, rows=2, columns=[
        commands.datatables.Int(),
        commands.datatables.Int(2),
        commands.datatables.Int(),
        commands.datatables.Int(),
        commands.datatables.Long(),
    ])
    c = commands.datatables.ReadDatatable(structure=table_structure, row_count=2)
    res = plc.send(c)
    print('My table', res)

Writing to a datatable is very much alike:

from pcom import commands
from pcom.plc import EthernetPlc


with EthernetPlc(address=('192.168.5.47', 1616)) as plc:
    table_structure = commands.datatables.DatatableStructure("My table", offset=19000, rows=2, columns=[
        commands.datatables.Int(2),
        commands.datatables.Int(),
        commands.datatables.String(5),
        commands.datatables.Int(),
        commands.datatables.Int(),
        commands.datatables.Long(),
    ])

    rows = [
        [[11, 12], [13], "hello", [14], [15], [-673542]],
        [[11, 14], [15], "bye  ", [16], [17], [655666]],
    ]
    c = commands.datatables.WriteDatatable(structure=table_structure, data=rows)
    try:
        plc.send(c)
    except datatables.WriteDatatableError as ex:
        print(ex)

Known limitations

  • General:
    • Serial communication is not implemented yet.
  • Datatables:
    • "Part of project" columns are not supported.
    • Reading a datatable structure is not supported.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pcom-0.5-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file pcom-0.5-py3-none-any.whl.

File metadata

  • Download URL: pcom-0.5-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.11.1 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.18

File hashes

Hashes for pcom-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b4f29dc5c4a52f78d719849de401de91a4fc4effb2cf8c728026459306a503a8
MD5 cc4a9d7fc96854da1fd7f8e04ad16459
BLAKE2b-256 0dda6f83cd5e51ccf9098de401d3946a7f7eb3a5fc51e781399739500b43a187

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page