This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Cpppo (Communication Protocol Python Parser and Originator) is a Python library for implementing binary communications protocol parsers using deterministic finite automata. The project primarily focuses on EtherNet/IP CIP (Common Industrial Protocol) communication with industrial controllers like Rockwell ControlLogix systems, along with Modbus/TCP support for PLC communication.
Run these commands from the checkout root with Nix flakes and nix-command enabled. The default shell uses CPython 3.13. Set TARGET to py311, py312, py313, py314, or py27 to select another shell. The nix-% rule forwards any Make target to that shell.
make nix-test
make TARGET=py27 nix-test
make TARGET=py312 nix-test-enip
make nix-unit-client
make nix-test TEST_ARGS='server/enip/client_test.py::test_parse_path'
make nix-test PYTESTOPTS='-vv -ra --tb=short'test runs the full pytest suite. test-<pattern> selects *<pattern>_test.py files, including nested suites. unit-<pattern> passes the pattern to pytest -k. TEST_ARGS accepts additional pytest arguments or paths. All three targets set TZ=Canada/Mountain and use pytest.ini.
The first Nix command that needs Python dependencies provisions .venv/<interpreter> using pip and installs .[all,tests]. Later runs reuse it and refresh dependencies after packaging inputs change. Python 2.7 uses virtualenv and pytest 4.6. Python 3 uses the standard-library venv module.
make nix-venv-setupprovisions the environment without opening an interactive shell.make nix-venvopens an activated Bash shell. From theremake test,make test-<pattern>, andmake unit-<pattern>use that interpreter.make nix-buildbuilds a source distribution and wheel intodist/.make nix-wheelbuilds only the wheel. SetDIST_DIRto change the output directory.make nix-installreinstalls the current checkout with its optional dependencies.make nix-install-devandmake nix-install-testsinstall the corresponding requirements files.make nix-analyzeandmake nix-pylintrun the linters in the selected environment.make cleanremoves build artifacts and Python caches and preserves the virtualenvs.
nix develop .#py27 followed by make test is equivalent to make TARGET=py27 nix-test. Outside Nix, plain make test uses the interpreter on PATH and expects dependencies to be installed. Set PYTHON to select a different interpreter. VENV_DIR changes the directory for managed virtualenvs, and VENV overrides the path of one environment. NIX_OPTS passes flags to nix develop.
The Python 3 suite runs the serial integration tests when SERIAL_TEST names a configured group of ports. Use make SERIAL_TEST=ttyS0 nix-test-serial for physical ports or make SERIAL_TEST=ttyV0 nix-test-serial for virtual ports. The number is the client port suffix. The next two ports are used as servers. On POSIX, run nix develop --command python3 ttyV-setup.py 3 in a separate terminal to provide three virtual ports, then stop the bridge with Ctrl-C after the tests. The bridge replaces local ttyV0 through ttyV2 links.
make nix-test-class1 exercises the Class 1 scanner, printer adapter, watchdog, and separate Class 3 job channel in cpppo. For independent peers, the interop shell adds a C/C++ toolchain and CMake.
git clone https://github.com/nimbuscontrols/EIPScanner.git ~/src/EIPScanner
make TARGET=interop nix-test-class1-interopThe target uses the OpENer checkout at ~/src/OpENer and EIPScanner at ~/src/EIPScanner. Override OPENER_SRC or EIPSCANNER_SRC to point to another checkout. Verified peer revisions are OpENer fb90c9918081c184b1876ce0c893168cf8b5653c and EIPScanner 12c89a57ec2e7449efb1348be52af10be9ef9701. The target builds temporary Git snapshots with loopback and macOS portability patches. EIPScanner's receive port is 2223 in the test build so it can share the host with OpENer. Keep TCP 44818 and UDP 2222 and 2223 free on loopback.
- The cpppo scanner opens OpENer's sample Input Only assembly, writes new sample data over explicit messaging, and verifies the changed cyclic input.
- EIPScanner opens the cpppo printer's Input Only assembly and verifies several snapshots containing the job number written over Class 3.
- EIPScanner opens OpENer's Input Only assembly and verifies the sample data it wrote over explicit messaging.
To reuse prebuilt peers, set CPPPO_OPENER to the OpENer sample executable and CPPPO_EIPSCANNER to the probe built from tools/class1_reference_scanner.cpp, then run make nix-test-class1.
make nix-test-readme runs every Python source block and named Python
example in README.org. It compares stdout with each named RESULTS entry
or the displayed output after an example. It starts the documented Class 1
adapter and a local Modbus simulator. Keep TCP ports 1502 and 44818 and UDP
port 2222 free on loopback.
make TARGET=py313 nix-build
make TARGET=interop nix-test-artifactsnix-test-artifacts expects one cpppo wheel and one source archive in
DIST_DIR. It builds the reference peers and runs the Class 1 suite, printer
demo, and README checks from separate virtualenvs outside the checkout.
The CPython 2.7 environment covers the protocol parser, EtherNet/IP simulators, history, and other compatible tests. The current PyModbus 3.8 integration and Modbus command-line tools require Python 3.9 or newer.
GitHub Actions tests CPython 3.11 through 3.14 and the legacy CPython 2.7 target through the Nix flake. CPython 3.11 is the minimum maintained Python 3 version. Existing installations on older Python releases can continue to use compatible features.
Branch CI and tagged releases use the same package verification workflow. A
version tag such as v5.7.0 must match version.py. The release workflow
passes the verified distributions to a separate job that publishes through
the PyPI pypi Trusted Publishing environment.
The project has several optional dependency groups:
[modbus]- Modbus TCP/RTU support via pymodbus[logix]- Alternative Logix I/O via pylogix[serial]- Serial communication support[dev]- Development tools[timestamp]- Timestamp handling[all]- All optional dependencies
- automata.py - Deterministic finite automata implementation using greenery library
- server/enip/ - EtherNet/IP CIP protocol implementation
main.py- EtherNet/IP server entry pointclient.py- EtherNet/IP client implementationparser.py- Protocol message parsingdevice.py- Device simulation capabilitieslogix.py- Rockwell Logix-specific functionality
- remote/ - Remote PLC communication utilities
plc.py- Generic PLC communicationplc_modbus.py- Modbus-specific PLC communication
- history/ - Historical data management
- tools/ - Utility modules
python -m cpppo.server.enip- Start EtherNet/IP serverenip_server- Console script for EtherNet/IP serverenip_client- Console script for EtherNet/IP clientenip_get_attribute- Console script for attribute readingmodbus_sim- Modbus simulator (Python 3.9+)modbus_poll- Modbus polling utility (Python 3.9+)
- EtherNet/IP CIP: Industrial Ethernet protocol for communication with PLCs
- Modbus/TCP and RTU: TCP and serial communication for industrial devices
- Support for Rockwell ControlLogix, MicroLogix controllers
- EtherNet/IP server configurations in
*.cfgfiles - Default configurations in
server/enip/defaults.py - Pytest configuration in
pytest.ini - Package metadata in
setup.py