Python driver for AutomationDirect (formerly Koyo) Ethernet ClickPLCs.
Project description
clickplc
Python ≥3.8 driver and command-line tool for Koyo Ethernet ClickPLCs.
Installation
pip install clickplc
Usage
Command Line
$ clickplc the-plc-ip-address
This will print all the X, Y, DS, and DF registers to stdout as JSON. You can pipe this as needed. However, you'll likely want the python functionality below.
Python
This uses Python ≥3.5's async/await syntax to asynchronously communicate with a ClickPLC. For example:
import asyncio
from clickplc import ClickPLC
async def get():
async with ClickPLC('the-plc-ip-address') as plc:
print(await plc.get('df1-df500'))
asyncio.run(get())
The entire API is get
and set
, and takes a range of inputs:
>>> await plc.get('df1')
0.0
>>> await plc.get('df1-df20')
{'df1': 0.0, 'df2': 0.0, ..., 'df20': 0.0}
>>> await plc.get('y101-y316')
{'y101': False, 'y102': False, ..., 'y316': False}
>>> await plc.set('df1', 0.0) # Sets DF1 to 0.0
>>> await plc.set('df1', [0.0, 0.0, 0.0]) # Sets DF1-DF3 to 0.0.
>>> await plc.set('y101', True) # Sets Y101 to true
Currently, the following datatypes are supported:
x | bool | Input point |
y | bool | Output point |
c | bool | (C)ontrol relay |
t | bool | (T)imer |
ct | bool | (C)oun(t)er |
ds | int16 | (D)ata register, (s)ingle signed int |
dd | int32 | (D)ata register, (d)double signed int |
dh | uint16 | (D) register, (h)ex |
df | float | (D)ata register, (f)loating point |
td | int16 | (T)ime (d)elay register |
ctd | int32 | (C)oun(t)er Current Values, (d)ouble int |
sd | int16 | (S)ystem (D)ata register |
Tags / Nicknames
Recent ClickPLC software provides the ability to export a "tags file", which contains all variables with user-assigned nicknames. The tags file can be used with this driver to improve code readability. (Who really wants to think about modbus addresses and register/coil types?)
To export a tags file, open the ClickPLC software, go to the Address Picker, select "Display MODBUS address", and export the file.
Once you have this file, simply pass the file path to the driver. You can now
set
variables by name and get
all named variables by default.
async with ClickPLC('the-plc-ip-address', 'path-to-tags.csv') as plc:
await plc.set('my-nickname', True) # Set variable by nickname
print(await plc.get()) # Get all named variables in tags file
Additionally, the tags file can be used with the commandline tool to provide more informative output:
$ clickplc the-plc-ip-address tags-filepath
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file clickplc-0.12.0.tar.gz
.
File metadata
- Download URL: clickplc-0.12.0.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 986cd6c6d9554a5674e45cd6c2e04662bec12d3e603cc00a3e199298e553404c |
|
MD5 | b62cf39c8895f927b57a8a7d3eec68c1 |
|
BLAKE2b-256 | 545be1320756790a23e8c6f7c374e8c3943de934bd45f0dc2ca9ea31dff93310 |
File details
Details for the file clickplc-0.12.0-py3-none-any.whl
.
File metadata
- Download URL: clickplc-0.12.0-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f7fc5b2843c0992a004004d96a9dca187aea9589e6b846969a82597d2ad2028 |
|
MD5 | 34c15d8bafdd59fff8bf070997d67118 |
|
BLAKE2b-256 | 5474758d85d5cf0f8573dcf660b70f140502c189012b9ad1bee919d6a54af049 |