Skip to main content

A Python wrapper for the snap7 PLC communication library with easy variable management

Project description

Python Snap7 Easy Vars

A Python wrapper for the snap7 PLC communication library with easy variable management

Quick Start

Install the package via pip:

pip install python-snap7-easy-vars

Import the library and create a data structure:

import snap7_easy_vars

class MyPLCData(snap7_easy_vars.PLCData):
    # Define PLC variables with their data types and offsets
    temperature = snap7_easy_vars.PLCRealField(byte_offset=0) 
    pressure = snap7_easy_vars.PLCWordField(byte_offset=4)

    # By default, fields are read-only; to make a field settable, use the 'settable' parameter
    status = snap7_easy_vars.PLCBoolField(byte_offset=6, bit_offset=0, settable=True)

Connect to the PLC and read/write data:

my_plc_data = MyPLCData()
my_plc_connection = snap7_easy_vars.PLCConnection(
    ip_address="192.168.0.1", # PLC IP address
    data_store=my_plc_data,
    db_number=1, # PLC DB number
    rack=0, # PLC rack number
    slot=1, # PLC slot number
    port=102, # PLC port number
)

# Connect to the PLC
my_plc_connection.connect()

# Read data from the PLC
my_plc_connection.read()

# Read variables
print(f"Temperature: {my_plc_data.temperature}")
print(f"Pressure: {my_plc_data.pressure}")
print(f"Status: {my_plc_data.status}")

# Modify a variable and write back to the PLC
my_plc_data.status = True
my_plc_connection.write()

Authors

Project details


Download files

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

Source Distribution

python_snap7_easy_vars-1.0.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

python_snap7_easy_vars-1.0.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file python_snap7_easy_vars-1.0.2.tar.gz.

File metadata

  • Download URL: python_snap7_easy_vars-1.0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for python_snap7_easy_vars-1.0.2.tar.gz
Algorithm Hash digest
SHA256 61766dab9d2b5f13e1a4061688d0e644fb507a6df2ed3388218595a3771fae0d
MD5 6b8aaf99928e0871a24aabcef5cee0ca
BLAKE2b-256 b0da9ee4b2f3cd18109f99b89044b51ac5ab5aeaeb14a9bbcce3cd2538b4fd60

See more details on using hashes here.

File details

Details for the file python_snap7_easy_vars-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for python_snap7_easy_vars-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 724e068e18139fd147175221908593b9f67086a2609fb0048367b0db0ef9a54a
MD5 0e659b04baa39b9cfe6f0d78718c2065
BLAKE2b-256 a45f6a13d481b4a12ebe5c49568cb9a55ab77a337bc9618359a0ca66de71412b

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