ethercat-master 0.1.0__tar.gz → 0.1.2__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.
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/PKG-INFO +90 -12
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/README.md +89 -11
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/bus.py +30 -3
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/slave.py +1 -1
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/webserver.py +14 -3
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master.egg-info/PKG-INFO +90 -12
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master.egg-info/SOURCES.txt +1 -1
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/pyproject.toml +2 -2
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/__init__.py +0 -0
- /ethercat_master-0.1.0/ethercat_master/pdo_mapping.json → /ethercat_master-0.1.2/ethercat_master/ethercat_config.json +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/exceptions.py +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/network_test.py +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/pdo.py +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/webgui/index.html +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master/webgui/style.css +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master.egg-info/dependency_links.txt +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master.egg-info/entry_points.txt +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master.egg-info/requires.txt +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master.egg-info/top_level.txt +0 -0
- {ethercat_master-0.1.0 → ethercat_master-0.1.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ethercat-master
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Generic EtherCAT master library built on PySOEM — bus management, PDO mapping, slave discovery
|
|
5
5
|
Author-email: Henschel Robotics GmbH <info@henschel-robotics.ch>
|
|
6
6
|
License: MIT
|
|
@@ -34,12 +34,14 @@ Generic EtherCAT master library built on [PySOEM](https://github.com/bnjmnp/pyso
|
|
|
34
34
|
|
|
35
35
|
Developed by [Henschel Robotics GmbH](https://henschel-robotics.ch).
|
|
36
36
|
|
|
37
|
+

|
|
38
|
+
|
|
37
39
|
## Features
|
|
38
40
|
|
|
39
41
|
- **Bus management** -- connect, configure, and run an EtherCAT bus with one or more slaves
|
|
40
42
|
- **Generic slave handle** -- read/write raw PDO bytes for any device (Beckhoff terminals, servos, I/O modules, ...)
|
|
41
43
|
- **PDO mapping** -- configure SyncManager assignments per slave via a JSON file or SDO writes
|
|
42
|
-
- **Bus discovery** -- scan the bus and
|
|
44
|
+
- **Bus discovery** -- scan the bus and detect any EtherCAT device (Beckhoff, Henschel, or any other vendor)
|
|
43
45
|
- **Auto-reconnect** -- background health monitoring with automatic recovery on cable disconnect
|
|
44
46
|
- **Web interface** -- built-in browser GUI for adapter selection, bus scanning, PDO configuration, and going OP
|
|
45
47
|
- **Extensible** -- subclass `GenericSlave` or implement the slave handle interface to build device-specific drivers (see [python-hdrive-etc](https://github.com/henschel-robotics/python-hdrive-etc))
|
|
@@ -70,14 +72,42 @@ sudo apt install libpcap-dev
|
|
|
70
72
|
sudo dnf install libpcap-devel
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
On Linux
|
|
75
|
+
On Linux, raw Ethernet access requires **root**. Either run with `sudo` or grant the capability once:
|
|
74
76
|
|
|
75
77
|
```bash
|
|
76
|
-
|
|
78
|
+
# Option A – run with sudo
|
|
79
|
+
sudo pip install ethercat-master --break-system-packages
|
|
80
|
+
sudo ecmaster-web
|
|
81
|
+
|
|
82
|
+
# Option B – grant raw socket capability (no sudo needed afterwards)
|
|
83
|
+
sudo setcap cap_net_raw=ep $(readlink -f $(which python3))
|
|
77
84
|
```
|
|
78
85
|
|
|
79
86
|
> Npcap is **not** needed on Linux -- `libpcap` provides the same functionality and is BSD-licensed.
|
|
80
87
|
|
|
88
|
+
### Raspberry Pi Quick-Start
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# 1. Install libpcap
|
|
92
|
+
sudo apt update
|
|
93
|
+
sudo apt install libpcap-dev
|
|
94
|
+
|
|
95
|
+
# 2. Install ethercat-master system-wide (so sudo can find it)
|
|
96
|
+
sudo pip install ethercat-master --break-system-packages
|
|
97
|
+
|
|
98
|
+
# 3. Add ~/.local/bin to PATH (if not already)
|
|
99
|
+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
|
|
100
|
+
source ~/.bashrc
|
|
101
|
+
|
|
102
|
+
# 4. Launch the web interface (requires root for raw Ethernet)
|
|
103
|
+
sudo ecmaster-web --adapter eth0
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Open `http://<pi-ip>:8080` from any device on your network.
|
|
107
|
+
|
|
108
|
+
> Connect the EtherCAT slave(s) directly to the Pi's Ethernet port (`eth0`).
|
|
109
|
+
> Use Wi-Fi or a second USB-Ethernet adapter for SSH / network access.
|
|
110
|
+
|
|
81
111
|
### Python
|
|
82
112
|
|
|
83
113
|
- **Python 3.8+**
|
|
@@ -143,7 +173,7 @@ for s in slaves:
|
|
|
143
173
|
|
|
144
174
|
## PDO Configuration
|
|
145
175
|
|
|
146
|
-
Create a `
|
|
176
|
+
Create a `ethercat_config.json` to control which PDOs are assigned per slave:
|
|
147
177
|
|
|
148
178
|
```json
|
|
149
179
|
{
|
|
@@ -164,27 +194,44 @@ Create a `pdo_mapping.json` to control which PDOs are assigned per slave:
|
|
|
164
194
|
Pass it when creating the bus:
|
|
165
195
|
|
|
166
196
|
```python
|
|
167
|
-
bus = EtherCATBus(adapter=..., cycle_time_ms=1, pdo_config_path="
|
|
197
|
+
bus = EtherCATBus(adapter=..., cycle_time_ms=1, pdo_config_path="ethercat_config.json")
|
|
168
198
|
```
|
|
169
199
|
|
|
170
200
|
Or use the web interface to scan the bus, select PDOs with checkboxes, and save.
|
|
171
201
|
|
|
202
|
+
> **Raspberry Pi / Linux:** When installed via pip, the default `ethercat_config.json` is inside the package directory (e.g. `/usr/local/lib/python3.13/dist-packages/ethercat_master/ethercat_config.json`). Copy it to your working directory for easy editing:
|
|
203
|
+
>
|
|
204
|
+
> ```bash
|
|
205
|
+
> cp $(python3 -c "import ethercat_master, os; print(os.path.join(os.path.dirname(ethercat_master.__file__), 'ethercat_config.json'))") .
|
|
206
|
+
> ```
|
|
207
|
+
|
|
172
208
|
## Web Interface
|
|
173
209
|
|
|
174
210
|
Start the built-in web server:
|
|
175
211
|
|
|
176
212
|
```bash
|
|
177
|
-
ecmaster-web
|
|
178
|
-
ecmaster-web --port 8080
|
|
179
|
-
ecmaster-web --pdo-config /path/to/
|
|
213
|
+
sudo ecmaster-web
|
|
214
|
+
sudo ecmaster-web --port 8080
|
|
215
|
+
sudo ecmaster-web --pdo-config /path/to/ethercat_config.json
|
|
180
216
|
```
|
|
181
217
|
|
|
182
|
-
Then open `http://localhost:8080` in your browser.
|
|
218
|
+
Then open `http://localhost:8080` in your browser.
|
|
219
|
+
|
|
220
|
+

|
|
221
|
+
|
|
222
|
+
The web GUI lets you:
|
|
183
223
|
|
|
184
224
|
- Select a network adapter
|
|
185
|
-
- Scan the bus and
|
|
225
|
+
- Scan the bus and discover **any EtherCAT device** — Beckhoff terminals, IO modules, servo drives, and more
|
|
186
226
|
- Configure PDO assignments per slave
|
|
187
227
|
- Set the cycle time and go to OP state
|
|
228
|
+
- Run network latency tests (SDO round-trip measurement with histogram)
|
|
229
|
+
|
|
230
|
+
| Mixed bus (Beckhoff + HDrive) | Network Latency Test |
|
|
231
|
+
|---|---|
|
|
232
|
+
|  |  |
|
|
233
|
+
|
|
234
|
+
> **Full guide:** [`docs/web-interface.md`](docs/web-interface.md)
|
|
188
235
|
|
|
189
236
|
## Project Structure
|
|
190
237
|
|
|
@@ -204,10 +251,41 @@ python-ethercat-master/
|
|
|
204
251
|
│ ├── connect.py # Minimal single-slave example
|
|
205
252
|
│ ├── beckhoff.py # Beckhoff EK1100 + terminals
|
|
206
253
|
│ └── mixed_bus.py # HDrive motor + Beckhoff terminals
|
|
207
|
-
├──
|
|
254
|
+
├── ethercat_config.json # Example PDO config
|
|
208
255
|
└── pyproject.toml
|
|
209
256
|
```
|
|
210
257
|
|
|
258
|
+
## Examples
|
|
259
|
+
|
|
260
|
+
The [`examples/`](examples/) folder contains ready-to-run scripts. The recommended workflow is:
|
|
261
|
+
|
|
262
|
+
1. **Configure the bus** using the web interface (`ecmaster-web`):
|
|
263
|
+
- Select your network adapter
|
|
264
|
+
- Click **Scan Bus** to discover all slaves
|
|
265
|
+
- Expand each slave and configure the PDO assignments
|
|
266
|
+
- Click **Save PDO Config** — this writes `ethercat_config.json` with the adapter, cycle time, and per-slave PDO mapping
|
|
267
|
+
|
|
268
|
+
2. **Copy `ethercat_config.json`** next to your script (or point to it with `pdo_config_path`)
|
|
269
|
+
|
|
270
|
+
3. **Run the example** — the bus uses the preconfigured adapter and PDO mapping from the file:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
sudo python3 examples/connect.py # Linux
|
|
274
|
+
python examples\connect.py # Windows
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### `connect.py` — Minimal single-slave example
|
|
278
|
+
|
|
279
|
+
Connects to one slave and continuously prints the raw input PDO bytes. Good for verifying that the bus works and PDOs are mapped correctly.
|
|
280
|
+
|
|
281
|
+
### `beckhoff.py` — Beckhoff coupler + terminals
|
|
282
|
+
|
|
283
|
+
Scans the bus, discovers all terminals behind an EK1100 coupler, and reads their inputs in a loop. Standard Beckhoff terminals use factory-default PDO mappings from the SII EEPROM, so no `ethercat_config.json` is needed.
|
|
284
|
+
|
|
285
|
+
### `mixed_bus.py` — HDrive motor + Beckhoff terminals
|
|
286
|
+
|
|
287
|
+
Demonstrates running an HDrive servo motor alongside Beckhoff I/O terminals on the same bus. Requires `pip install hdrive-etc`. The `HDriveETC` class is a slave handle that plugs into `EtherCATBus` just like `GenericSlave`, so you can combine any devices.
|
|
288
|
+
|
|
211
289
|
## API Overview
|
|
212
290
|
|
|
213
291
|
### `EtherCATBus`
|
|
@@ -4,12 +4,14 @@ Generic EtherCAT master library built on [PySOEM](https://github.com/bnjmnp/pyso
|
|
|
4
4
|
|
|
5
5
|
Developed by [Henschel Robotics GmbH](https://henschel-robotics.ch).
|
|
6
6
|
|
|
7
|
+

|
|
8
|
+
|
|
7
9
|
## Features
|
|
8
10
|
|
|
9
11
|
- **Bus management** -- connect, configure, and run an EtherCAT bus with one or more slaves
|
|
10
12
|
- **Generic slave handle** -- read/write raw PDO bytes for any device (Beckhoff terminals, servos, I/O modules, ...)
|
|
11
13
|
- **PDO mapping** -- configure SyncManager assignments per slave via a JSON file or SDO writes
|
|
12
|
-
- **Bus discovery** -- scan the bus and
|
|
14
|
+
- **Bus discovery** -- scan the bus and detect any EtherCAT device (Beckhoff, Henschel, or any other vendor)
|
|
13
15
|
- **Auto-reconnect** -- background health monitoring with automatic recovery on cable disconnect
|
|
14
16
|
- **Web interface** -- built-in browser GUI for adapter selection, bus scanning, PDO configuration, and going OP
|
|
15
17
|
- **Extensible** -- subclass `GenericSlave` or implement the slave handle interface to build device-specific drivers (see [python-hdrive-etc](https://github.com/henschel-robotics/python-hdrive-etc))
|
|
@@ -40,14 +42,42 @@ sudo apt install libpcap-dev
|
|
|
40
42
|
sudo dnf install libpcap-devel
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
On Linux
|
|
45
|
+
On Linux, raw Ethernet access requires **root**. Either run with `sudo` or grant the capability once:
|
|
44
46
|
|
|
45
47
|
```bash
|
|
46
|
-
|
|
48
|
+
# Option A – run with sudo
|
|
49
|
+
sudo pip install ethercat-master --break-system-packages
|
|
50
|
+
sudo ecmaster-web
|
|
51
|
+
|
|
52
|
+
# Option B – grant raw socket capability (no sudo needed afterwards)
|
|
53
|
+
sudo setcap cap_net_raw=ep $(readlink -f $(which python3))
|
|
47
54
|
```
|
|
48
55
|
|
|
49
56
|
> Npcap is **not** needed on Linux -- `libpcap` provides the same functionality and is BSD-licensed.
|
|
50
57
|
|
|
58
|
+
### Raspberry Pi Quick-Start
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# 1. Install libpcap
|
|
62
|
+
sudo apt update
|
|
63
|
+
sudo apt install libpcap-dev
|
|
64
|
+
|
|
65
|
+
# 2. Install ethercat-master system-wide (so sudo can find it)
|
|
66
|
+
sudo pip install ethercat-master --break-system-packages
|
|
67
|
+
|
|
68
|
+
# 3. Add ~/.local/bin to PATH (if not already)
|
|
69
|
+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
|
|
70
|
+
source ~/.bashrc
|
|
71
|
+
|
|
72
|
+
# 4. Launch the web interface (requires root for raw Ethernet)
|
|
73
|
+
sudo ecmaster-web --adapter eth0
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Open `http://<pi-ip>:8080` from any device on your network.
|
|
77
|
+
|
|
78
|
+
> Connect the EtherCAT slave(s) directly to the Pi's Ethernet port (`eth0`).
|
|
79
|
+
> Use Wi-Fi or a second USB-Ethernet adapter for SSH / network access.
|
|
80
|
+
|
|
51
81
|
### Python
|
|
52
82
|
|
|
53
83
|
- **Python 3.8+**
|
|
@@ -113,7 +143,7 @@ for s in slaves:
|
|
|
113
143
|
|
|
114
144
|
## PDO Configuration
|
|
115
145
|
|
|
116
|
-
Create a `
|
|
146
|
+
Create a `ethercat_config.json` to control which PDOs are assigned per slave:
|
|
117
147
|
|
|
118
148
|
```json
|
|
119
149
|
{
|
|
@@ -134,27 +164,44 @@ Create a `pdo_mapping.json` to control which PDOs are assigned per slave:
|
|
|
134
164
|
Pass it when creating the bus:
|
|
135
165
|
|
|
136
166
|
```python
|
|
137
|
-
bus = EtherCATBus(adapter=..., cycle_time_ms=1, pdo_config_path="
|
|
167
|
+
bus = EtherCATBus(adapter=..., cycle_time_ms=1, pdo_config_path="ethercat_config.json")
|
|
138
168
|
```
|
|
139
169
|
|
|
140
170
|
Or use the web interface to scan the bus, select PDOs with checkboxes, and save.
|
|
141
171
|
|
|
172
|
+
> **Raspberry Pi / Linux:** When installed via pip, the default `ethercat_config.json` is inside the package directory (e.g. `/usr/local/lib/python3.13/dist-packages/ethercat_master/ethercat_config.json`). Copy it to your working directory for easy editing:
|
|
173
|
+
>
|
|
174
|
+
> ```bash
|
|
175
|
+
> cp $(python3 -c "import ethercat_master, os; print(os.path.join(os.path.dirname(ethercat_master.__file__), 'ethercat_config.json'))") .
|
|
176
|
+
> ```
|
|
177
|
+
|
|
142
178
|
## Web Interface
|
|
143
179
|
|
|
144
180
|
Start the built-in web server:
|
|
145
181
|
|
|
146
182
|
```bash
|
|
147
|
-
ecmaster-web
|
|
148
|
-
ecmaster-web --port 8080
|
|
149
|
-
ecmaster-web --pdo-config /path/to/
|
|
183
|
+
sudo ecmaster-web
|
|
184
|
+
sudo ecmaster-web --port 8080
|
|
185
|
+
sudo ecmaster-web --pdo-config /path/to/ethercat_config.json
|
|
150
186
|
```
|
|
151
187
|
|
|
152
|
-
Then open `http://localhost:8080` in your browser.
|
|
188
|
+
Then open `http://localhost:8080` in your browser.
|
|
189
|
+
|
|
190
|
+

|
|
191
|
+
|
|
192
|
+
The web GUI lets you:
|
|
153
193
|
|
|
154
194
|
- Select a network adapter
|
|
155
|
-
- Scan the bus and
|
|
195
|
+
- Scan the bus and discover **any EtherCAT device** — Beckhoff terminals, IO modules, servo drives, and more
|
|
156
196
|
- Configure PDO assignments per slave
|
|
157
197
|
- Set the cycle time and go to OP state
|
|
198
|
+
- Run network latency tests (SDO round-trip measurement with histogram)
|
|
199
|
+
|
|
200
|
+
| Mixed bus (Beckhoff + HDrive) | Network Latency Test |
|
|
201
|
+
|---|---|
|
|
202
|
+
|  |  |
|
|
203
|
+
|
|
204
|
+
> **Full guide:** [`docs/web-interface.md`](docs/web-interface.md)
|
|
158
205
|
|
|
159
206
|
## Project Structure
|
|
160
207
|
|
|
@@ -174,10 +221,41 @@ python-ethercat-master/
|
|
|
174
221
|
│ ├── connect.py # Minimal single-slave example
|
|
175
222
|
│ ├── beckhoff.py # Beckhoff EK1100 + terminals
|
|
176
223
|
│ └── mixed_bus.py # HDrive motor + Beckhoff terminals
|
|
177
|
-
├──
|
|
224
|
+
├── ethercat_config.json # Example PDO config
|
|
178
225
|
└── pyproject.toml
|
|
179
226
|
```
|
|
180
227
|
|
|
228
|
+
## Examples
|
|
229
|
+
|
|
230
|
+
The [`examples/`](examples/) folder contains ready-to-run scripts. The recommended workflow is:
|
|
231
|
+
|
|
232
|
+
1. **Configure the bus** using the web interface (`ecmaster-web`):
|
|
233
|
+
- Select your network adapter
|
|
234
|
+
- Click **Scan Bus** to discover all slaves
|
|
235
|
+
- Expand each slave and configure the PDO assignments
|
|
236
|
+
- Click **Save PDO Config** — this writes `ethercat_config.json` with the adapter, cycle time, and per-slave PDO mapping
|
|
237
|
+
|
|
238
|
+
2. **Copy `ethercat_config.json`** next to your script (or point to it with `pdo_config_path`)
|
|
239
|
+
|
|
240
|
+
3. **Run the example** — the bus uses the preconfigured adapter and PDO mapping from the file:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
sudo python3 examples/connect.py # Linux
|
|
244
|
+
python examples\connect.py # Windows
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### `connect.py` — Minimal single-slave example
|
|
248
|
+
|
|
249
|
+
Connects to one slave and continuously prints the raw input PDO bytes. Good for verifying that the bus works and PDOs are mapped correctly.
|
|
250
|
+
|
|
251
|
+
### `beckhoff.py` — Beckhoff coupler + terminals
|
|
252
|
+
|
|
253
|
+
Scans the bus, discovers all terminals behind an EK1100 coupler, and reads their inputs in a loop. Standard Beckhoff terminals use factory-default PDO mappings from the SII EEPROM, so no `ethercat_config.json` is needed.
|
|
254
|
+
|
|
255
|
+
### `mixed_bus.py` — HDrive motor + Beckhoff terminals
|
|
256
|
+
|
|
257
|
+
Demonstrates running an HDrive servo motor alongside Beckhoff I/O terminals on the same bus. Requires `pip install hdrive-etc`. The `HDriveETC` class is a slave handle that plugs into `EtherCATBus` just like `GenericSlave`, so you can combine any devices.
|
|
258
|
+
|
|
181
259
|
## API Overview
|
|
182
260
|
|
|
183
261
|
### `EtherCATBus`
|
|
@@ -37,9 +37,12 @@ Bus discovery (no OP transition)::
|
|
|
37
37
|
|
|
38
38
|
"""
|
|
39
39
|
|
|
40
|
+
import json
|
|
41
|
+
import os
|
|
40
42
|
import struct
|
|
41
43
|
import threading
|
|
42
44
|
import time
|
|
45
|
+
from pathlib import Path
|
|
43
46
|
|
|
44
47
|
import pysoem
|
|
45
48
|
|
|
@@ -79,15 +82,24 @@ class EtherCATBus:
|
|
|
79
82
|
``\\Device\\NPF_{GUID}``). Use :meth:`list_adapters` to
|
|
80
83
|
enumerate available adapters and their names.
|
|
81
84
|
cycle_time_ms: PDO update cycle time in milliseconds.
|
|
82
|
-
pdo_config_path: Optional path to
|
|
85
|
+
pdo_config_path: Optional path to an ``ethercat_config.json`` file.
|
|
83
86
|
When provided, per-slave PDO assignments are read from
|
|
84
87
|
this file instead of using the hardcoded defaults.
|
|
85
88
|
"""
|
|
86
89
|
|
|
87
90
|
def __init__(self, adapter=None, cycle_time_ms=10, pdo_config_path=None):
|
|
91
|
+
if pdo_config_path:
|
|
92
|
+
self.pdo_config = load_pdo_config(pdo_config_path)
|
|
93
|
+
net = self._read_network_config(pdo_config_path)
|
|
94
|
+
if adapter is None and net.get("adapter"):
|
|
95
|
+
adapter = net["adapter"]
|
|
96
|
+
if cycle_time_ms == 10 and net.get("cycle_ms"):
|
|
97
|
+
cycle_time_ms = net["cycle_ms"]
|
|
98
|
+
else:
|
|
99
|
+
self.pdo_config = None
|
|
100
|
+
|
|
88
101
|
self.adapter = adapter
|
|
89
102
|
self.cycle_time = cycle_time_ms / 1000.0
|
|
90
|
-
self.pdo_config = load_pdo_config(pdo_config_path) if pdo_config_path else None
|
|
91
103
|
|
|
92
104
|
self.master = None
|
|
93
105
|
self._slaves = []
|
|
@@ -126,6 +138,15 @@ class EtherCATBus:
|
|
|
126
138
|
except Exception:
|
|
127
139
|
pass
|
|
128
140
|
|
|
141
|
+
@staticmethod
|
|
142
|
+
def _read_network_config(pdo_config_path):
|
|
143
|
+
"""Read the 'network' section from an ethercat_config.json file."""
|
|
144
|
+
try:
|
|
145
|
+
raw = json.loads(Path(pdo_config_path).read_text(encoding="utf-8"))
|
|
146
|
+
return raw.get("network", {})
|
|
147
|
+
except Exception:
|
|
148
|
+
return {}
|
|
149
|
+
|
|
129
150
|
# ------------------------------------------------------------------
|
|
130
151
|
# Adapter discovery
|
|
131
152
|
# ------------------------------------------------------------------
|
|
@@ -171,7 +192,7 @@ class EtherCATBus:
|
|
|
171
192
|
|
|
172
193
|
Args:
|
|
173
194
|
adapter: Network-adapter name/UID string.
|
|
174
|
-
pdo_config_path: Optional path to
|
|
195
|
+
pdo_config_path: Optional path to an ``ethercat_config.json``
|
|
175
196
|
file. Per-slave PDO assignments are applied before
|
|
176
197
|
``config_map`` so that I/O sizes reflect the intended
|
|
177
198
|
mapping.
|
|
@@ -380,6 +401,12 @@ class EtherCATBus:
|
|
|
380
401
|
transition fails.
|
|
381
402
|
ConfigurationError: If PDO mapping fails.
|
|
382
403
|
"""
|
|
404
|
+
if os.name != "nt" and os.geteuid() != 0:
|
|
405
|
+
raise PermissionError(
|
|
406
|
+
"EtherCAT requires raw socket access. "
|
|
407
|
+
"Please run with sudo: sudo python your_script.py"
|
|
408
|
+
)
|
|
409
|
+
|
|
383
410
|
adapter = self._resolve_adapter(self.adapter)
|
|
384
411
|
print(f"[BUS] Connecting to: {adapter.name}")
|
|
385
412
|
|
|
@@ -36,7 +36,7 @@ class GenericSlave:
|
|
|
36
36
|
For devices with standard SII PDO mappings (e.g. Beckhoff terminals),
|
|
37
37
|
set ``use_default_pdo=True`` (the default) to skip custom PDO
|
|
38
38
|
configuration. For devices that need explicit PDO assignments from
|
|
39
|
-
``
|
|
39
|
+
``ethercat_config.json``, set ``use_default_pdo=False``.
|
|
40
40
|
|
|
41
41
|
Args:
|
|
42
42
|
slave_index: EtherCAT slave position on the bus.
|
|
@@ -13,7 +13,7 @@ Usage::
|
|
|
13
13
|
|
|
14
14
|
python -m ethercat_master.webserver
|
|
15
15
|
python -m ethercat_master.webserver --port 8080
|
|
16
|
-
python -m ethercat_master.webserver --pdo-config
|
|
16
|
+
python -m ethercat_master.webserver --pdo-config ethercat_config.json
|
|
17
17
|
|
|
18
18
|
Then open http://localhost:8080 in your browser.
|
|
19
19
|
"""
|
|
@@ -130,6 +130,8 @@ _SKIP_ADAPTERS = (
|
|
|
130
130
|
"wi-fi direct", "wan miniport", "hyper-v",
|
|
131
131
|
)
|
|
132
132
|
|
|
133
|
+
_SKIP_LINUX_IFACES = ("lo", "wlan", "wlp", "docker", "br-", "veth", "virbr")
|
|
134
|
+
|
|
133
135
|
bus_state: BusState = None # set in main()
|
|
134
136
|
|
|
135
137
|
_WEBGUI_DIR = Path(__file__).parent / "webgui"
|
|
@@ -163,6 +165,8 @@ class _Handler(BaseHTTPRequestHandler):
|
|
|
163
165
|
desc = a.desc.decode("utf-8", errors="replace") if isinstance(a.desc, bytes) else str(a.desc)
|
|
164
166
|
if any(s in desc.lower() for s in _SKIP_ADAPTERS):
|
|
165
167
|
continue
|
|
168
|
+
if any(name.startswith(p) for p in _SKIP_LINUX_IFACES):
|
|
169
|
+
continue
|
|
166
170
|
result.append({"name": name, "desc": desc})
|
|
167
171
|
self._send_json({
|
|
168
172
|
"adapters": result,
|
|
@@ -348,12 +352,19 @@ def main():
|
|
|
348
352
|
parser.add_argument("--adapter", type=str, default=None,
|
|
349
353
|
help="Adapter name/UID (e.g. \\Device\\NPF_{...})")
|
|
350
354
|
parser.add_argument("--pdo-config", type=str, default=None,
|
|
351
|
-
help="Path to
|
|
355
|
+
help="Path to ethercat_config.json")
|
|
352
356
|
args = parser.parse_args()
|
|
353
357
|
|
|
358
|
+
import os
|
|
359
|
+
if os.name != "nt" and os.geteuid() != 0:
|
|
360
|
+
print("\n Error: EtherCAT requires raw socket access.")
|
|
361
|
+
print(" Please run with sudo:\n")
|
|
362
|
+
print(" sudo ecmaster-web\n")
|
|
363
|
+
raise SystemExit(1)
|
|
364
|
+
|
|
354
365
|
pdo_path = args.pdo_config
|
|
355
366
|
if not pdo_path:
|
|
356
|
-
candidate = Path(__file__).parent / "
|
|
367
|
+
candidate = Path(__file__).parent / "ethercat_config.json"
|
|
357
368
|
if not candidate.exists():
|
|
358
369
|
candidate.write_text('{"network": {}, "default": {}, "slaves": {}}\n', encoding="utf-8")
|
|
359
370
|
pdo_path = str(candidate)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ethercat-master
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Generic EtherCAT master library built on PySOEM — bus management, PDO mapping, slave discovery
|
|
5
5
|
Author-email: Henschel Robotics GmbH <info@henschel-robotics.ch>
|
|
6
6
|
License: MIT
|
|
@@ -34,12 +34,14 @@ Generic EtherCAT master library built on [PySOEM](https://github.com/bnjmnp/pyso
|
|
|
34
34
|
|
|
35
35
|
Developed by [Henschel Robotics GmbH](https://henschel-robotics.ch).
|
|
36
36
|
|
|
37
|
+

|
|
38
|
+
|
|
37
39
|
## Features
|
|
38
40
|
|
|
39
41
|
- **Bus management** -- connect, configure, and run an EtherCAT bus with one or more slaves
|
|
40
42
|
- **Generic slave handle** -- read/write raw PDO bytes for any device (Beckhoff terminals, servos, I/O modules, ...)
|
|
41
43
|
- **PDO mapping** -- configure SyncManager assignments per slave via a JSON file or SDO writes
|
|
42
|
-
- **Bus discovery** -- scan the bus and
|
|
44
|
+
- **Bus discovery** -- scan the bus and detect any EtherCAT device (Beckhoff, Henschel, or any other vendor)
|
|
43
45
|
- **Auto-reconnect** -- background health monitoring with automatic recovery on cable disconnect
|
|
44
46
|
- **Web interface** -- built-in browser GUI for adapter selection, bus scanning, PDO configuration, and going OP
|
|
45
47
|
- **Extensible** -- subclass `GenericSlave` or implement the slave handle interface to build device-specific drivers (see [python-hdrive-etc](https://github.com/henschel-robotics/python-hdrive-etc))
|
|
@@ -70,14 +72,42 @@ sudo apt install libpcap-dev
|
|
|
70
72
|
sudo dnf install libpcap-devel
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
On Linux
|
|
75
|
+
On Linux, raw Ethernet access requires **root**. Either run with `sudo` or grant the capability once:
|
|
74
76
|
|
|
75
77
|
```bash
|
|
76
|
-
|
|
78
|
+
# Option A – run with sudo
|
|
79
|
+
sudo pip install ethercat-master --break-system-packages
|
|
80
|
+
sudo ecmaster-web
|
|
81
|
+
|
|
82
|
+
# Option B – grant raw socket capability (no sudo needed afterwards)
|
|
83
|
+
sudo setcap cap_net_raw=ep $(readlink -f $(which python3))
|
|
77
84
|
```
|
|
78
85
|
|
|
79
86
|
> Npcap is **not** needed on Linux -- `libpcap` provides the same functionality and is BSD-licensed.
|
|
80
87
|
|
|
88
|
+
### Raspberry Pi Quick-Start
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# 1. Install libpcap
|
|
92
|
+
sudo apt update
|
|
93
|
+
sudo apt install libpcap-dev
|
|
94
|
+
|
|
95
|
+
# 2. Install ethercat-master system-wide (so sudo can find it)
|
|
96
|
+
sudo pip install ethercat-master --break-system-packages
|
|
97
|
+
|
|
98
|
+
# 3. Add ~/.local/bin to PATH (if not already)
|
|
99
|
+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
|
|
100
|
+
source ~/.bashrc
|
|
101
|
+
|
|
102
|
+
# 4. Launch the web interface (requires root for raw Ethernet)
|
|
103
|
+
sudo ecmaster-web --adapter eth0
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Open `http://<pi-ip>:8080` from any device on your network.
|
|
107
|
+
|
|
108
|
+
> Connect the EtherCAT slave(s) directly to the Pi's Ethernet port (`eth0`).
|
|
109
|
+
> Use Wi-Fi or a second USB-Ethernet adapter for SSH / network access.
|
|
110
|
+
|
|
81
111
|
### Python
|
|
82
112
|
|
|
83
113
|
- **Python 3.8+**
|
|
@@ -143,7 +173,7 @@ for s in slaves:
|
|
|
143
173
|
|
|
144
174
|
## PDO Configuration
|
|
145
175
|
|
|
146
|
-
Create a `
|
|
176
|
+
Create a `ethercat_config.json` to control which PDOs are assigned per slave:
|
|
147
177
|
|
|
148
178
|
```json
|
|
149
179
|
{
|
|
@@ -164,27 +194,44 @@ Create a `pdo_mapping.json` to control which PDOs are assigned per slave:
|
|
|
164
194
|
Pass it when creating the bus:
|
|
165
195
|
|
|
166
196
|
```python
|
|
167
|
-
bus = EtherCATBus(adapter=..., cycle_time_ms=1, pdo_config_path="
|
|
197
|
+
bus = EtherCATBus(adapter=..., cycle_time_ms=1, pdo_config_path="ethercat_config.json")
|
|
168
198
|
```
|
|
169
199
|
|
|
170
200
|
Or use the web interface to scan the bus, select PDOs with checkboxes, and save.
|
|
171
201
|
|
|
202
|
+
> **Raspberry Pi / Linux:** When installed via pip, the default `ethercat_config.json` is inside the package directory (e.g. `/usr/local/lib/python3.13/dist-packages/ethercat_master/ethercat_config.json`). Copy it to your working directory for easy editing:
|
|
203
|
+
>
|
|
204
|
+
> ```bash
|
|
205
|
+
> cp $(python3 -c "import ethercat_master, os; print(os.path.join(os.path.dirname(ethercat_master.__file__), 'ethercat_config.json'))") .
|
|
206
|
+
> ```
|
|
207
|
+
|
|
172
208
|
## Web Interface
|
|
173
209
|
|
|
174
210
|
Start the built-in web server:
|
|
175
211
|
|
|
176
212
|
```bash
|
|
177
|
-
ecmaster-web
|
|
178
|
-
ecmaster-web --port 8080
|
|
179
|
-
ecmaster-web --pdo-config /path/to/
|
|
213
|
+
sudo ecmaster-web
|
|
214
|
+
sudo ecmaster-web --port 8080
|
|
215
|
+
sudo ecmaster-web --pdo-config /path/to/ethercat_config.json
|
|
180
216
|
```
|
|
181
217
|
|
|
182
|
-
Then open `http://localhost:8080` in your browser.
|
|
218
|
+
Then open `http://localhost:8080` in your browser.
|
|
219
|
+
|
|
220
|
+

|
|
221
|
+
|
|
222
|
+
The web GUI lets you:
|
|
183
223
|
|
|
184
224
|
- Select a network adapter
|
|
185
|
-
- Scan the bus and
|
|
225
|
+
- Scan the bus and discover **any EtherCAT device** — Beckhoff terminals, IO modules, servo drives, and more
|
|
186
226
|
- Configure PDO assignments per slave
|
|
187
227
|
- Set the cycle time and go to OP state
|
|
228
|
+
- Run network latency tests (SDO round-trip measurement with histogram)
|
|
229
|
+
|
|
230
|
+
| Mixed bus (Beckhoff + HDrive) | Network Latency Test |
|
|
231
|
+
|---|---|
|
|
232
|
+
|  |  |
|
|
233
|
+
|
|
234
|
+
> **Full guide:** [`docs/web-interface.md`](docs/web-interface.md)
|
|
188
235
|
|
|
189
236
|
## Project Structure
|
|
190
237
|
|
|
@@ -204,10 +251,41 @@ python-ethercat-master/
|
|
|
204
251
|
│ ├── connect.py # Minimal single-slave example
|
|
205
252
|
│ ├── beckhoff.py # Beckhoff EK1100 + terminals
|
|
206
253
|
│ └── mixed_bus.py # HDrive motor + Beckhoff terminals
|
|
207
|
-
├──
|
|
254
|
+
├── ethercat_config.json # Example PDO config
|
|
208
255
|
└── pyproject.toml
|
|
209
256
|
```
|
|
210
257
|
|
|
258
|
+
## Examples
|
|
259
|
+
|
|
260
|
+
The [`examples/`](examples/) folder contains ready-to-run scripts. The recommended workflow is:
|
|
261
|
+
|
|
262
|
+
1. **Configure the bus** using the web interface (`ecmaster-web`):
|
|
263
|
+
- Select your network adapter
|
|
264
|
+
- Click **Scan Bus** to discover all slaves
|
|
265
|
+
- Expand each slave and configure the PDO assignments
|
|
266
|
+
- Click **Save PDO Config** — this writes `ethercat_config.json` with the adapter, cycle time, and per-slave PDO mapping
|
|
267
|
+
|
|
268
|
+
2. **Copy `ethercat_config.json`** next to your script (or point to it with `pdo_config_path`)
|
|
269
|
+
|
|
270
|
+
3. **Run the example** — the bus uses the preconfigured adapter and PDO mapping from the file:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
sudo python3 examples/connect.py # Linux
|
|
274
|
+
python examples\connect.py # Windows
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### `connect.py` — Minimal single-slave example
|
|
278
|
+
|
|
279
|
+
Connects to one slave and continuously prints the raw input PDO bytes. Good for verifying that the bus works and PDOs are mapped correctly.
|
|
280
|
+
|
|
281
|
+
### `beckhoff.py` — Beckhoff coupler + terminals
|
|
282
|
+
|
|
283
|
+
Scans the bus, discovers all terminals behind an EK1100 coupler, and reads their inputs in a loop. Standard Beckhoff terminals use factory-default PDO mappings from the SII EEPROM, so no `ethercat_config.json` is needed.
|
|
284
|
+
|
|
285
|
+
### `mixed_bus.py` — HDrive motor + Beckhoff terminals
|
|
286
|
+
|
|
287
|
+
Demonstrates running an HDrive servo motor alongside Beckhoff I/O terminals on the same bus. Requires `pip install hdrive-etc`. The `HDriveETC` class is a slave handle that plugs into `EtherCATBus` just like `GenericSlave`, so you can combine any devices.
|
|
288
|
+
|
|
211
289
|
## API Overview
|
|
212
290
|
|
|
213
291
|
### `EtherCATBus`
|
|
@@ -2,10 +2,10 @@ README.md
|
|
|
2
2
|
pyproject.toml
|
|
3
3
|
ethercat_master/__init__.py
|
|
4
4
|
ethercat_master/bus.py
|
|
5
|
+
ethercat_master/ethercat_config.json
|
|
5
6
|
ethercat_master/exceptions.py
|
|
6
7
|
ethercat_master/network_test.py
|
|
7
8
|
ethercat_master/pdo.py
|
|
8
|
-
ethercat_master/pdo_mapping.json
|
|
9
9
|
ethercat_master/slave.py
|
|
10
10
|
ethercat_master/webserver.py
|
|
11
11
|
ethercat_master.egg-info/PKG-INFO
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ethercat-master"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "Generic EtherCAT master library built on PySOEM — bus management, PDO mapping, slave discovery"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "MIT"}
|
|
@@ -52,7 +52,7 @@ include = ["ethercat_master*"]
|
|
|
52
52
|
[tool.setuptools.package-data]
|
|
53
53
|
ethercat_master = [
|
|
54
54
|
"webgui/**/*",
|
|
55
|
-
"
|
|
55
|
+
"ethercat_config.json",
|
|
56
56
|
]
|
|
57
57
|
|
|
58
58
|
[tool.ruff]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ethercat_master-0.1.0 → ethercat_master-0.1.2}/ethercat_master.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|