Using Beckhoff bus terminals with the bus coupler BK9050 in python over tcp/ip
Go to file
Nicolas 96c716b1c5 missing explicit function return types added 2025-04-12 11:10:35 +02:00
notes build notes updated 2025-02-20 13:19:59 +01:00
src/pyhoff missing explicit function return types added 2025-04-12 11:10:35 +02:00
tests Test modified to allow for in- and output digital terminals 2025-02-20 17:14:23 +01:00
.flake8 docstrings and project settings updated, few refacoring 2025-02-17 14:57:03 +01:00
.gitignore docstrings and project settings updated, few refacoring 2025-02-17 14:57:03 +01:00
CITATION.cff version updated 2025-02-20 17:19:55 +01:00
LICENSE full refactored, minimal modbus tcp implementation integrated 2025-02-16 23:49:16 +01:00
README.md Readme example updated for new interface 2025-02-20 13:19:41 +01:00
pyproject.toml mypy config added 2025-04-12 11:09:26 +02:00
requirements-dev.txt docstrings and project settings updated, few refacoring 2025-02-17 14:57:03 +01:00

README.md

pyhoff

Description

The pyhoff package allows you to read and write the most common Beckhoff and WAGO bus terminals ("Busklemmen") using the Ethernet bus coupler ("Busskoppler") BK9000, BK9050, BK9100, or WAGO 750_352 over Ethernet TCP/IP based on ModBus TCP.

Key Features

  • Supports a wide range of Beckhoff and WAGO analog and digital bus terminals.
  • Very lightweight: no dependencies; compact code base
  • Easy to extend
  • Using standardized ModBus TCP.
  • Provides high-level abstractions for reading and writing data from/to IO-terminals with minimal code

Usage Scenarios

  • Industrial test setups.
  • Research automation setups.
  • Data acquisition and monitoring.

Installation

The package has no additional decencies. It can be installed with pip:

pip install pyhoff

Usage

It is easy to use as the following example code shows:

from pyhoff.devices import *

# connect to the BK9050 by tcp/ip on default port 502
bk = BK9050("172.16.17.1")

# add all bus terminals connected to the bus coupler
# in the order of the physical arrangement
bk.add_bus_terminals(KL2404, KL2424, KL9100, KL1104, KL3202,
                     KL3202, KL4002, KL9188, KL3054, KL3214,
                     KL4004, KL9010)

# Set 1. output of the first KL2404-type bus terminal to hi
KL2404.select(bk, 0).write_coil(1, True)

# read temperature from the 2. channel of the 2. KL3202-type
# bus terminal
t = KL3202.select(bk, 1).read_temperature(2)
print(f"t = {t:.1f} °C")

# Set 1. output of the 1. KL4002-type bus terminal to 4.2 V
KL4002.select(bk, 0).set_voltage(1, 4.2)

Contributing

Other analog and digital IO terminals are easy to complement. Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Developer Guide

To get started with developing the pyhoff package, follow these steps:

  1. Clone the Repository First, clone the repository to your local machine using Git:

    git clone https://github.com/Nonannet/pyhoff.git
    cd pyhoff
    
  2. Set Up a Virtual Environment It is recommended to use a virtual environment to manage dependencies. You can create one using venv:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    
  3. Install Dev Dependencies Install the dependencies required for development using pip:

    pip install -r requirements-dev.txt
    
  4. Run Tests Ensure that everything is set up correctly by running the tests:

    pytest
    

License

This project is licensed under the MIT License - see the LICENSE file for details.