easye4-python 1.0.1__tar.gz → 1.0.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.
Files changed (28) hide show
  1. easye4_python-1.0.2/PKG-INFO +311 -0
  2. easye4_python-1.0.2/README.md +293 -0
  3. {easye4_python-1.0.1 → easye4_python-1.0.2}/easye4/client.py +8 -1
  4. easye4_python-1.0.2/easye4_python.egg-info/PKG-INFO +311 -0
  5. {easye4_python-1.0.1 → easye4_python-1.0.2}/pyproject.toml +1 -1
  6. easye4_python-1.0.1/PKG-INFO +0 -251
  7. easye4_python-1.0.1/README.md +0 -233
  8. easye4_python-1.0.1/easye4_python.egg-info/PKG-INFO +0 -251
  9. {easye4_python-1.0.1 → easye4_python-1.0.2}/LICENSE +0 -0
  10. {easye4_python-1.0.1 → easye4_python-1.0.2}/easye4/__init__.py +0 -0
  11. {easye4_python-1.0.1 → easye4_python-1.0.2}/easye4/api.py +0 -0
  12. {easye4_python-1.0.1 → easye4_python-1.0.2}/easye4/certificates/easyRootCertV1.crt +0 -0
  13. {easye4_python-1.0.1 → easye4_python-1.0.2}/easye4_python.egg-info/SOURCES.txt +0 -0
  14. {easye4_python-1.0.1 → easye4_python-1.0.2}/easye4_python.egg-info/dependency_links.txt +0 -0
  15. {easye4_python-1.0.1 → easye4_python-1.0.2}/easye4_python.egg-info/requires.txt +0 -0
  16. {easye4_python-1.0.1 → easye4_python-1.0.2}/easye4_python.egg-info/top_level.txt +0 -0
  17. {easye4_python-1.0.1 → easye4_python-1.0.2}/setup.cfg +0 -0
  18. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_analog_inputs.py +0 -0
  19. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_analog_outputs.py +0 -0
  20. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_combined_io.py +0 -0
  21. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_digital_inputs.py +0 -0
  22. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_digital_outputs.py +0 -0
  23. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_live_session.py +0 -0
  24. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_memory.py +0 -0
  25. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_public_client.py +0 -0
  26. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_session.py +0 -0
  27. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_snapshot.py +0 -0
  28. {easye4_python-1.0.1 → easye4_python-1.0.2}/tests/test_writing.py +0 -0
@@ -0,0 +1,311 @@
1
+ Metadata-Version: 2.4
2
+ Name: easye4-python
3
+ Version: 1.0.2
4
+ Summary: Python interface for the Eaton easyE4 JSON API
5
+ Author: Dennis Ulijn
6
+ License-Expression: MIT
7
+ Keywords: Eaton,easyE4,PLC,industrial automation,JSON API,Python
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: System :: Hardware
11
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests>=2.31
16
+ Requires-Dist: python-dotenv>=1.0
17
+ Dynamic: license-file
18
+
19
+ # easyE4 Python Library
20
+
21
+ A reusable, independently developed Python interface for the Eaton easyE4 JSON API. It provides device information, digital and analog I/O reads, marker-memory access, and controlled marker writes without application-specific scaling or operand mappings. **This is not an official Eaton SDK.**
22
+
23
+ **Current published version:** `1.0.1` on PyPI. **Next maintenance version:** `1.0.2` (in preparation; not yet published). Tested with an easyE4 running firmware 2.46, build 3603. The changes under preparation correct `.env` discovery and bundled-certificate selection for use from another project.
24
+
25
+ ## Requirements
26
+
27
+ - Python 3.10 or newer (the library has been tested with Python 3.13).
28
+ - Network access to an easyE4 with its webserver and JSON API enabled.
29
+ - Appropriate easySoft webserver settings and user permissions.
30
+ - `requests` and `python-dotenv` (installed automatically).
31
+
32
+ For I/O reading, enable **Read I/Os**. For marker writes, enable **marker write**, configure the allowed write range, and use a read/write account. Transfer configuration changes to the device. Only enable writes to addresses that are safe for the installation.
33
+
34
+ ## Installation
35
+
36
+ ### From PyPI
37
+
38
+ ```powershell
39
+ python -m pip install easye4-python
40
+ ```
41
+
42
+ To pin the currently published release:
43
+
44
+ ```powershell
45
+ python -m pip install easye4-python==1.0.1
46
+ ```
47
+
48
+ > The `.env` default-path fix is being prepared for 1.0.2. On 1.0.1, pass the path to your project's `.env` explicitly, as shown below.
49
+
50
+ ### From source (development)
51
+
52
+ Run in the folder containing `pyproject.toml`:
53
+
54
+ ```powershell
55
+ python -m venv .venv
56
+ .\.venv\Scripts\Activate.ps1
57
+ python -m pip install -e .
58
+ ```
59
+
60
+ For a non-editable local installation:
61
+
62
+ ```powershell
63
+ python -m pip install .
64
+ ```
65
+
66
+ ## Configuration
67
+
68
+ Create `.env` alongside your application script:
69
+
70
+ ```dotenv
71
+ EASYE4_IP=192.168.1.100
72
+ EASYE4_PORT=443
73
+ EASYE4_PROTOCOL=https
74
+ EASYE4_TIMEOUT=5
75
+
76
+ EASYE4_AUTH_METHOD=basic
77
+ EASYE4_USERNAME=
78
+ EASYE4_PASSWORD=
79
+ EASYE4_API_KEY=
80
+
81
+ # Leave blank to use the Eaton root certificate bundled with the package.
82
+ EASYE4_CA_FILE=
83
+
84
+ # Enable only when the connected device requires the tested compatibility workaround.
85
+ EASYE4_TLS_COMPATIBILITY=false
86
+ ```
87
+
88
+ Authentication modes are `none`, `basic`, and `bearer`. Never commit `.env`, passwords, API tokens, or private keys.
89
+
90
+ **Certificate selection:** When `EASYE4_CA_FILE` is blank, the library uses its bundled `easye4/certificates/easyRootCertV1.crt` if present. When a custom path is supplied, relative paths are resolved against the `.env` file's directory. An explicit path takes precedence over the bundled certificate. The bundled root certificate is public trust material, not a client secret.
91
+
92
+ **`.env` discovery by version:**
93
+
94
+ - **Published 1.0.1:** Explicitly pass `env_file` for applications outside the library's source project. Otherwise it can look in the wrong directory.
95
+ - **1.0.2 in preparation:** When `env_file` is omitted, `from_env()` uses `Path.cwd() / ".env"`; an explicit path remains the most reliable choice when an IDE sets a different working directory. The code raises `FileNotFoundError` if that configuration file is missing.
96
+
97
+ ## Quick start
98
+
99
+ ```python
100
+ from pathlib import Path
101
+ from easye4 import EasyE4
102
+
103
+ env_file = Path(__file__).resolve().parent / ".env"
104
+
105
+ with EasyE4.from_env(env_file=env_file) as easy:
106
+ print("Connection:", easy.connect())
107
+ print("State:", easy.get_state())
108
+ print("M1:", easy.read_marker(1))
109
+ print("MW1:", easy.read_word(1))
110
+ ```
111
+
112
+ In the upcoming 1.0.2, `EasyE4.from_env()` without arguments also works when the working directory contains `.env`. The context manager closes the HTTP session automatically. `connect()` tests the firmware endpoint; it does not start or stop the PLC program.
113
+
114
+ ## TLS security
115
+
116
+ Normal certificate verification is preferred. On the tested device, Python 3.13 reported `Missing Authority Key Identifier`. Setting `EASYE4_TLS_COMPATIBILITY=true` disables OpenSSL's extra `VERIFY_X509_STRICT` profile checks while retaining the intended CA-chain and hostname verification. This is a **compatibility exception**, not equivalent to fully compliant TLS. Review device identity, certificate trust, and security requirements before production deployment. Do not use `verify=False` as a routine workaround.
117
+
118
+ Bundling the Eaton root certificate does **not** remove the need for compatibility mode on the affected device. Keep compatibility mode disabled unless required and validated. Public redistribution of the certificate is subject to the applicable rights and terms.
119
+
120
+ ## Public API
121
+
122
+ ### Connection and system information
123
+
124
+ | Method | Purpose |
125
+ |---|---|
126
+ | `connect()` | Verify communication/authentication and return connection details |
127
+ | `disconnect()` | Close HTTP session |
128
+ | `is_connected()` | Check whether the device responds now |
129
+ | `get_firmware()` | Return firmware version and build |
130
+ | `get_state()` | Return RUN/STOP |
131
+ | `get_device_name()` | Read device name |
132
+ | `get_program_name()` | Read program name |
133
+
134
+ ### Read I/O
135
+
136
+ | Method | Result |
137
+ |---|---|
138
+ | `read_digital_input(index)` / `read_digital_inputs(indices)` | `I` bit(s), 0/1 |
139
+ | `read_digital_output(index)` / `read_digital_outputs(indices)` | `O` bit(s), 0/1 |
140
+ | `read_analog_input(index)` / `read_analog_inputs(indices)` | Raw signed 32-bit `AI` values |
141
+ | `read_analog_output(index)` / `read_analog_outputs(indices)` | Raw signed 32-bit `AO` values |
142
+ | `read_io(digital_inputs=..., digital_outputs=..., analog_inputs=..., analog_outputs=...)` | Combined I/O dictionary |
143
+
144
+ ### Marker memory
145
+
146
+ | Method | Purpose |
147
+ |---|---|
148
+ | `read_marker(index)` / `read_markers(indices)` | Read M bit(s) |
149
+ | `read_word(index)` | Read unsigned 16-bit MW |
150
+ | `read_dword(index)` | Read unsigned 32-bit MD |
151
+ | `read_memory(markers=..., words=..., dwords=...)` | Read selected M/MW/MD from one `MALL` response |
152
+ | `write_marker(index, value)` | Write 0 or 1 to an allowed M address |
153
+ | `write_word(index, value)` | Write 0..65535 to an allowed MW address |
154
+ | `read_snapshot(...)` | Combine I/O and marker-memory reads |
155
+
156
+ `read_snapshot()` accepts the four `read_io()` lists plus `markers`, `words`, and `dwords`. It makes up to **five sequential HTTP requests**, not an atomic PLC snapshot. A requested marker-memory group uses one request regardless of the number of selected M/MW/MD values.
157
+
158
+ ```python
159
+ from pathlib import Path
160
+ from easye4 import EasyE4
161
+
162
+ with EasyE4.from_env(Path(__file__).resolve().parent / ".env") as easy:
163
+ easy.connect()
164
+ snapshot = easy.read_snapshot(
165
+ digital_inputs=[1, 2],
166
+ digital_outputs=[1, 2],
167
+ analog_inputs=[1, 2],
168
+ analog_outputs=[1],
169
+ markers=[1, 2],
170
+ words=[1, 2],
171
+ dwords=[1],
172
+ )
173
+ print(snapshot)
174
+ ```
175
+
176
+ **Raw data:** The library applies no engineering units or scale factors. Interpret values according to the connected easySoft program. `M`, `MB`, `MW`, and `MD` overlap in the same memory: `MW1` contains bits `M1` through `M16`, and `MD1` covers `MW1` and `MW2`. Do not assign unrelated variables to overlapping addresses.
177
+
178
+ ## Writing safely
179
+
180
+ Writing requires explicit PLC permissions and an approved, noncritical operand. Even a short write can change machine behavior; restoring a value does not undo physical consequences. The interactive `09_write_markers.py` example asks for confirmation, verifies readback, and attempts restoration. Restoration cannot be guaranteed after network, power, or process failure.
181
+
182
+ ```python
183
+ from pathlib import Path
184
+ from easye4 import EasyE4
185
+
186
+ # Read-only inspection before considering a write.
187
+ with EasyE4.from_env(Path(__file__).resolve().parent / ".env") as easy:
188
+ easy.connect()
189
+ original = easy.read_marker(1)
190
+ print("M1:", original)
191
+ # Only call easy.write_marker(...) for an approved, safe address.
192
+ ```
193
+
194
+ ## Examples
195
+
196
+ Run from the source project's root, for example `python examples/01_connection.py`.
197
+
198
+ | File | Demonstrates | Writes to PLC? |
199
+ |---|---|---|
200
+ | `01_connection.py` | Connect and close | No |
201
+ | `02_system_info.py` | Firmware, state, names | No |
202
+ | `03_digital_inputs.py` | `IALL` diagnostic read | No |
203
+ | `04_digital_outputs.py` | `OALL` diagnostic read | No |
204
+ | `05_analog_inputs.py` | `AIALL` raw values | No |
205
+ | `06_analog_outputs.py` | `AOALL` raw values | No |
206
+ | `07_read_markers.py` | Single and multiple M reads | No |
207
+ | `08_read_words.py` | MW/MD, signed conversion and overlap | No |
208
+ | `09_write_markers.py` | Interactive M/MW write and restore | **Yes, after confirmation** |
209
+ | `10_combined_read.py` | `read_snapshot()` | No |
210
+ | `11_live_monitor.py` | Polling and change detection; Ctrl+C to stop | No |
211
+ | `12_error_handling.py` | Error scenarios, mostly mocks | No |
212
+
213
+ **Packaging note:** The published wheel installs the library, not necessarily the `examples/` or `tests/` directories. Obtain examples from the source repository or source distribution as appropriate. Some diagnostic examples intentionally use the internal `easy.api._get_json()` interface; application code should prefer public `EasyE4` methods.
214
+
215
+ ## Verified device response formats
216
+
217
+ | Request `GET /api/get/data?elm=...` | Response key | Decoded length |
218
+ |---|---|---:|
219
+ | `I` | `IALL` | 16 bytes |
220
+ | `O` | `OALL` | 16 bytes |
221
+ | `AI` | `AIALL` | 2048 bytes |
222
+ | `AO` | `AOALL` | 512 bytes |
223
+ | `M` | `MALL` | 128 bytes |
224
+
225
+ The physical device confirmed these response keys and sizes. The library decodes digital blocks least-significant bit first and analog blocks as signed little-endian 32-bit integers. **Not every physical channel-to-bit/index mapping has been independently verified.** Check against known hardware states before relying on mappings in production.
226
+
227
+ For writes, the tested endpoint is `GET /api/set/op?op=M&index=...&val=...` or `op=MW`; successful writes returned **HTTP 204 No Content**. Always verify by reading back when appropriate.
228
+
229
+ ## Error handling
230
+
231
+ The current release uses built-in exceptions, not dedicated library exception classes:
232
+
233
+ - `ConnectionError`: connection, timeout, TLS, or read authentication failures; inspect the message.
234
+ - `PermissionError`: rejected write authorization (401/403).
235
+ - `ValueError`: invalid index/value, malformed response, or rejected write request (400).
236
+ - `OSError`: local file/system problems. `FileNotFoundError` is also an `OSError`.
237
+
238
+ ```python
239
+ from pathlib import Path
240
+ from easye4 import EasyE4
241
+
242
+ try:
243
+ with EasyE4.from_env(Path(__file__).resolve().parent / ".env") as easy:
244
+ easy.connect()
245
+ print(easy.read_marker(1))
246
+ except (ConnectionError, PermissionError, ValueError, OSError) as error:
247
+ print("easyE4 operation failed:", error)
248
+ ```
249
+
250
+ ## Troubleshooting
251
+
252
+ | Symptom | Check |
253
+ |---|---|
254
+ | `EASYE4_IP is not configured` | `.env` location; on 1.0.1 pass `env_file` explicitly |
255
+ | Configuration file not found | Check the current working directory or explicit path (1.0.2 behavior) |
256
+ | Certificate file not found | Leave `EASYE4_CA_FILE=` blank to use the bundled certificate, or provide a valid custom path |
257
+ | `Missing Authority Key Identifier` | Review CA/certificate; compatibility mode only for the verified device case |
258
+ | Connection refused / timeout | IP, port, network, webserver enabled |
259
+ | HTTP 401 | Credentials and user rights; check read vs write permission |
260
+ | HTTP 400 or device `ERROR` | Operand category, index, write range, and device documentation |
261
+ | No I/O data | Enable **Read I/Os** in easySoft and transfer configuration |
262
+ | Write rejected | Enable **marker write**, permitted range, read/write account |
263
+ | Unexpected M/MW/MD values | Check shared-memory overlap and PLC program writes |
264
+ | Zero values | May be valid; confirm PLC program and physical I/O states |
265
+
266
+ ## Tests and validation
267
+
268
+ The `tests/` directory includes mock-based tests for parsing, validation, sessions, reading, writing, and snapshots. Run the offline regression suite after changing transport, TLS, or decoders:
269
+
270
+ ```powershell
271
+ python tests/run_regression.py
272
+ ```
273
+
274
+ The examples and public library have also been exercised against a physical easyE4 on firmware 2.46, build 3603. Mock tests do not prove every hardware address mapping or production security behavior. The package was installed successfully from a wheel in a clean environment; a second-computer test revealed the `.env` path issue addressed in the upcoming 1.0.2.
275
+
276
+ ## Known limitations and next improvements
277
+
278
+ - I/O index-to-physical-channel mappings need controlled hardware validation.
279
+ - TLS compatibility exception needs production security review and ideally compliant device certificates.
280
+ - `read_snapshot()` is sequential, not atomic.
281
+ - No dedicated exception hierarchy yet.
282
+ - No generic MD write method or asynchronous polling API in this version.
283
+ - The examples and API are not certified for safety-critical or unattended control.
284
+
285
+ ## Project structure
286
+
287
+ ```text
288
+ easye4-python/
289
+ ├── easye4/
290
+ │ ├── __init__.py
291
+ │ ├── api.py
292
+ │ ├── client.py
293
+ │ └── certificates/
294
+ │ └── easyRootCertV1.crt
295
+ ├── examples/
296
+ │ ├── 01_connection.py
297
+ │ └── ... 12_error_handling.py
298
+ ├── tests/
299
+ │ └── ...
300
+ ├── .env.example
301
+ ├── .gitignore
302
+ ├── LICENSE
303
+ ├── pyproject.toml
304
+ └── README.md
305
+ ```
306
+
307
+ Keep the library generic. Place process-specific operand mappings, scaling, alarm logic, and logging in the consuming application.
308
+
309
+ ## License and attribution
310
+
311
+ The Python library is distributed under the MIT license, subject to the rights held by its publisher. The bundled Eaton root certificate is third-party material and is **not automatically covered by the library's MIT license**. Eaton and easyE4 are trademarks of their respective owner.
@@ -0,0 +1,293 @@
1
+ # easyE4 Python Library
2
+
3
+ A reusable, independently developed Python interface for the Eaton easyE4 JSON API. It provides device information, digital and analog I/O reads, marker-memory access, and controlled marker writes without application-specific scaling or operand mappings. **This is not an official Eaton SDK.**
4
+
5
+ **Current published version:** `1.0.1` on PyPI. **Next maintenance version:** `1.0.2` (in preparation; not yet published). Tested with an easyE4 running firmware 2.46, build 3603. The changes under preparation correct `.env` discovery and bundled-certificate selection for use from another project.
6
+
7
+ ## Requirements
8
+
9
+ - Python 3.10 or newer (the library has been tested with Python 3.13).
10
+ - Network access to an easyE4 with its webserver and JSON API enabled.
11
+ - Appropriate easySoft webserver settings and user permissions.
12
+ - `requests` and `python-dotenv` (installed automatically).
13
+
14
+ For I/O reading, enable **Read I/Os**. For marker writes, enable **marker write**, configure the allowed write range, and use a read/write account. Transfer configuration changes to the device. Only enable writes to addresses that are safe for the installation.
15
+
16
+ ## Installation
17
+
18
+ ### From PyPI
19
+
20
+ ```powershell
21
+ python -m pip install easye4-python
22
+ ```
23
+
24
+ To pin the currently published release:
25
+
26
+ ```powershell
27
+ python -m pip install easye4-python==1.0.1
28
+ ```
29
+
30
+ > The `.env` default-path fix is being prepared for 1.0.2. On 1.0.1, pass the path to your project's `.env` explicitly, as shown below.
31
+
32
+ ### From source (development)
33
+
34
+ Run in the folder containing `pyproject.toml`:
35
+
36
+ ```powershell
37
+ python -m venv .venv
38
+ .\.venv\Scripts\Activate.ps1
39
+ python -m pip install -e .
40
+ ```
41
+
42
+ For a non-editable local installation:
43
+
44
+ ```powershell
45
+ python -m pip install .
46
+ ```
47
+
48
+ ## Configuration
49
+
50
+ Create `.env` alongside your application script:
51
+
52
+ ```dotenv
53
+ EASYE4_IP=192.168.1.100
54
+ EASYE4_PORT=443
55
+ EASYE4_PROTOCOL=https
56
+ EASYE4_TIMEOUT=5
57
+
58
+ EASYE4_AUTH_METHOD=basic
59
+ EASYE4_USERNAME=
60
+ EASYE4_PASSWORD=
61
+ EASYE4_API_KEY=
62
+
63
+ # Leave blank to use the Eaton root certificate bundled with the package.
64
+ EASYE4_CA_FILE=
65
+
66
+ # Enable only when the connected device requires the tested compatibility workaround.
67
+ EASYE4_TLS_COMPATIBILITY=false
68
+ ```
69
+
70
+ Authentication modes are `none`, `basic`, and `bearer`. Never commit `.env`, passwords, API tokens, or private keys.
71
+
72
+ **Certificate selection:** When `EASYE4_CA_FILE` is blank, the library uses its bundled `easye4/certificates/easyRootCertV1.crt` if present. When a custom path is supplied, relative paths are resolved against the `.env` file's directory. An explicit path takes precedence over the bundled certificate. The bundled root certificate is public trust material, not a client secret.
73
+
74
+ **`.env` discovery by version:**
75
+
76
+ - **Published 1.0.1:** Explicitly pass `env_file` for applications outside the library's source project. Otherwise it can look in the wrong directory.
77
+ - **1.0.2 in preparation:** When `env_file` is omitted, `from_env()` uses `Path.cwd() / ".env"`; an explicit path remains the most reliable choice when an IDE sets a different working directory. The code raises `FileNotFoundError` if that configuration file is missing.
78
+
79
+ ## Quick start
80
+
81
+ ```python
82
+ from pathlib import Path
83
+ from easye4 import EasyE4
84
+
85
+ env_file = Path(__file__).resolve().parent / ".env"
86
+
87
+ with EasyE4.from_env(env_file=env_file) as easy:
88
+ print("Connection:", easy.connect())
89
+ print("State:", easy.get_state())
90
+ print("M1:", easy.read_marker(1))
91
+ print("MW1:", easy.read_word(1))
92
+ ```
93
+
94
+ In the upcoming 1.0.2, `EasyE4.from_env()` without arguments also works when the working directory contains `.env`. The context manager closes the HTTP session automatically. `connect()` tests the firmware endpoint; it does not start or stop the PLC program.
95
+
96
+ ## TLS security
97
+
98
+ Normal certificate verification is preferred. On the tested device, Python 3.13 reported `Missing Authority Key Identifier`. Setting `EASYE4_TLS_COMPATIBILITY=true` disables OpenSSL's extra `VERIFY_X509_STRICT` profile checks while retaining the intended CA-chain and hostname verification. This is a **compatibility exception**, not equivalent to fully compliant TLS. Review device identity, certificate trust, and security requirements before production deployment. Do not use `verify=False` as a routine workaround.
99
+
100
+ Bundling the Eaton root certificate does **not** remove the need for compatibility mode on the affected device. Keep compatibility mode disabled unless required and validated. Public redistribution of the certificate is subject to the applicable rights and terms.
101
+
102
+ ## Public API
103
+
104
+ ### Connection and system information
105
+
106
+ | Method | Purpose |
107
+ |---|---|
108
+ | `connect()` | Verify communication/authentication and return connection details |
109
+ | `disconnect()` | Close HTTP session |
110
+ | `is_connected()` | Check whether the device responds now |
111
+ | `get_firmware()` | Return firmware version and build |
112
+ | `get_state()` | Return RUN/STOP |
113
+ | `get_device_name()` | Read device name |
114
+ | `get_program_name()` | Read program name |
115
+
116
+ ### Read I/O
117
+
118
+ | Method | Result |
119
+ |---|---|
120
+ | `read_digital_input(index)` / `read_digital_inputs(indices)` | `I` bit(s), 0/1 |
121
+ | `read_digital_output(index)` / `read_digital_outputs(indices)` | `O` bit(s), 0/1 |
122
+ | `read_analog_input(index)` / `read_analog_inputs(indices)` | Raw signed 32-bit `AI` values |
123
+ | `read_analog_output(index)` / `read_analog_outputs(indices)` | Raw signed 32-bit `AO` values |
124
+ | `read_io(digital_inputs=..., digital_outputs=..., analog_inputs=..., analog_outputs=...)` | Combined I/O dictionary |
125
+
126
+ ### Marker memory
127
+
128
+ | Method | Purpose |
129
+ |---|---|
130
+ | `read_marker(index)` / `read_markers(indices)` | Read M bit(s) |
131
+ | `read_word(index)` | Read unsigned 16-bit MW |
132
+ | `read_dword(index)` | Read unsigned 32-bit MD |
133
+ | `read_memory(markers=..., words=..., dwords=...)` | Read selected M/MW/MD from one `MALL` response |
134
+ | `write_marker(index, value)` | Write 0 or 1 to an allowed M address |
135
+ | `write_word(index, value)` | Write 0..65535 to an allowed MW address |
136
+ | `read_snapshot(...)` | Combine I/O and marker-memory reads |
137
+
138
+ `read_snapshot()` accepts the four `read_io()` lists plus `markers`, `words`, and `dwords`. It makes up to **five sequential HTTP requests**, not an atomic PLC snapshot. A requested marker-memory group uses one request regardless of the number of selected M/MW/MD values.
139
+
140
+ ```python
141
+ from pathlib import Path
142
+ from easye4 import EasyE4
143
+
144
+ with EasyE4.from_env(Path(__file__).resolve().parent / ".env") as easy:
145
+ easy.connect()
146
+ snapshot = easy.read_snapshot(
147
+ digital_inputs=[1, 2],
148
+ digital_outputs=[1, 2],
149
+ analog_inputs=[1, 2],
150
+ analog_outputs=[1],
151
+ markers=[1, 2],
152
+ words=[1, 2],
153
+ dwords=[1],
154
+ )
155
+ print(snapshot)
156
+ ```
157
+
158
+ **Raw data:** The library applies no engineering units or scale factors. Interpret values according to the connected easySoft program. `M`, `MB`, `MW`, and `MD` overlap in the same memory: `MW1` contains bits `M1` through `M16`, and `MD1` covers `MW1` and `MW2`. Do not assign unrelated variables to overlapping addresses.
159
+
160
+ ## Writing safely
161
+
162
+ Writing requires explicit PLC permissions and an approved, noncritical operand. Even a short write can change machine behavior; restoring a value does not undo physical consequences. The interactive `09_write_markers.py` example asks for confirmation, verifies readback, and attempts restoration. Restoration cannot be guaranteed after network, power, or process failure.
163
+
164
+ ```python
165
+ from pathlib import Path
166
+ from easye4 import EasyE4
167
+
168
+ # Read-only inspection before considering a write.
169
+ with EasyE4.from_env(Path(__file__).resolve().parent / ".env") as easy:
170
+ easy.connect()
171
+ original = easy.read_marker(1)
172
+ print("M1:", original)
173
+ # Only call easy.write_marker(...) for an approved, safe address.
174
+ ```
175
+
176
+ ## Examples
177
+
178
+ Run from the source project's root, for example `python examples/01_connection.py`.
179
+
180
+ | File | Demonstrates | Writes to PLC? |
181
+ |---|---|---|
182
+ | `01_connection.py` | Connect and close | No |
183
+ | `02_system_info.py` | Firmware, state, names | No |
184
+ | `03_digital_inputs.py` | `IALL` diagnostic read | No |
185
+ | `04_digital_outputs.py` | `OALL` diagnostic read | No |
186
+ | `05_analog_inputs.py` | `AIALL` raw values | No |
187
+ | `06_analog_outputs.py` | `AOALL` raw values | No |
188
+ | `07_read_markers.py` | Single and multiple M reads | No |
189
+ | `08_read_words.py` | MW/MD, signed conversion and overlap | No |
190
+ | `09_write_markers.py` | Interactive M/MW write and restore | **Yes, after confirmation** |
191
+ | `10_combined_read.py` | `read_snapshot()` | No |
192
+ | `11_live_monitor.py` | Polling and change detection; Ctrl+C to stop | No |
193
+ | `12_error_handling.py` | Error scenarios, mostly mocks | No |
194
+
195
+ **Packaging note:** The published wheel installs the library, not necessarily the `examples/` or `tests/` directories. Obtain examples from the source repository or source distribution as appropriate. Some diagnostic examples intentionally use the internal `easy.api._get_json()` interface; application code should prefer public `EasyE4` methods.
196
+
197
+ ## Verified device response formats
198
+
199
+ | Request `GET /api/get/data?elm=...` | Response key | Decoded length |
200
+ |---|---|---:|
201
+ | `I` | `IALL` | 16 bytes |
202
+ | `O` | `OALL` | 16 bytes |
203
+ | `AI` | `AIALL` | 2048 bytes |
204
+ | `AO` | `AOALL` | 512 bytes |
205
+ | `M` | `MALL` | 128 bytes |
206
+
207
+ The physical device confirmed these response keys and sizes. The library decodes digital blocks least-significant bit first and analog blocks as signed little-endian 32-bit integers. **Not every physical channel-to-bit/index mapping has been independently verified.** Check against known hardware states before relying on mappings in production.
208
+
209
+ For writes, the tested endpoint is `GET /api/set/op?op=M&index=...&val=...` or `op=MW`; successful writes returned **HTTP 204 No Content**. Always verify by reading back when appropriate.
210
+
211
+ ## Error handling
212
+
213
+ The current release uses built-in exceptions, not dedicated library exception classes:
214
+
215
+ - `ConnectionError`: connection, timeout, TLS, or read authentication failures; inspect the message.
216
+ - `PermissionError`: rejected write authorization (401/403).
217
+ - `ValueError`: invalid index/value, malformed response, or rejected write request (400).
218
+ - `OSError`: local file/system problems. `FileNotFoundError` is also an `OSError`.
219
+
220
+ ```python
221
+ from pathlib import Path
222
+ from easye4 import EasyE4
223
+
224
+ try:
225
+ with EasyE4.from_env(Path(__file__).resolve().parent / ".env") as easy:
226
+ easy.connect()
227
+ print(easy.read_marker(1))
228
+ except (ConnectionError, PermissionError, ValueError, OSError) as error:
229
+ print("easyE4 operation failed:", error)
230
+ ```
231
+
232
+ ## Troubleshooting
233
+
234
+ | Symptom | Check |
235
+ |---|---|
236
+ | `EASYE4_IP is not configured` | `.env` location; on 1.0.1 pass `env_file` explicitly |
237
+ | Configuration file not found | Check the current working directory or explicit path (1.0.2 behavior) |
238
+ | Certificate file not found | Leave `EASYE4_CA_FILE=` blank to use the bundled certificate, or provide a valid custom path |
239
+ | `Missing Authority Key Identifier` | Review CA/certificate; compatibility mode only for the verified device case |
240
+ | Connection refused / timeout | IP, port, network, webserver enabled |
241
+ | HTTP 401 | Credentials and user rights; check read vs write permission |
242
+ | HTTP 400 or device `ERROR` | Operand category, index, write range, and device documentation |
243
+ | No I/O data | Enable **Read I/Os** in easySoft and transfer configuration |
244
+ | Write rejected | Enable **marker write**, permitted range, read/write account |
245
+ | Unexpected M/MW/MD values | Check shared-memory overlap and PLC program writes |
246
+ | Zero values | May be valid; confirm PLC program and physical I/O states |
247
+
248
+ ## Tests and validation
249
+
250
+ The `tests/` directory includes mock-based tests for parsing, validation, sessions, reading, writing, and snapshots. Run the offline regression suite after changing transport, TLS, or decoders:
251
+
252
+ ```powershell
253
+ python tests/run_regression.py
254
+ ```
255
+
256
+ The examples and public library have also been exercised against a physical easyE4 on firmware 2.46, build 3603. Mock tests do not prove every hardware address mapping or production security behavior. The package was installed successfully from a wheel in a clean environment; a second-computer test revealed the `.env` path issue addressed in the upcoming 1.0.2.
257
+
258
+ ## Known limitations and next improvements
259
+
260
+ - I/O index-to-physical-channel mappings need controlled hardware validation.
261
+ - TLS compatibility exception needs production security review and ideally compliant device certificates.
262
+ - `read_snapshot()` is sequential, not atomic.
263
+ - No dedicated exception hierarchy yet.
264
+ - No generic MD write method or asynchronous polling API in this version.
265
+ - The examples and API are not certified for safety-critical or unattended control.
266
+
267
+ ## Project structure
268
+
269
+ ```text
270
+ easye4-python/
271
+ ├── easye4/
272
+ │ ├── __init__.py
273
+ │ ├── api.py
274
+ │ ├── client.py
275
+ │ └── certificates/
276
+ │ └── easyRootCertV1.crt
277
+ ├── examples/
278
+ │ ├── 01_connection.py
279
+ │ └── ... 12_error_handling.py
280
+ ├── tests/
281
+ │ └── ...
282
+ ├── .env.example
283
+ ├── .gitignore
284
+ ├── LICENSE
285
+ ├── pyproject.toml
286
+ └── README.md
287
+ ```
288
+
289
+ Keep the library generic. Place process-specific operand mappings, scaling, alarm logic, and logging in the consuming application.
290
+
291
+ ## License and attribution
292
+
293
+ The Python library is distributed under the MIT license, subject to the rights held by its publisher. The bundled Eaton root certificate is third-party material and is **not automatically covered by the library's MIT license**. Eaton and easyE4 are trademarks of their respective owner.
@@ -358,7 +358,14 @@ class EasyE4:
358
358
  """
359
359
 
360
360
  if env_file is None:
361
- env_file = Path(__file__).resolve().parent.parent / ".env"
361
+ env_file = Path.cwd() / ".env"
362
+
363
+ env_file = Path(env_file).resolve()
364
+
365
+ if not env_file.is_file():
366
+ raise FileNotFoundError(
367
+ f"Configuration file not found: {env_file}"
368
+ )
362
369
 
363
370
  load_dotenv(
364
371
  dotenv_path=env_file,