ethercat-master 0.1.2__tar.gz → 0.1.4__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.
Files changed (21) hide show
  1. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/PKG-INFO +9 -1
  2. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/README.md +5 -0
  3. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/bus.py +15 -0
  4. ethercat_master-0.1.4/ethercat_master/ethercat_config.json +31 -0
  5. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/pdo.py +32 -16
  6. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/webgui/index.html +12 -14
  7. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/webserver.py +18 -1
  8. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master.egg-info/PKG-INFO +9 -1
  9. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/pyproject.toml +6 -1
  10. ethercat_master-0.1.2/ethercat_master/ethercat_config.json +0 -29
  11. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/__init__.py +0 -0
  12. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/exceptions.py +0 -0
  13. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/network_test.py +0 -0
  14. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/slave.py +0 -0
  15. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master/webgui/style.css +0 -0
  16. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master.egg-info/SOURCES.txt +0 -0
  17. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master.egg-info/dependency_links.txt +0 -0
  18. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master.egg-info/entry_points.txt +0 -0
  19. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master.egg-info/requires.txt +0 -0
  20. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/ethercat_master.egg-info/top_level.txt +0 -0
  21. {ethercat_master-0.1.2 → ethercat_master-0.1.4}/setup.cfg +0 -0
@@ -1,11 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ethercat-master
3
- Version: 0.1.2
3
+ Version: 0.1.4
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
+ Maintainer-email: Henschel Robotics GmbH <info@henschel-robotics.ch>
6
7
  License: MIT
7
8
  Project-URL: Homepage, https://henschel-robotics.ch
9
+ Project-URL: Documentation, https://henschel-robotics.ch
8
10
  Project-URL: Repository, https://github.com/henschel-robotics/python-ethercat-master
11
+ Project-URL: Issues, https://github.com/henschel-robotics/python-ethercat-master/issues
9
12
  Keywords: ethercat,pysoem,fieldbus,motion-control,industrial,automation
10
13
  Classifier: Development Status :: 3 - Alpha
11
14
  Classifier: Intended Audience :: Developers
@@ -249,6 +252,7 @@ python-ethercat-master/
249
252
  │ └── style.css # Stylesheet
250
253
  ├── examples/
251
254
  │ ├── connect.py # Minimal single-slave example
255
+ │ ├── discover_bus.py # List slaves on the bus (read-only scan)
252
256
  │ ├── beckhoff.py # Beckhoff EK1100 + terminals
253
257
  │ └── mixed_bus.py # HDrive motor + Beckhoff terminals
254
258
  ├── ethercat_config.json # Example PDO config
@@ -278,6 +282,10 @@ python examples\connect.py # Windows
278
282
 
279
283
  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
284
 
285
+ ### `discover_bus.py` — Bus scan only
286
+
287
+ Prints all slaves (index, name, vendor/product, state, I/O sizes) without going to OP. Uses `ethercat_config.json` for adapter and optional PDO mapping.
288
+
281
289
  ### `beckhoff.py` — Beckhoff coupler + terminals
282
290
 
283
291
  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.
@@ -219,6 +219,7 @@ python-ethercat-master/
219
219
  │ └── style.css # Stylesheet
220
220
  ├── examples/
221
221
  │ ├── connect.py # Minimal single-slave example
222
+ │ ├── discover_bus.py # List slaves on the bus (read-only scan)
222
223
  │ ├── beckhoff.py # Beckhoff EK1100 + terminals
223
224
  │ └── mixed_bus.py # HDrive motor + Beckhoff terminals
224
225
  ├── ethercat_config.json # Example PDO config
@@ -248,6 +249,10 @@ python examples\connect.py # Windows
248
249
 
249
250
  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
 
252
+ ### `discover_bus.py` — Bus scan only
253
+
254
+ Prints all slaves (index, name, vendor/product, state, I/O sizes) without going to OP. Uses `ethercat_config.json` for adapter and optional PDO mapping.
255
+
251
256
  ### `beckhoff.py` — Beckhoff coupler + terminals
252
257
 
253
258
  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.
@@ -244,6 +244,21 @@ class EtherCATBus:
244
244
  info["available_rx_pdo"] = avail_rx
245
245
  info["available_tx_pdo"] = avail_tx
246
246
 
247
+ has_io = info["input_bytes"] > 0 or info["output_bytes"] > 0
248
+ no_coe = not avail_rx and not avail_tx
249
+ if has_io and no_coe:
250
+ info["sii_only"] = True
251
+ if info["output_bytes"] > 0 and not avail_rx:
252
+ sii_rx = {"pdo_index": "0x1600",
253
+ "objects": [f"SII default ({info['output_bytes']}B)"]}
254
+ info["available_rx_pdo"] = [sii_rx]
255
+ info["rx_pdo"] = [sii_rx]
256
+ if info["input_bytes"] > 0 and not avail_tx:
257
+ sii_tx = {"pdo_index": "0x1A00",
258
+ "objects": [f"SII default ({info['input_bytes']}B)"]}
259
+ info["available_tx_pdo"] = [sii_tx]
260
+ info["tx_pdo"] = [sii_tx]
261
+
247
262
  slaves.append(info)
248
263
  finally:
249
264
  master.close()
@@ -0,0 +1,31 @@
1
+ {
2
+ "network": {
3
+ "adapter": "\\Device\\NPF_{BB3EC489-F999-4A9B-9345-B5254A25CCC2}",
4
+ "cycle_ms": 0.1
5
+ },
6
+ "default": {},
7
+ "slaves": {
8
+ "0": {
9
+ "rx_pdo": [],
10
+ "tx_pdo": []
11
+ },
12
+ "1": {
13
+ "rx_pdo": [],
14
+ "tx_pdo": [
15
+ "0x1A00"
16
+ ]
17
+ },
18
+ "2": {
19
+ "rx_pdo": [],
20
+ "tx_pdo": [
21
+ "0x1A00"
22
+ ]
23
+ },
24
+ "3": {
25
+ "rx_pdo": [
26
+ "0x1600"
27
+ ],
28
+ "tx_pdo": []
29
+ }
30
+ }
31
+ }
@@ -71,8 +71,9 @@ def load_pdo_config(path):
71
71
  def get_slave_pdo(pdo_config, slave_index, default_rx=None, default_tx=None):
72
72
  """Look up (rx_pdo, tx_pdo) lists for a slave index.
73
73
 
74
- Falls back to the ``"default"`` key, then to the provided defaults
75
- (or ``DEFAULT_RX_PDO`` / ``DEFAULT_TX_PDO``).
74
+ Falls back to the ``"default"`` key, then to the provided defaults.
75
+ If no defaults are given and no config entry exists, returns empty
76
+ lists so that ``configure_pdo_mapping`` skips unconfigured SMs.
76
77
 
77
78
  Returns:
78
79
  tuple[list[int], list[int]]: (rx_pdo, tx_pdo) index lists.
@@ -81,20 +82,23 @@ def get_slave_pdo(pdo_config, slave_index, default_rx=None, default_tx=None):
81
82
  entry = pdo_config.get(slave_index, pdo_config.get("default"))
82
83
  if entry:
83
84
  return entry["rx_pdo"], entry["tx_pdo"]
84
- return list(default_rx or DEFAULT_RX_PDO), list(default_tx or DEFAULT_TX_PDO)
85
+ return list(default_rx or []), list(default_tx or [])
85
86
 
86
87
 
87
88
  def configure_pdo_mapping(slave, rx_pdo=None, tx_pdo=None):
88
89
  """Write SDO objects to configure PDO mapping on *slave*.
89
90
 
90
91
  Writes the SyncManager 2 (0x1C12, RxPDO) and SyncManager 3
91
- (0x1C13, TxPDO) assignment lists.
92
+ (0x1C13, TxPDO) assignment lists. Silently skips a SyncManager
93
+ if the slave does not support it (e.g. input-only devices have no SM2).
92
94
 
93
95
  Args:
94
96
  slave: A pysoem slave object (in PRE-OP or higher).
95
97
  rx_pdo: List of RxPDO indices to assign to SM2 (master -> slave).
98
+ Pass an empty list to skip RxPDO configuration.
96
99
  Defaults to ``DEFAULT_RX_PDO``.
97
100
  tx_pdo: List of TxPDO indices to assign to SM3 (slave -> master).
101
+ Pass an empty list to skip TxPDO configuration.
98
102
  Defaults to ``DEFAULT_TX_PDO``.
99
103
  """
100
104
  if rx_pdo is None:
@@ -115,15 +119,27 @@ def configure_pdo_mapping(slave, rx_pdo=None, tx_pdo=None):
115
119
  f"0x{index:04X}:0x{subindex:02X} {label} — {exc}"
116
120
  ) from exc
117
121
 
118
- _sdo_write(0x1C12, 0x00, struct.pack("<B", 0), "clear SM2 RxPDO count")
119
- _sdo_write(0x1C13, 0x00, struct.pack("<B", 0), "clear SM3 TxPDO count")
120
-
121
- for i, pdo in enumerate(rx_pdo, start=1):
122
- _sdo_write(0x1C12, i, struct.pack("<H", pdo), f"RxPDO[{i}]=0x{pdo:04X}")
123
- _sdo_write(0x1C12, 0x00, struct.pack("<B", len(rx_pdo)),
124
- f"set SM2 RxPDO count={len(rx_pdo)}")
125
-
126
- for i, pdo in enumerate(tx_pdo, start=1):
127
- _sdo_write(0x1C13, i, struct.pack("<H", pdo), f"TxPDO[{i}]=0x{pdo:04X}")
128
- _sdo_write(0x1C13, 0x00, struct.pack("<B", len(tx_pdo)),
129
- f"set SM3 TxPDO count={len(tx_pdo)}")
122
+ def _try_sdo_write(index, subindex, data, label=""):
123
+ try:
124
+ slave.sdo_write(index, subindex, data)
125
+ return True
126
+ except Exception:
127
+ return False
128
+
129
+ if rx_pdo:
130
+ if _try_sdo_write(0x1C12, 0x00, struct.pack("<B", 0), "clear SM2 RxPDO count"):
131
+ for i, pdo in enumerate(rx_pdo, start=1):
132
+ _sdo_write(0x1C12, i, struct.pack("<H", pdo), f"RxPDO[{i}]=0x{pdo:04X}")
133
+ _sdo_write(0x1C12, 0x00, struct.pack("<B", len(rx_pdo)),
134
+ f"set SM2 RxPDO count={len(rx_pdo)}")
135
+ else:
136
+ print(f"[PDO] {name}: SM2 (RxPDO) not supported, skipping")
137
+
138
+ if tx_pdo:
139
+ if _try_sdo_write(0x1C13, 0x00, struct.pack("<B", 0), "clear SM3 TxPDO count"):
140
+ for i, pdo in enumerate(tx_pdo, start=1):
141
+ _sdo_write(0x1C13, i, struct.pack("<H", pdo), f"TxPDO[{i}]=0x{pdo:04X}")
142
+ _sdo_write(0x1C13, 0x00, struct.pack("<B", len(tx_pdo)),
143
+ f"set SM3 TxPDO count={len(tx_pdo)}")
144
+ else:
145
+ print(f"[PDO] {name}: SM3 (TxPDO) not supported, skipping")
@@ -249,32 +249,29 @@ function savePdoConfig() {
249
249
  fetch(host+"api/pdo_config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)})
250
250
  .then(function(r){return r.json();}).then(function(d){
251
251
  if (d.error) { if(statusEl) statusEl.innerHTML="<span style='color:var(--danger)'>"+d.error+"</span>"; return; }
252
- if (_busState === "OP") {
253
- if(statusEl) statusEl.innerHTML="<span style='color:var(--accent)'>Saved. Reconnecting...</span>";
254
- saveAndReconnect(statusEl);
255
- } else {
256
- if(statusEl) statusEl.innerHTML="<span style='color:var(--accent)'>Saved. Scanning &amp; going OP...</span>";
257
- saveAndReconnect(statusEl);
258
- }
252
+ var pathInfo = d.path ? "<br><span style='color:var(--text-dim);font-size:10px'>Saved to: " + d.path + "</span>" : "";
253
+ if(statusEl) statusEl.innerHTML="<span style='color:var(--accent)'>Saved. Connecting...</span>" + pathInfo;
254
+ saveAndReconnect(statusEl, pathInfo);
259
255
  }).catch(function(e){ if(statusEl) statusEl.innerHTML="<span style='color:var(--danger)'>"+e+"</span>"; });
260
256
  }
261
257
 
262
- function saveAndReconnect(statusEl) {
258
+ function saveAndReconnect(statusEl, pathInfo) {
259
+ pathInfo = pathInfo || "";
263
260
  var params = _selectedAdapter != null ? "?adapter="+encodeURIComponent(_selectedAdapter) : "";
264
261
  fetch(host+"api/disconnect").then(function(r){return r.json();})
265
262
  .then(function() {
266
263
  setBusState("IDLE", null, null);
267
- if(statusEl) statusEl.innerHTML="<span style='color:var(--accent)'>Scanning bus...</span>";
264
+ if(statusEl) statusEl.innerHTML="<span style='color:var(--accent)'>Scanning bus...</span>" + pathInfo;
268
265
  return fetch(host+"api/discover"+params);
269
266
  })
270
267
  .then(function(r){return r.json();})
271
268
  .then(function(data) {
272
- if (data.error) { if(statusEl) statusEl.innerHTML="<span style='color:var(--danger)'>Scan failed: "+data.error+"</span>"; return; }
273
- if(statusEl) statusEl.innerHTML="<span style='color:var(--accent)'>Going OP...</span>";
269
+ if (data.error) { if(statusEl) statusEl.innerHTML="<span style='color:var(--danger)'>Scan failed: "+data.error+"</span>" + pathInfo; return; }
270
+ if(statusEl) statusEl.innerHTML="<span style='color:var(--accent)'>Going OP...</span>" + pathInfo;
274
271
  doGoOp();
275
- if(statusEl) statusEl.innerHTML="<span style='color:var(--success)'>Done</span>";
272
+ if(statusEl) statusEl.innerHTML="<span style='color:var(--success)'>Done</span>" + pathInfo;
276
273
  })
277
- .catch(function(e){ if(statusEl) statusEl.innerHTML="<span style='color:var(--danger)'>Reconnect failed: "+e+"</span>"; });
274
+ .catch(function(e){ if(statusEl) statusEl.innerHTML="<span style='color:var(--danger)'>Reconnect failed: "+e+"</span>" + pathInfo; });
278
275
  }
279
276
 
280
277
  // ---------- Bus Discovery ----------
@@ -299,7 +296,8 @@ function scanBus() {
299
296
  var txCb = pdoCheckboxes(s.index, "tx", s.available_tx_pdo, s.tx_pdo);
300
297
  var pdoHtml = "";
301
298
  if (rxCb || txCb) {
302
- pdoHtml = "<details onclick='event.stopPropagation()' style='margin-top:8px'><summary style='font-size:11px;color:var(--text-dim)'>PDO Configuration</summary><div style='margin-top:6px'>"+rxCb+txCb+"</div></details>";
299
+ var siiNote = s.sii_only ? "<div style='font-size:10px;color:var(--text-dim);margin-bottom:4px'>This device uses fixed SII/EEPROM PDO mapping (no CoE). Configuration is read-only.</div>" : "";
300
+ pdoHtml = "<details onclick='event.stopPropagation()' style='margin-top:8px'><summary style='font-size:11px;color:var(--text-dim)'>PDO Configuration</summary><div style='margin-top:6px'>"+siiNote+rxCb+txCb+"</div></details>";
303
301
  }
304
302
  html += "<div class='net-disc-slave' style='padding:10px 14px;border-top:1px solid var(--border)'>" +
305
303
  "<div style='display:flex;align-items:center;gap:10px'>" +
@@ -100,17 +100,34 @@ class BusState:
100
100
  return 0
101
101
 
102
102
  def connect(self, adapter_name, cycle_time_ms):
103
+ from .slave import GenericSlave
104
+
103
105
  with self._lock:
104
106
  if self.bus and self.bus.master and self.bus.master.in_op:
105
107
  raise RuntimeError("Already in OP. Stop first.")
106
108
  self.last_error = ""
107
109
  self.adapter_name = adapter_name
108
110
  self.cycle_time_ms = cycle_time_ms
111
+
112
+ slaves_info = EtherCATBus.discover(
113
+ adapter=adapter_name,
114
+ pdo_config_path=self.pdo_config_path,
115
+ )
116
+
109
117
  self.bus = EtherCATBus(
110
118
  adapter=adapter_name,
111
119
  cycle_time_ms=cycle_time_ms,
112
120
  pdo_config_path=self.pdo_config_path,
113
121
  )
122
+
123
+ for s in slaves_info:
124
+ if s["input_bytes"] > 0 or s["output_bytes"] > 0:
125
+ has_custom_pdo = False
126
+ if self.bus.pdo_config and s["index"] in self.bus.pdo_config:
127
+ has_custom_pdo = True
128
+ handle = GenericSlave(s["index"], use_default_pdo=not has_custom_pdo)
129
+ self.bus.register_slave(handle)
130
+
114
131
  self.bus.open()
115
132
  _save_net_config(self.pdo_config_path, adapter_name, cycle_time_ms)
116
133
 
@@ -301,7 +318,7 @@ class _Handler(BaseHTTPRequestHandler):
301
318
  bus_state.cycle_time_ms = float(net.get("cycle_ms", bus_state.cycle_time_ms))
302
319
 
303
320
  p.write_text(json.dumps(existing, indent=2) + "\n", encoding="utf-8")
304
- self._send_json({"ok": True})
321
+ self._send_json({"ok": True, "path": str(p.resolve())})
305
322
  except Exception as exc:
306
323
  self._send_json({"error": str(exc)})
307
324
  return
@@ -1,11 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ethercat-master
3
- Version: 0.1.2
3
+ Version: 0.1.4
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
+ Maintainer-email: Henschel Robotics GmbH <info@henschel-robotics.ch>
6
7
  License: MIT
7
8
  Project-URL: Homepage, https://henschel-robotics.ch
9
+ Project-URL: Documentation, https://henschel-robotics.ch
8
10
  Project-URL: Repository, https://github.com/henschel-robotics/python-ethercat-master
11
+ Project-URL: Issues, https://github.com/henschel-robotics/python-ethercat-master/issues
9
12
  Keywords: ethercat,pysoem,fieldbus,motion-control,industrial,automation
10
13
  Classifier: Development Status :: 3 - Alpha
11
14
  Classifier: Intended Audience :: Developers
@@ -249,6 +252,7 @@ python-ethercat-master/
249
252
  │ └── style.css # Stylesheet
250
253
  ├── examples/
251
254
  │ ├── connect.py # Minimal single-slave example
255
+ │ ├── discover_bus.py # List slaves on the bus (read-only scan)
252
256
  │ ├── beckhoff.py # Beckhoff EK1100 + terminals
253
257
  │ └── mixed_bus.py # HDrive motor + Beckhoff terminals
254
258
  ├── ethercat_config.json # Example PDO config
@@ -278,6 +282,10 @@ python examples\connect.py # Windows
278
282
 
279
283
  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
284
 
285
+ ### `discover_bus.py` — Bus scan only
286
+
287
+ Prints all slaves (index, name, vendor/product, state, I/O sizes) without going to OP. Uses `ethercat_config.json` for adapter and optional PDO mapping.
288
+
281
289
  ### `beckhoff.py` — Beckhoff coupler + terminals
282
290
 
283
291
  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.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ethercat-master"
7
- version = "0.1.2"
7
+ version = "0.1.4"
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"}
@@ -12,6 +12,9 @@ requires-python = ">=3.8"
12
12
  authors = [
13
13
  {name = "Henschel Robotics GmbH", email = "info@henschel-robotics.ch"},
14
14
  ]
15
+ maintainers = [
16
+ {name = "Henschel Robotics GmbH", email = "info@henschel-robotics.ch"},
17
+ ]
15
18
  keywords = ["ethercat", "pysoem", "fieldbus", "motion-control", "industrial", "automation"]
16
19
  classifiers = [
17
20
  "Development Status :: 3 - Alpha",
@@ -38,7 +41,9 @@ ecmaster-web = "ethercat_master.webserver:main"
38
41
 
39
42
  [project.urls]
40
43
  Homepage = "https://henschel-robotics.ch"
44
+ Documentation = "https://henschel-robotics.ch"
41
45
  Repository = "https://github.com/henschel-robotics/python-ethercat-master"
46
+ Issues = "https://github.com/henschel-robotics/python-ethercat-master/issues"
42
47
 
43
48
  [project.optional-dependencies]
44
49
  dev = [
@@ -1,29 +0,0 @@
1
- {
2
- "network": {
3
- "adapter": "\\Device\\NPF_{4599DDA5-3F5D-466B-BC6A-BBD358731532}",
4
- "cycle_ms": 0.1
5
- },
6
- "default": {},
7
- "slaves": {
8
- "0": {
9
- "rx_pdo": [
10
- "0x1600",
11
- "0x1605"
12
- ],
13
- "tx_pdo": [
14
- "0x1A00",
15
- "0x1A05"
16
- ]
17
- },
18
- "1": {
19
- "rx_pdo": [
20
- "0x1600",
21
- "0x1605"
22
- ],
23
- "tx_pdo": [
24
- "0x1A00",
25
- "0x1A05"
26
- ]
27
- }
28
- }
29
- }