LECPython 1.2.0.6__tar.gz → 1.2.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/LECPythonLib.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/LECPythonLib.pdb +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/LECPythonLib.py +54 -38
- lecpython-1.2.2.6/LECPython.egg-info/PKG-INFO +252 -0
- lecpython-1.2.2.6/PKG-INFO +252 -0
- lecpython-1.2.2.6/README.md +237 -0
- lecpython-1.2.2.6/setup.py +29 -0
- lecpython-1.2.0.6/LECPython.egg-info/PKG-INFO +0 -70
- lecpython-1.2.0.6/PKG-INFO +0 -70
- lecpython-1.2.0.6/README.md +0 -58
- lecpython-1.2.0.6/setup.py +0 -26
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/LECPythonLib.deps.json +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/Microsoft.Win32.SystemEvents.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/Newtonsoft.Json.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/System.Collections.Immutable.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/System.Data.SqlClient.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/System.Drawing.Common.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/System.Formats.Nrbf.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/System.IO.Ports.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/System.Reflection.Metadata.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/System.Resources.Extensions.dll +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython/__init__.py +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython.egg-info/SOURCES.txt +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython.egg-info/dependency_links.txt +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython.egg-info/requires.txt +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/LECPython.egg-info/top_level.txt +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/MANIFEST.in +0 -0
- {lecpython-1.2.0.6 → lecpython-1.2.2.6}/setup.cfg +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -34,48 +34,64 @@ class DotNetInstaller:
|
|
|
34
34
|
"""
|
|
35
35
|
Install the .NET runtime.
|
|
36
36
|
"""
|
|
37
|
-
if os.name
|
|
38
|
-
print("
|
|
37
|
+
if os.name == 'posix':
|
|
38
|
+
print("Detected Linux environment.")
|
|
39
|
+
elif os.name == 'nt':
|
|
40
|
+
print("Detected Windows environment.")
|
|
41
|
+
else:
|
|
42
|
+
print("Unsupported operating system environment.")
|
|
39
43
|
return
|
|
40
44
|
|
|
41
45
|
distribution = platform.system().lower()
|
|
42
46
|
try:
|
|
43
|
-
if
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
47
|
+
if os.name == 'nt': # Windows环境
|
|
48
|
+
print("Detected Windows environment. Installing .NET 8 Runtime...")
|
|
49
|
+
os.system('powershell -Command "& {Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; Set-ExecutionPolicy Bypass -Scope Process -Force; ./dotnet-install.ps1 -Channel 8.0 -Runtime dotnet}"')
|
|
50
|
+
elif os.name == 'posix':
|
|
51
|
+
if 'ubuntu' in distribution or 'debian' in distribution:
|
|
52
|
+
# Install .NET 8 on Ubuntu/Debian
|
|
53
|
+
print("Detected Ubuntu/Debian. Installing .NET 8 Runtime...")
|
|
54
|
+
os.system('sudo apt update')
|
|
55
|
+
os.system('sudo apt install -y wget')
|
|
56
|
+
os.system('wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb')
|
|
57
|
+
os.system('sudo dpkg -i packages-microsoft-prod.deb')
|
|
58
|
+
os.system('sudo apt update')
|
|
59
|
+
os.system('sudo apt install -y dotnet-runtime-8.0')
|
|
60
|
+
|
|
61
|
+
elif 'centos' in distribution or 'rhel' in distribution or 'fedora' in distribution:
|
|
62
|
+
# Install .NET 8 on CentOS/RHEL/Fedora
|
|
63
|
+
print("Detected CentOS/RHEL/Fedora. Installing .NET 8 Runtime...")
|
|
64
|
+
os.system('sudo dnf install -y wget')
|
|
65
|
+
os.system('wget https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm -O packages-microsoft-prod.rpm')
|
|
66
|
+
os.system('sudo rpm -Uvh packages-microsoft-prod.rpm')
|
|
67
|
+
os.system('sudo dnf install -y dotnet-runtime-8.0')
|
|
68
|
+
|
|
69
|
+
else:
|
|
70
|
+
# Other Linux distros
|
|
71
|
+
# if running on WSL, use apt to install dotnet-runtime-8.0
|
|
72
|
+
# else do not support install dotnet-runtime-8.0 by default
|
|
73
|
+
# output message to using manual installation
|
|
74
|
+
with open("/proc/version", "r") as f:
|
|
75
|
+
version_info = f.read().lower()
|
|
76
|
+
if "microsoft" in version_info or "wsl" in version_info:
|
|
77
|
+
print("Detected Ubuntu/Debian. Installing .NET 8 Runtime...")
|
|
78
|
+
os.system('sudo apt update')
|
|
79
|
+
os.system('sudo apt install -y wget')
|
|
80
|
+
os.system('wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb')
|
|
81
|
+
os.system('sudo dpkg -i packages-microsoft-prod.deb')
|
|
82
|
+
os.system('sudo apt update')
|
|
83
|
+
os.system('sudo apt install -y dotnet-runtime-8.0')
|
|
84
|
+
elif "rpt-rpi" in version_info:
|
|
85
|
+
print("Detected Raspberry Pi environment. Installing .NET 8 Runtime...")
|
|
86
|
+
os.system('sudo apt update')
|
|
87
|
+
os.system('sudo apt install -y wget')
|
|
88
|
+
os.system('wget -O aspnetcore-runtime-8.0.8-linux-arm64.tar.gz https://download.visualstudio.microsoft.com/download/pr/f6fcf2c9-39ad-49c7-80b5-92306309e796/3cac9217f55528cb60c95702ba92d78b/aspnetcore-runtime-8.0.8-linux-arm64.tar.gz')
|
|
89
|
+
os.system('sudo mkdir -p /usr/share/dotnet')
|
|
90
|
+
os.system('sudo tar zxf aspnetcore-runtime-8.0.8-linux-arm64.tar.gz -C /usr/share/dotnet')
|
|
91
|
+
os.system('sudo ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet')
|
|
92
|
+
else:
|
|
93
|
+
raise RuntimeError("Automatic installation of .NET runtime is not supported. Please install .NET runtime manually.")
|
|
94
|
+
|
|
79
95
|
# Verify installation
|
|
80
96
|
result = subprocess.run(['dotnet', '--list-runtimes'], stdout=subprocess.PIPE, text=True)
|
|
81
97
|
if f' {DotNetInstaller.RUNTIME_VERSION}' in result.stdout:
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: LECPython
|
|
3
|
+
Version: 1.2.2.6
|
|
4
|
+
Summary: LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs...
|
|
5
|
+
Home-page: https://github.com/xeden3/LECPython
|
|
6
|
+
Author: xeden3
|
|
7
|
+
Author-email: james@sctmes.com
|
|
8
|
+
Project-URL: Documentation, http://lecpserver.com:3003/
|
|
9
|
+
Project-URL: Source, https://github.com/xeden3/LECPython
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/xeden3/LECPython/issues
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: pythonnet==3.0.4
|
|
15
|
+
|
|
16
|
+
# LECPython
|
|
17
|
+
|
|
18
|
+
LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It requires .NET 8 runtime support. When LECPython is called for the first time, the component automatically checks if .NET 8 is installed, and if not, it will perform an automatic online installation.
|
|
19
|
+
|
|
20
|
+
LECPython supports a wide range of PLCs available in the market, including those supporting the Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.
|
|
21
|
+
|
|
22
|
+
# Introduction
|
|
23
|
+
|
|
24
|
+
LECPython provides a simple and efficient way to connect and communicate with various PLCs. Whether for industrial automation or other applications requiring PLC control, LECPython offers a reliable solution. Since LECPython is developed in C#, its read and write efficiency is faster than pure Python.
|
|
25
|
+
|
|
26
|
+
The operation process of LECPython is as follows: First, a connector is created through `DeviceProfinetConnection`, but it does not connect to the PLC at this time. During the first read and write operation to the PLC, the actual connection and communication with the PLC are performed through `DeviceProfinetCommunication`. The connector automatically completes the long connection and reconnection mechanism. As long as the `DeviceProfinetConnection` object is not cleared, the connector remains effective. Meanwhile, users can set the connector's `data_format` and `is_string_reverse_byte_word` to achieve high and low byte read settings for the PLC.
|
|
27
|
+
|
|
28
|
+
# Getting Started
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Ensure you have Python installed. You can install LECPython using pip:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install LECPython
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
LECPython automatically installs the required `pythonnet` dependency. However, if needed, you can manually install it using:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install pythonnet==3.0.4
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## .NET 8 Installation
|
|
45
|
+
|
|
46
|
+
LECPython requires .NET 8 runtime support. When you call LECPython for the first time, the component will automatically check if .NET 8 is installed on your system. If not, LECPython will automatically install the .NET 8 runtime online.
|
|
47
|
+
|
|
48
|
+
### Automatic Installation Steps
|
|
49
|
+
|
|
50
|
+
1. When you run LECPython for the first time, the component will check if .NET 8 runtime is present on your system.
|
|
51
|
+
2. If .NET 8 runtime is not detected, LECPython will attempt to download and install .NET 8 online.
|
|
52
|
+
3. The installation process will vary depending on the operating system. If the automatic installation fails, LECPython will prompt you to manually install .NET 8.
|
|
53
|
+
|
|
54
|
+
### Manual Installation
|
|
55
|
+
|
|
56
|
+
If the automatic installation fails, you can manually install .NET 8 by following these steps:
|
|
57
|
+
|
|
58
|
+
- For Windows users:
|
|
59
|
+
1. Visit the official .NET website: https://dotnet.microsoft.com/download/dotnet/8.0
|
|
60
|
+
2. Download and run the installer for Windows.
|
|
61
|
+
|
|
62
|
+
- For Ubuntu users:
|
|
63
|
+
```bash
|
|
64
|
+
wget https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-8.0.0-linux-x64-binaries
|
|
65
|
+
tar -zxf dotnet-runtime-8.0.0-linux-x64.tar.gz -C $HOME/dotnet
|
|
66
|
+
export PATH=$PATH:$HOME/dotnet
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- For users of other Linux distributions, please refer to the installation guide on the official .NET website.
|
|
70
|
+
|
|
71
|
+
### Supported Systems
|
|
72
|
+
|
|
73
|
+
LECPython has been tested and confirmed to automatically complete the .NET 8 installation on the following systems:
|
|
74
|
+
- Ubuntu 20.04, 22.04
|
|
75
|
+
- Windows 11 WSL2 environment
|
|
76
|
+
- Windows 11 PowerShell environment
|
|
77
|
+
- Raspbian OS environment on Raspberry Pi
|
|
78
|
+
|
|
79
|
+
## Usage Example
|
|
80
|
+
|
|
81
|
+
Here's a basic example of how to use LECPython:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from LECPython import LECPython
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
lecp = LECPython()
|
|
88
|
+
try:
|
|
89
|
+
# Establish connection to Omron FINS PLC
|
|
90
|
+
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
91
|
+
print("Omron FINS PLC Connection called successfully:", result["ErrorCode"])
|
|
92
|
+
|
|
93
|
+
# Read 10 float values from address D100
|
|
94
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
95
|
+
print(f"The PLC read rtval is: {rtval}")
|
|
96
|
+
|
|
97
|
+
# Write a float value to address D100
|
|
98
|
+
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
99
|
+
print(f"The PLC write rtval is: {rtval}")
|
|
100
|
+
|
|
101
|
+
# Read 10 float values from address D100 again
|
|
102
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
103
|
+
print(f"The PLC read rtval is: {rtval}")
|
|
104
|
+
|
|
105
|
+
# Close connection
|
|
106
|
+
lecp.ConnectClose(result["Content"])
|
|
107
|
+
except AttributeError as e:
|
|
108
|
+
print(e)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# Features
|
|
113
|
+
|
|
114
|
+
- Supports multiple PLC protocols including Modbus, Mitsubishi, Siemens, Omron, Rockwell, and more.
|
|
115
|
+
- Easy to use API for connecting and communicating with PLCs.
|
|
116
|
+
- Standalone component with no need for additional third-party PLC controls.
|
|
117
|
+
- Built-in .NET 8 runtime automatic installation.
|
|
118
|
+
|
|
119
|
+
For more detailed API documentation, please visit: [LECPython API Documentation](http://www.lecpserver.com:3003/)
|
|
120
|
+
|
|
121
|
+
# License
|
|
122
|
+
|
|
123
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
124
|
+
|
|
125
|
+
-----
|
|
126
|
+
|
|
127
|
+
# LECPython (中文)
|
|
128
|
+
|
|
129
|
+
LECPython 是一个用 C# 开发的 Python 组件,能够实现 Python 与 PLC 之间的无缝通信。它需要 .NET 8 运行时支持,当首次调用 LECPython 时,组件会自动检查是否安装了 .NET 8,如果没有,它将自动在线安装。
|
|
130
|
+
|
|
131
|
+
LECPython 支持市场上广泛的 PLC,包括支持 Modbus 协议的 PLC、三菱、西门子、欧姆龙、罗克韦尔、基恩士、台达、倍福、松下、汇川、富士、EverSensing、施耐德等。该组件是独立的,不需要额外的第三方 PLC 控件支持。
|
|
132
|
+
|
|
133
|
+
# 简介
|
|
134
|
+
|
|
135
|
+
LECPython 提供了一种简单而高效的方式来连接和通信各种 PLC。无论是工业自动化还是其他需要 PLC 控制的应用,LECPython 都能提供可靠的解决方案。由于 LECPython 是基于 C# 开发的,因此其运行读写效率会比纯 Python 快。
|
|
136
|
+
|
|
137
|
+
LECPython 的运行过程如下:首先通过 `DeviceProfinetConnection` 创建一个连接器,但此时并不会与 PLC 进行连接。在第一次读写 PLC 时,通过 `DeviceProfinetCommunication` 操作,对 PLC 进行实际的连接和通讯。连接器自动完成长连接和断线重连的机制,只要 `DeviceProfinetConnection` 对象不被清除,连接器就一直有效。同时,用户可以通过设置连接器的 `data_format` 和 `is_string_reverse_byte_word` 来实现 PLC 的高低位读取设定。
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# 使用指南
|
|
143
|
+
|
|
144
|
+
## 安装
|
|
145
|
+
|
|
146
|
+
确保你已经安装了 Python。你可以使用 pip 安装 LECPython:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pip install LECPython
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
LECPython 会自动安装所需的 `pythonnet` 依赖项。如果需要,你也可以手动安装:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
pip install pythonnet==3.0.4
|
|
156
|
+
```
|
|
157
|
+
## .NET 8 安装
|
|
158
|
+
|
|
159
|
+
LECPython 需要 .NET 8 运行时支持。当你第一次调用 LECPython 时,组件会自动检查系统中是否安装了 .NET 8。如果没有安装,LECPython 将会自动在线安装 .NET 8 运行时。
|
|
160
|
+
|
|
161
|
+
### 自动安装步骤
|
|
162
|
+
|
|
163
|
+
1. 当你第一次运行 LECPython 时,组件会检测系统中是否存在 .NET 8 运行时。
|
|
164
|
+
2. 如果没有检测到 .NET 8 运行时,LECPython 将会尝试在线下载并安装 .NET 8。
|
|
165
|
+
3. 安装过程会根据操作系统的不同而有所不同。如果自动安装失败,LECPython 会提示你手动安装 .NET 8。
|
|
166
|
+
|
|
167
|
+
### 手动安装
|
|
168
|
+
|
|
169
|
+
如果自动安装失败,你可以根据以下步骤手动安装 .NET 8:
|
|
170
|
+
|
|
171
|
+
- 对于 Windows 用户:
|
|
172
|
+
1. 访问 .NET 官方网站:https://dotnet.microsoft.com/download/dotnet/8.0
|
|
173
|
+
2. 下载并运行适用于 Windows 的安装程序。
|
|
174
|
+
|
|
175
|
+
- 对于 Ubuntu 用户:
|
|
176
|
+
```bash
|
|
177
|
+
wget https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-8.0.0-linux-x64-binaries
|
|
178
|
+
tar -zxf dotnet-runtime-8.0.0-linux-x64.tar.gz -C $HOME/dotnet
|
|
179
|
+
export PATH=$PATH:$HOME/dotnet
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- 对于其他 Linux 发行版用户,请参考 .NET 官方网站上的安装指南。
|
|
183
|
+
|
|
184
|
+
### 支持的系统
|
|
185
|
+
|
|
186
|
+
LECPython 已在以下系统上测试并确认可以自动完成 .NET 8 的安装:
|
|
187
|
+
- Ubuntu 20.04, 22.04
|
|
188
|
+
- Windows 11 WSL2 环境
|
|
189
|
+
- Windows 11 PowerShell 环境
|
|
190
|
+
- 树莓派的 Raspbian OS 环境
|
|
191
|
+
|
|
192
|
+
## 使用示例
|
|
193
|
+
|
|
194
|
+
以下是一个如何使用 LECPython 的基本示例:
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from LECPython import LECPython
|
|
198
|
+
|
|
199
|
+
if __name__ == "__main__":
|
|
200
|
+
lecp = LECPython()
|
|
201
|
+
try:
|
|
202
|
+
# 开启连接器 欧姆龙 FINS PLC
|
|
203
|
+
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
204
|
+
print("Omron FINS PLC Connection 调用成功:", result["ErrorCode"])
|
|
205
|
+
|
|
206
|
+
# 从地址 D100 读取 10 个浮点值
|
|
207
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
208
|
+
print(f"读取的值是: {rtval}")
|
|
209
|
+
|
|
210
|
+
# 向地址 D100 写入浮点值
|
|
211
|
+
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
212
|
+
print(f"写入的值是: {rtval}")
|
|
213
|
+
|
|
214
|
+
# 再次从地址 D100 读取 10 个浮点值
|
|
215
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
216
|
+
print(f"读取的值是: {rtval}")
|
|
217
|
+
|
|
218
|
+
# 关闭连接器
|
|
219
|
+
lecp.ConnectClose(result["Content"])
|
|
220
|
+
except AttributeError as e:
|
|
221
|
+
print(e)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
# 特点
|
|
225
|
+
|
|
226
|
+
- 支持多种 PLC 协议,包括 Modbus、三菱、西门子、欧姆龙、罗克韦尔等。
|
|
227
|
+
- 提供易于使用的 API,用于连接和通信 PLC。
|
|
228
|
+
- 独立组件,无需额外的第三方 PLC 控件。
|
|
229
|
+
- 自带 .NET 8 运行时自动安装。
|
|
230
|
+
-
|
|
231
|
+
需要了解更多的API信息,请查阅官方文档: [LECPython API Documentation](http://www.lecpserver.com:3003/)
|
|
232
|
+
|
|
233
|
+
# 许可证
|
|
234
|
+
|
|
235
|
+
此项目根据 MIT 许可证授权。详情请参阅 [LICENSE](LICENSE) 文件。
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: LECPython
|
|
3
|
+
Version: 1.2.2.6
|
|
4
|
+
Summary: LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs...
|
|
5
|
+
Home-page: https://github.com/xeden3/LECPython
|
|
6
|
+
Author: xeden3
|
|
7
|
+
Author-email: james@sctmes.com
|
|
8
|
+
Project-URL: Documentation, http://lecpserver.com:3003/
|
|
9
|
+
Project-URL: Source, https://github.com/xeden3/LECPython
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/xeden3/LECPython/issues
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: pythonnet==3.0.4
|
|
15
|
+
|
|
16
|
+
# LECPython
|
|
17
|
+
|
|
18
|
+
LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It requires .NET 8 runtime support. When LECPython is called for the first time, the component automatically checks if .NET 8 is installed, and if not, it will perform an automatic online installation.
|
|
19
|
+
|
|
20
|
+
LECPython supports a wide range of PLCs available in the market, including those supporting the Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.
|
|
21
|
+
|
|
22
|
+
# Introduction
|
|
23
|
+
|
|
24
|
+
LECPython provides a simple and efficient way to connect and communicate with various PLCs. Whether for industrial automation or other applications requiring PLC control, LECPython offers a reliable solution. Since LECPython is developed in C#, its read and write efficiency is faster than pure Python.
|
|
25
|
+
|
|
26
|
+
The operation process of LECPython is as follows: First, a connector is created through `DeviceProfinetConnection`, but it does not connect to the PLC at this time. During the first read and write operation to the PLC, the actual connection and communication with the PLC are performed through `DeviceProfinetCommunication`. The connector automatically completes the long connection and reconnection mechanism. As long as the `DeviceProfinetConnection` object is not cleared, the connector remains effective. Meanwhile, users can set the connector's `data_format` and `is_string_reverse_byte_word` to achieve high and low byte read settings for the PLC.
|
|
27
|
+
|
|
28
|
+
# Getting Started
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Ensure you have Python installed. You can install LECPython using pip:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install LECPython
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
LECPython automatically installs the required `pythonnet` dependency. However, if needed, you can manually install it using:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install pythonnet==3.0.4
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## .NET 8 Installation
|
|
45
|
+
|
|
46
|
+
LECPython requires .NET 8 runtime support. When you call LECPython for the first time, the component will automatically check if .NET 8 is installed on your system. If not, LECPython will automatically install the .NET 8 runtime online.
|
|
47
|
+
|
|
48
|
+
### Automatic Installation Steps
|
|
49
|
+
|
|
50
|
+
1. When you run LECPython for the first time, the component will check if .NET 8 runtime is present on your system.
|
|
51
|
+
2. If .NET 8 runtime is not detected, LECPython will attempt to download and install .NET 8 online.
|
|
52
|
+
3. The installation process will vary depending on the operating system. If the automatic installation fails, LECPython will prompt you to manually install .NET 8.
|
|
53
|
+
|
|
54
|
+
### Manual Installation
|
|
55
|
+
|
|
56
|
+
If the automatic installation fails, you can manually install .NET 8 by following these steps:
|
|
57
|
+
|
|
58
|
+
- For Windows users:
|
|
59
|
+
1. Visit the official .NET website: https://dotnet.microsoft.com/download/dotnet/8.0
|
|
60
|
+
2. Download and run the installer for Windows.
|
|
61
|
+
|
|
62
|
+
- For Ubuntu users:
|
|
63
|
+
```bash
|
|
64
|
+
wget https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-8.0.0-linux-x64-binaries
|
|
65
|
+
tar -zxf dotnet-runtime-8.0.0-linux-x64.tar.gz -C $HOME/dotnet
|
|
66
|
+
export PATH=$PATH:$HOME/dotnet
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- For users of other Linux distributions, please refer to the installation guide on the official .NET website.
|
|
70
|
+
|
|
71
|
+
### Supported Systems
|
|
72
|
+
|
|
73
|
+
LECPython has been tested and confirmed to automatically complete the .NET 8 installation on the following systems:
|
|
74
|
+
- Ubuntu 20.04, 22.04
|
|
75
|
+
- Windows 11 WSL2 environment
|
|
76
|
+
- Windows 11 PowerShell environment
|
|
77
|
+
- Raspbian OS environment on Raspberry Pi
|
|
78
|
+
|
|
79
|
+
## Usage Example
|
|
80
|
+
|
|
81
|
+
Here's a basic example of how to use LECPython:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from LECPython import LECPython
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
lecp = LECPython()
|
|
88
|
+
try:
|
|
89
|
+
# Establish connection to Omron FINS PLC
|
|
90
|
+
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
91
|
+
print("Omron FINS PLC Connection called successfully:", result["ErrorCode"])
|
|
92
|
+
|
|
93
|
+
# Read 10 float values from address D100
|
|
94
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
95
|
+
print(f"The PLC read rtval is: {rtval}")
|
|
96
|
+
|
|
97
|
+
# Write a float value to address D100
|
|
98
|
+
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
99
|
+
print(f"The PLC write rtval is: {rtval}")
|
|
100
|
+
|
|
101
|
+
# Read 10 float values from address D100 again
|
|
102
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
103
|
+
print(f"The PLC read rtval is: {rtval}")
|
|
104
|
+
|
|
105
|
+
# Close connection
|
|
106
|
+
lecp.ConnectClose(result["Content"])
|
|
107
|
+
except AttributeError as e:
|
|
108
|
+
print(e)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# Features
|
|
113
|
+
|
|
114
|
+
- Supports multiple PLC protocols including Modbus, Mitsubishi, Siemens, Omron, Rockwell, and more.
|
|
115
|
+
- Easy to use API for connecting and communicating with PLCs.
|
|
116
|
+
- Standalone component with no need for additional third-party PLC controls.
|
|
117
|
+
- Built-in .NET 8 runtime automatic installation.
|
|
118
|
+
|
|
119
|
+
For more detailed API documentation, please visit: [LECPython API Documentation](http://www.lecpserver.com:3003/)
|
|
120
|
+
|
|
121
|
+
# License
|
|
122
|
+
|
|
123
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
124
|
+
|
|
125
|
+
-----
|
|
126
|
+
|
|
127
|
+
# LECPython (中文)
|
|
128
|
+
|
|
129
|
+
LECPython 是一个用 C# 开发的 Python 组件,能够实现 Python 与 PLC 之间的无缝通信。它需要 .NET 8 运行时支持,当首次调用 LECPython 时,组件会自动检查是否安装了 .NET 8,如果没有,它将自动在线安装。
|
|
130
|
+
|
|
131
|
+
LECPython 支持市场上广泛的 PLC,包括支持 Modbus 协议的 PLC、三菱、西门子、欧姆龙、罗克韦尔、基恩士、台达、倍福、松下、汇川、富士、EverSensing、施耐德等。该组件是独立的,不需要额外的第三方 PLC 控件支持。
|
|
132
|
+
|
|
133
|
+
# 简介
|
|
134
|
+
|
|
135
|
+
LECPython 提供了一种简单而高效的方式来连接和通信各种 PLC。无论是工业自动化还是其他需要 PLC 控制的应用,LECPython 都能提供可靠的解决方案。由于 LECPython 是基于 C# 开发的,因此其运行读写效率会比纯 Python 快。
|
|
136
|
+
|
|
137
|
+
LECPython 的运行过程如下:首先通过 `DeviceProfinetConnection` 创建一个连接器,但此时并不会与 PLC 进行连接。在第一次读写 PLC 时,通过 `DeviceProfinetCommunication` 操作,对 PLC 进行实际的连接和通讯。连接器自动完成长连接和断线重连的机制,只要 `DeviceProfinetConnection` 对象不被清除,连接器就一直有效。同时,用户可以通过设置连接器的 `data_format` 和 `is_string_reverse_byte_word` 来实现 PLC 的高低位读取设定。
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# 使用指南
|
|
143
|
+
|
|
144
|
+
## 安装
|
|
145
|
+
|
|
146
|
+
确保你已经安装了 Python。你可以使用 pip 安装 LECPython:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pip install LECPython
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
LECPython 会自动安装所需的 `pythonnet` 依赖项。如果需要,你也可以手动安装:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
pip install pythonnet==3.0.4
|
|
156
|
+
```
|
|
157
|
+
## .NET 8 安装
|
|
158
|
+
|
|
159
|
+
LECPython 需要 .NET 8 运行时支持。当你第一次调用 LECPython 时,组件会自动检查系统中是否安装了 .NET 8。如果没有安装,LECPython 将会自动在线安装 .NET 8 运行时。
|
|
160
|
+
|
|
161
|
+
### 自动安装步骤
|
|
162
|
+
|
|
163
|
+
1. 当你第一次运行 LECPython 时,组件会检测系统中是否存在 .NET 8 运行时。
|
|
164
|
+
2. 如果没有检测到 .NET 8 运行时,LECPython 将会尝试在线下载并安装 .NET 8。
|
|
165
|
+
3. 安装过程会根据操作系统的不同而有所不同。如果自动安装失败,LECPython 会提示你手动安装 .NET 8。
|
|
166
|
+
|
|
167
|
+
### 手动安装
|
|
168
|
+
|
|
169
|
+
如果自动安装失败,你可以根据以下步骤手动安装 .NET 8:
|
|
170
|
+
|
|
171
|
+
- 对于 Windows 用户:
|
|
172
|
+
1. 访问 .NET 官方网站:https://dotnet.microsoft.com/download/dotnet/8.0
|
|
173
|
+
2. 下载并运行适用于 Windows 的安装程序。
|
|
174
|
+
|
|
175
|
+
- 对于 Ubuntu 用户:
|
|
176
|
+
```bash
|
|
177
|
+
wget https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-8.0.0-linux-x64-binaries
|
|
178
|
+
tar -zxf dotnet-runtime-8.0.0-linux-x64.tar.gz -C $HOME/dotnet
|
|
179
|
+
export PATH=$PATH:$HOME/dotnet
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- 对于其他 Linux 发行版用户,请参考 .NET 官方网站上的安装指南。
|
|
183
|
+
|
|
184
|
+
### 支持的系统
|
|
185
|
+
|
|
186
|
+
LECPython 已在以下系统上测试并确认可以自动完成 .NET 8 的安装:
|
|
187
|
+
- Ubuntu 20.04, 22.04
|
|
188
|
+
- Windows 11 WSL2 环境
|
|
189
|
+
- Windows 11 PowerShell 环境
|
|
190
|
+
- 树莓派的 Raspbian OS 环境
|
|
191
|
+
|
|
192
|
+
## 使用示例
|
|
193
|
+
|
|
194
|
+
以下是一个如何使用 LECPython 的基本示例:
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from LECPython import LECPython
|
|
198
|
+
|
|
199
|
+
if __name__ == "__main__":
|
|
200
|
+
lecp = LECPython()
|
|
201
|
+
try:
|
|
202
|
+
# 开启连接器 欧姆龙 FINS PLC
|
|
203
|
+
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
204
|
+
print("Omron FINS PLC Connection 调用成功:", result["ErrorCode"])
|
|
205
|
+
|
|
206
|
+
# 从地址 D100 读取 10 个浮点值
|
|
207
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
208
|
+
print(f"读取的值是: {rtval}")
|
|
209
|
+
|
|
210
|
+
# 向地址 D100 写入浮点值
|
|
211
|
+
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
212
|
+
print(f"写入的值是: {rtval}")
|
|
213
|
+
|
|
214
|
+
# 再次从地址 D100 读取 10 个浮点值
|
|
215
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
216
|
+
print(f"读取的值是: {rtval}")
|
|
217
|
+
|
|
218
|
+
# 关闭连接器
|
|
219
|
+
lecp.ConnectClose(result["Content"])
|
|
220
|
+
except AttributeError as e:
|
|
221
|
+
print(e)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
# 特点
|
|
225
|
+
|
|
226
|
+
- 支持多种 PLC 协议,包括 Modbus、三菱、西门子、欧姆龙、罗克韦尔等。
|
|
227
|
+
- 提供易于使用的 API,用于连接和通信 PLC。
|
|
228
|
+
- 独立组件,无需额外的第三方 PLC 控件。
|
|
229
|
+
- 自带 .NET 8 运行时自动安装。
|
|
230
|
+
-
|
|
231
|
+
需要了解更多的API信息,请查阅官方文档: [LECPython API Documentation](http://www.lecpserver.com:3003/)
|
|
232
|
+
|
|
233
|
+
# 许可证
|
|
234
|
+
|
|
235
|
+
此项目根据 MIT 许可证授权。详情请参阅 [LICENSE](LICENSE) 文件。
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# LECPython
|
|
2
|
+
|
|
3
|
+
LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It requires .NET 8 runtime support. When LECPython is called for the first time, the component automatically checks if .NET 8 is installed, and if not, it will perform an automatic online installation.
|
|
4
|
+
|
|
5
|
+
LECPython supports a wide range of PLCs available in the market, including those supporting the Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.
|
|
6
|
+
|
|
7
|
+
# Introduction
|
|
8
|
+
|
|
9
|
+
LECPython provides a simple and efficient way to connect and communicate with various PLCs. Whether for industrial automation or other applications requiring PLC control, LECPython offers a reliable solution. Since LECPython is developed in C#, its read and write efficiency is faster than pure Python.
|
|
10
|
+
|
|
11
|
+
The operation process of LECPython is as follows: First, a connector is created through `DeviceProfinetConnection`, but it does not connect to the PLC at this time. During the first read and write operation to the PLC, the actual connection and communication with the PLC are performed through `DeviceProfinetCommunication`. The connector automatically completes the long connection and reconnection mechanism. As long as the `DeviceProfinetConnection` object is not cleared, the connector remains effective. Meanwhile, users can set the connector's `data_format` and `is_string_reverse_byte_word` to achieve high and low byte read settings for the PLC.
|
|
12
|
+
|
|
13
|
+
# Getting Started
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Ensure you have Python installed. You can install LECPython using pip:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install LECPython
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
LECPython automatically installs the required `pythonnet` dependency. However, if needed, you can manually install it using:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install pythonnet==3.0.4
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## .NET 8 Installation
|
|
30
|
+
|
|
31
|
+
LECPython requires .NET 8 runtime support. When you call LECPython for the first time, the component will automatically check if .NET 8 is installed on your system. If not, LECPython will automatically install the .NET 8 runtime online.
|
|
32
|
+
|
|
33
|
+
### Automatic Installation Steps
|
|
34
|
+
|
|
35
|
+
1. When you run LECPython for the first time, the component will check if .NET 8 runtime is present on your system.
|
|
36
|
+
2. If .NET 8 runtime is not detected, LECPython will attempt to download and install .NET 8 online.
|
|
37
|
+
3. The installation process will vary depending on the operating system. If the automatic installation fails, LECPython will prompt you to manually install .NET 8.
|
|
38
|
+
|
|
39
|
+
### Manual Installation
|
|
40
|
+
|
|
41
|
+
If the automatic installation fails, you can manually install .NET 8 by following these steps:
|
|
42
|
+
|
|
43
|
+
- For Windows users:
|
|
44
|
+
1. Visit the official .NET website: https://dotnet.microsoft.com/download/dotnet/8.0
|
|
45
|
+
2. Download and run the installer for Windows.
|
|
46
|
+
|
|
47
|
+
- For Ubuntu users:
|
|
48
|
+
```bash
|
|
49
|
+
wget https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-8.0.0-linux-x64-binaries
|
|
50
|
+
tar -zxf dotnet-runtime-8.0.0-linux-x64.tar.gz -C $HOME/dotnet
|
|
51
|
+
export PATH=$PATH:$HOME/dotnet
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- For users of other Linux distributions, please refer to the installation guide on the official .NET website.
|
|
55
|
+
|
|
56
|
+
### Supported Systems
|
|
57
|
+
|
|
58
|
+
LECPython has been tested and confirmed to automatically complete the .NET 8 installation on the following systems:
|
|
59
|
+
- Ubuntu 20.04, 22.04
|
|
60
|
+
- Windows 11 WSL2 environment
|
|
61
|
+
- Windows 11 PowerShell environment
|
|
62
|
+
- Raspbian OS environment on Raspberry Pi
|
|
63
|
+
|
|
64
|
+
## Usage Example
|
|
65
|
+
|
|
66
|
+
Here's a basic example of how to use LECPython:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from LECPython import LECPython
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
lecp = LECPython()
|
|
73
|
+
try:
|
|
74
|
+
# Establish connection to Omron FINS PLC
|
|
75
|
+
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
76
|
+
print("Omron FINS PLC Connection called successfully:", result["ErrorCode"])
|
|
77
|
+
|
|
78
|
+
# Read 10 float values from address D100
|
|
79
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
80
|
+
print(f"The PLC read rtval is: {rtval}")
|
|
81
|
+
|
|
82
|
+
# Write a float value to address D100
|
|
83
|
+
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
84
|
+
print(f"The PLC write rtval is: {rtval}")
|
|
85
|
+
|
|
86
|
+
# Read 10 float values from address D100 again
|
|
87
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
88
|
+
print(f"The PLC read rtval is: {rtval}")
|
|
89
|
+
|
|
90
|
+
# Close connection
|
|
91
|
+
lecp.ConnectClose(result["Content"])
|
|
92
|
+
except AttributeError as e:
|
|
93
|
+
print(e)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# Features
|
|
98
|
+
|
|
99
|
+
- Supports multiple PLC protocols including Modbus, Mitsubishi, Siemens, Omron, Rockwell, and more.
|
|
100
|
+
- Easy to use API for connecting and communicating with PLCs.
|
|
101
|
+
- Standalone component with no need for additional third-party PLC controls.
|
|
102
|
+
- Built-in .NET 8 runtime automatic installation.
|
|
103
|
+
|
|
104
|
+
For more detailed API documentation, please visit: [LECPython API Documentation](http://www.lecpserver.com:3003/)
|
|
105
|
+
|
|
106
|
+
# License
|
|
107
|
+
|
|
108
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
109
|
+
|
|
110
|
+
-----
|
|
111
|
+
|
|
112
|
+
# LECPython (中文)
|
|
113
|
+
|
|
114
|
+
LECPython 是一个用 C# 开发的 Python 组件,能够实现 Python 与 PLC 之间的无缝通信。它需要 .NET 8 运行时支持,当首次调用 LECPython 时,组件会自动检查是否安装了 .NET 8,如果没有,它将自动在线安装。
|
|
115
|
+
|
|
116
|
+
LECPython 支持市场上广泛的 PLC,包括支持 Modbus 协议的 PLC、三菱、西门子、欧姆龙、罗克韦尔、基恩士、台达、倍福、松下、汇川、富士、EverSensing、施耐德等。该组件是独立的,不需要额外的第三方 PLC 控件支持。
|
|
117
|
+
|
|
118
|
+
# 简介
|
|
119
|
+
|
|
120
|
+
LECPython 提供了一种简单而高效的方式来连接和通信各种 PLC。无论是工业自动化还是其他需要 PLC 控制的应用,LECPython 都能提供可靠的解决方案。由于 LECPython 是基于 C# 开发的,因此其运行读写效率会比纯 Python 快。
|
|
121
|
+
|
|
122
|
+
LECPython 的运行过程如下:首先通过 `DeviceProfinetConnection` 创建一个连接器,但此时并不会与 PLC 进行连接。在第一次读写 PLC 时,通过 `DeviceProfinetCommunication` 操作,对 PLC 进行实际的连接和通讯。连接器自动完成长连接和断线重连的机制,只要 `DeviceProfinetConnection` 对象不被清除,连接器就一直有效。同时,用户可以通过设置连接器的 `data_format` 和 `is_string_reverse_byte_word` 来实现 PLC 的高低位读取设定。
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# 使用指南
|
|
128
|
+
|
|
129
|
+
## 安装
|
|
130
|
+
|
|
131
|
+
确保你已经安装了 Python。你可以使用 pip 安装 LECPython:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
pip install LECPython
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
LECPython 会自动安装所需的 `pythonnet` 依赖项。如果需要,你也可以手动安装:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pip install pythonnet==3.0.4
|
|
141
|
+
```
|
|
142
|
+
## .NET 8 安装
|
|
143
|
+
|
|
144
|
+
LECPython 需要 .NET 8 运行时支持。当你第一次调用 LECPython 时,组件会自动检查系统中是否安装了 .NET 8。如果没有安装,LECPython 将会自动在线安装 .NET 8 运行时。
|
|
145
|
+
|
|
146
|
+
### 自动安装步骤
|
|
147
|
+
|
|
148
|
+
1. 当你第一次运行 LECPython 时,组件会检测系统中是否存在 .NET 8 运行时。
|
|
149
|
+
2. 如果没有检测到 .NET 8 运行时,LECPython 将会尝试在线下载并安装 .NET 8。
|
|
150
|
+
3. 安装过程会根据操作系统的不同而有所不同。如果自动安装失败,LECPython 会提示你手动安装 .NET 8。
|
|
151
|
+
|
|
152
|
+
### 手动安装
|
|
153
|
+
|
|
154
|
+
如果自动安装失败,你可以根据以下步骤手动安装 .NET 8:
|
|
155
|
+
|
|
156
|
+
- 对于 Windows 用户:
|
|
157
|
+
1. 访问 .NET 官方网站:https://dotnet.microsoft.com/download/dotnet/8.0
|
|
158
|
+
2. 下载并运行适用于 Windows 的安装程序。
|
|
159
|
+
|
|
160
|
+
- 对于 Ubuntu 用户:
|
|
161
|
+
```bash
|
|
162
|
+
wget https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-8.0.0-linux-x64-binaries
|
|
163
|
+
tar -zxf dotnet-runtime-8.0.0-linux-x64.tar.gz -C $HOME/dotnet
|
|
164
|
+
export PATH=$PATH:$HOME/dotnet
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
- 对于其他 Linux 发行版用户,请参考 .NET 官方网站上的安装指南。
|
|
168
|
+
|
|
169
|
+
### 支持的系统
|
|
170
|
+
|
|
171
|
+
LECPython 已在以下系统上测试并确认可以自动完成 .NET 8 的安装:
|
|
172
|
+
- Ubuntu 20.04, 22.04
|
|
173
|
+
- Windows 11 WSL2 环境
|
|
174
|
+
- Windows 11 PowerShell 环境
|
|
175
|
+
- 树莓派的 Raspbian OS 环境
|
|
176
|
+
|
|
177
|
+
## 使用示例
|
|
178
|
+
|
|
179
|
+
以下是一个如何使用 LECPython 的基本示例:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from LECPython import LECPython
|
|
183
|
+
|
|
184
|
+
if __name__ == "__main__":
|
|
185
|
+
lecp = LECPython()
|
|
186
|
+
try:
|
|
187
|
+
# 开启连接器 欧姆龙 FINS PLC
|
|
188
|
+
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
189
|
+
print("Omron FINS PLC Connection 调用成功:", result["ErrorCode"])
|
|
190
|
+
|
|
191
|
+
# 从地址 D100 读取 10 个浮点值
|
|
192
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
193
|
+
print(f"读取的值是: {rtval}")
|
|
194
|
+
|
|
195
|
+
# 向地址 D100 写入浮点值
|
|
196
|
+
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
197
|
+
print(f"写入的值是: {rtval}")
|
|
198
|
+
|
|
199
|
+
# 再次从地址 D100 读取 10 个浮点值
|
|
200
|
+
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
201
|
+
print(f"读取的值是: {rtval}")
|
|
202
|
+
|
|
203
|
+
# 关闭连接器
|
|
204
|
+
lecp.ConnectClose(result["Content"])
|
|
205
|
+
except AttributeError as e:
|
|
206
|
+
print(e)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
# 特点
|
|
210
|
+
|
|
211
|
+
- 支持多种 PLC 协议,包括 Modbus、三菱、西门子、欧姆龙、罗克韦尔等。
|
|
212
|
+
- 提供易于使用的 API,用于连接和通信 PLC。
|
|
213
|
+
- 独立组件,无需额外的第三方 PLC 控件。
|
|
214
|
+
- 自带 .NET 8 运行时自动安装。
|
|
215
|
+
-
|
|
216
|
+
需要了解更多的API信息,请查阅官方文档: [LECPython API Documentation](http://www.lecpserver.com:3003/)
|
|
217
|
+
|
|
218
|
+
# 许可证
|
|
219
|
+
|
|
220
|
+
此项目根据 MIT 许可证授权。详情请参阅 [LICENSE](LICENSE) 文件。
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='LECPython',
|
|
5
|
+
version='1.2.2.6',
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
include_package_data=True,
|
|
8
|
+
package_data={
|
|
9
|
+
'LECPythonLib': ['*.pdb', '*.dll', '*.so', '*.json'],
|
|
10
|
+
},
|
|
11
|
+
install_requires=[
|
|
12
|
+
'pythonnet==3.0.4', # 固定安装pythonnet版本为3.0.4
|
|
13
|
+
],
|
|
14
|
+
author='xeden3',
|
|
15
|
+
author_email='james@sctmes.com',
|
|
16
|
+
description='LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs...',
|
|
17
|
+
long_description=open('README.md').read(),
|
|
18
|
+
long_description_content_type='text/markdown',
|
|
19
|
+
url='https://github.com/xeden3/LECPython',
|
|
20
|
+
project_urls={ # 添加项目相关的额外URL
|
|
21
|
+
'Documentation': 'http://lecpserver.com:3003/', # 替换为你的文档地址
|
|
22
|
+
'Source': 'https://github.com/xeden3/LECPython',
|
|
23
|
+
'Bug Tracker': 'https://github.com/xeden3/LECPython/issues',
|
|
24
|
+
},
|
|
25
|
+
classifiers=[
|
|
26
|
+
'Programming Language :: Python :: 3',
|
|
27
|
+
'License :: OSI Approved :: MIT License',
|
|
28
|
+
],
|
|
29
|
+
)
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: LECPython
|
|
3
|
-
Version: 1.2.0.6
|
|
4
|
-
Summary: LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It supports the majority of PLCs available in the market, including those supporting Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.
|
|
5
|
-
Home-page: https://github.com/xeden3/LECPython
|
|
6
|
-
Author: xeden3
|
|
7
|
-
Author-email: james@sctmes.com
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
Requires-Dist: pythonnet==3.0.4
|
|
12
|
-
|
|
13
|
-
# LECPython
|
|
14
|
-
|
|
15
|
-
LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It requires .NET 8 runtime support,When LECPython is called for the first time, the component automatically checks if .NET 8 is installed, and if not, it will perform an automatic online installation.
|
|
16
|
-
|
|
17
|
-
LECPython supports a wide range of PLCs available in the market, including those supporting the Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
Ensure you have Python installed. You can install LECPython using pip:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
pip install LECPython
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
LECPython automatically installs the required `pythonnet` dependency. However, if needed, you can manually install it using:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
pip install pythonnet==3.0.4
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Usage
|
|
34
|
-
|
|
35
|
-
Here's a basic example of how to use LECPython:
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
from LECPython import LECPython
|
|
39
|
-
|
|
40
|
-
if __name__ == "__main__":
|
|
41
|
-
lecp = LECPython()
|
|
42
|
-
try:
|
|
43
|
-
# Establish connection to Omron FINS PLC
|
|
44
|
-
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
45
|
-
print("ModbusTcpNetConnection called successfully:", result["ErrorCode"])
|
|
46
|
-
|
|
47
|
-
# Read 10 float values from address D100
|
|
48
|
-
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
49
|
-
print(f"The rtval is: {rtval}")
|
|
50
|
-
|
|
51
|
-
# Write a float value to address D100
|
|
52
|
-
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
53
|
-
print(f"The rtval is: {rtval}")
|
|
54
|
-
|
|
55
|
-
# Read 10 float values from address D100 again
|
|
56
|
-
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
57
|
-
print(f"The rtval is: {rtval}")
|
|
58
|
-
except AttributeError as e:
|
|
59
|
-
print(e)
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Features
|
|
63
|
-
|
|
64
|
-
- Supports multiple PLC protocols including Modbus, Mitsubishi, Siemens, Omron, Rockwell and more.
|
|
65
|
-
- Easy to use API for connecting and communicating with PLCs.
|
|
66
|
-
- Standalone component with no need for additional third-party PLC controls.
|
|
67
|
-
|
|
68
|
-
## License
|
|
69
|
-
|
|
70
|
-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
lecpython-1.2.0.6/PKG-INFO
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: LECPython
|
|
3
|
-
Version: 1.2.0.6
|
|
4
|
-
Summary: LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It supports the majority of PLCs available in the market, including those supporting Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.
|
|
5
|
-
Home-page: https://github.com/xeden3/LECPython
|
|
6
|
-
Author: xeden3
|
|
7
|
-
Author-email: james@sctmes.com
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
Requires-Dist: pythonnet==3.0.4
|
|
12
|
-
|
|
13
|
-
# LECPython
|
|
14
|
-
|
|
15
|
-
LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It requires .NET 8 runtime support,When LECPython is called for the first time, the component automatically checks if .NET 8 is installed, and if not, it will perform an automatic online installation.
|
|
16
|
-
|
|
17
|
-
LECPython supports a wide range of PLCs available in the market, including those supporting the Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
Ensure you have Python installed. You can install LECPython using pip:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
pip install LECPython
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
LECPython automatically installs the required `pythonnet` dependency. However, if needed, you can manually install it using:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
pip install pythonnet==3.0.4
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Usage
|
|
34
|
-
|
|
35
|
-
Here's a basic example of how to use LECPython:
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
from LECPython import LECPython
|
|
39
|
-
|
|
40
|
-
if __name__ == "__main__":
|
|
41
|
-
lecp = LECPython()
|
|
42
|
-
try:
|
|
43
|
-
# Establish connection to Omron FINS PLC
|
|
44
|
-
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
45
|
-
print("ModbusTcpNetConnection called successfully:", result["ErrorCode"])
|
|
46
|
-
|
|
47
|
-
# Read 10 float values from address D100
|
|
48
|
-
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
49
|
-
print(f"The rtval is: {rtval}")
|
|
50
|
-
|
|
51
|
-
# Write a float value to address D100
|
|
52
|
-
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
53
|
-
print(f"The rtval is: {rtval}")
|
|
54
|
-
|
|
55
|
-
# Read 10 float values from address D100 again
|
|
56
|
-
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
57
|
-
print(f"The rtval is: {rtval}")
|
|
58
|
-
except AttributeError as e:
|
|
59
|
-
print(e)
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Features
|
|
63
|
-
|
|
64
|
-
- Supports multiple PLC protocols including Modbus, Mitsubishi, Siemens, Omron, Rockwell and more.
|
|
65
|
-
- Easy to use API for connecting and communicating with PLCs.
|
|
66
|
-
- Standalone component with no need for additional third-party PLC controls.
|
|
67
|
-
|
|
68
|
-
## License
|
|
69
|
-
|
|
70
|
-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
lecpython-1.2.0.6/README.md
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# LECPython
|
|
2
|
-
|
|
3
|
-
LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It requires .NET 8 runtime support,When LECPython is called for the first time, the component automatically checks if .NET 8 is installed, and if not, it will perform an automatic online installation.
|
|
4
|
-
|
|
5
|
-
LECPython supports a wide range of PLCs available in the market, including those supporting the Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
Ensure you have Python installed. You can install LECPython using pip:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
pip install LECPython
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
LECPython automatically installs the required `pythonnet` dependency. However, if needed, you can manually install it using:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
pip install pythonnet==3.0.4
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
Here's a basic example of how to use LECPython:
|
|
24
|
-
|
|
25
|
-
```python
|
|
26
|
-
from LECPython import LECPython
|
|
27
|
-
|
|
28
|
-
if __name__ == "__main__":
|
|
29
|
-
lecp = LECPython()
|
|
30
|
-
try:
|
|
31
|
-
# Establish connection to Omron FINS PLC
|
|
32
|
-
result = lecp.OmronFinsNetConnection("192.168.31.64", 9600, 13, 0, "CDAB", True, 2000)
|
|
33
|
-
print("ModbusTcpNetConnection called successfully:", result["ErrorCode"])
|
|
34
|
-
|
|
35
|
-
# Read 10 float values from address D100
|
|
36
|
-
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
37
|
-
print(f"The rtval is: {rtval}")
|
|
38
|
-
|
|
39
|
-
# Write a float value to address D100
|
|
40
|
-
rtval = lecp.WriteNodeValues(result["Content"], "D100", "float", [88.123, 726.1223])
|
|
41
|
-
print(f"The rtval is: {rtval}")
|
|
42
|
-
|
|
43
|
-
# Read 10 float values from address D100 again
|
|
44
|
-
rtval = lecp.ReadNodeValues(result["Content"], "D100", "float", 10)
|
|
45
|
-
print(f"The rtval is: {rtval}")
|
|
46
|
-
except AttributeError as e:
|
|
47
|
-
print(e)
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Features
|
|
51
|
-
|
|
52
|
-
- Supports multiple PLC protocols including Modbus, Mitsubishi, Siemens, Omron, Rockwell and more.
|
|
53
|
-
- Easy to use API for connecting and communicating with PLCs.
|
|
54
|
-
- Standalone component with no need for additional third-party PLC controls.
|
|
55
|
-
|
|
56
|
-
## License
|
|
57
|
-
|
|
58
|
-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
lecpython-1.2.0.6/setup.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# setup.py
|
|
2
|
-
from setuptools import setup, find_packages
|
|
3
|
-
|
|
4
|
-
setup(
|
|
5
|
-
name='LECPython',
|
|
6
|
-
version='1.2.0.6',
|
|
7
|
-
packages=find_packages(),
|
|
8
|
-
include_package_data=True,
|
|
9
|
-
package_data={
|
|
10
|
-
# 包含依赖文件的路径
|
|
11
|
-
'LECPythonLib': ['*.pdb','*.dll', '*.so', '*.json'],
|
|
12
|
-
},
|
|
13
|
-
install_requires=[
|
|
14
|
-
'pythonnet==3.0.4', # 固定安装pythonnet版本为3.0.1。可通过 `pip show pythonnet` 查看当前版本
|
|
15
|
-
],
|
|
16
|
-
author='xeden3',
|
|
17
|
-
author_email='james@sctmes.com',
|
|
18
|
-
description='LECPython is a Python component developed in C# that enables seamless communication between Python and PLCs. It supports the majority of PLCs available in the market, including those supporting Modbus protocol, Mitsubishi, Siemens, Omron, Rockwell, Keyence PLC, Delta, Beckhoff, Panasonic, Inovance, Fuji, EverSensing, Schneider, and more. This component is standalone, requiring no additional third-party PLC controls for support.',
|
|
19
|
-
long_description=open('README.md').read(),
|
|
20
|
-
long_description_content_type='text/markdown',
|
|
21
|
-
url='https://github.com/xeden3/LECPython', # Replace with your repo URL
|
|
22
|
-
classifiers=[
|
|
23
|
-
'Programming Language :: Python :: 3',
|
|
24
|
-
'License :: OSI Approved :: MIT License',
|
|
25
|
-
],
|
|
26
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|