easye4-python 1.0.1__py3-none-any.whl → 1.0.2__py3-none-any.whl

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.
easye4/client.py CHANGED
@@ -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,
@@ -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,9 @@
1
+ easye4/__init__.py,sha256=1zE_2rfQdfMC00998J8EzMznbCqyF_dM6-eVrosWM14,146
2
+ easye4/api.py,sha256=g_4lBc_0trKYNEzStTSFUTITJwlGW7xKKv_A93d2rRQ,24314
3
+ easye4/client.py,sha256=_SKo7LtbvKE4bSWBLMZykwikrKJ9GyrOx33TeQLlz_U,11592
4
+ easye4/certificates/easyRootCertV1.crt,sha256=XQtIJT2YBowCmg5MANLDXnN5aygSlXs2DtbsnABatIM,882
5
+ easye4_python-1.0.2.dist-info/licenses/LICENSE,sha256=1A01jEVyoX9z-VjkgGr69UGznKlUUeZh57uXB1EXn3U,1069
6
+ easye4_python-1.0.2.dist-info/METADATA,sha256=Oi7f-3RyBQ05VRqohob_2T-pr5k6cjRh221j2iJryIA,14579
7
+ easye4_python-1.0.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ easye4_python-1.0.2.dist-info/top_level.txt,sha256=sBrQ_NyV5SPXLWLdL4FK0bAMN2HA8waTRqcFXzzUCIk,7
9
+ easye4_python-1.0.2.dist-info/RECORD,,
@@ -1,251 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: easye4-python
3
- Version: 1.0.1
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 Python interface for the Eaton easyE4 JSON API. The library provides system information, digital and analog I/O reads, marker memory reads, and controlled marker writes without application-specific scaling or operand mappings.
22
-
23
- **Status:** Development release 1.0.0. Tested with a physical easyE4 on firmware 2.46 (build 3603). This is an independently developed starter kit, not an official Eaton SDK.
24
-
25
- ## Requirements
26
-
27
- - Python 3.10 or newer
28
- - Network access to an easyE4 with its webserver enabled
29
- - Appropriate easySoft webserver settings and user permissions
30
- - `requests` and `python-dotenv` (installed automatically with the package)
31
-
32
- For reading I/O, enable **Read I/Os** in the easySoft webserver configuration. For writing markers, enable **marker write**, configure an allowed write range, and use an account with read/write rights. Transfer configuration changes to the device.
33
-
34
- ## Installation
35
-
36
- From the project root (the directory containing `pyproject.toml`):
37
-
38
- ```powershell
39
- python -m venv .venv
40
- .venv\Scripts\Activate.ps1
41
- python -m pip install -e .
42
- ```
43
-
44
- Editable installation is useful for development. To install a local copy non-editably, run `python -m pip install .`.
45
-
46
- ## Configuration
47
-
48
- Copy `.env.example` to `.env` in the project root and fill in your own values:
49
-
50
- ```dotenv
51
- EASYE4_IP=192.168.1.100
52
- EASYE4_PORT=443
53
- EASYE4_PROTOCOL=https
54
- EASYE4_TIMEOUT=5
55
- EASYE4_AUTH_METHOD=basic
56
- EASYE4_USERNAME=
57
- EASYE4_PASSWORD=
58
- EASYE4_API_KEY=
59
- EASYE4_CA_FILE=certificates/easyRootCertV1.crt
60
- EASYE4_TLS_COMPATIBILITY=false
61
- ```
62
-
63
- - Supported authentication modes: `none`, `basic`, `bearer`.
64
- - The CA path is resolved relative to the `.env` file when using `EasyE4.from_env()`.
65
- - Do not commit `.env`, passwords, API keys, or private keys to version control.
66
- - `from_env()` in this development version defaults to the package project's `.env`; for another location pass `EasyE4.from_env(env_file="path/to/.env")`.
67
-
68
- ### TLS security
69
-
70
- Normal certificate verification is the default. 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 and hostname verification. This is a **compatibility exception**, not the preferred production configuration. Validate certificate identity, trust, and security requirements before customer deployment. Never use `verify=False` as a routine workaround.
71
-
72
- ## Quick start
73
-
74
- ```python
75
- from easye4 import EasyE4
76
-
77
- with EasyE4.from_env() as easy:
78
- connection = easy.connect()
79
- print(connection)
80
- print("State:", easy.get_state())
81
- print("M1:", easy.read_marker(1))
82
- print("MW1:", easy.read_word(1))
83
- ```
84
-
85
- The context manager closes the HTTP session automatically. `connect()` verifies communication using the firmware endpoint; it does not start or stop the PLC program.
86
-
87
- ## Public API
88
-
89
- ### Connection and system information
90
-
91
- | Method | Purpose |
92
- |---|---|
93
- | `connect()` | Verify communication and authentication; return connection details |
94
- | `disconnect()` | Close HTTP session |
95
- | `is_connected()` | Check whether device responds now |
96
- | `get_firmware()` | Return version and build |
97
- | `get_state()` | Return RUN/STOP state |
98
- | `get_device_name()` | Read configured device name |
99
- | `get_program_name()` | Read program name |
100
-
101
- ### Read I/O
102
-
103
- | Method | Returns |
104
- |---|---|
105
- | `read_digital_input(index)` / `read_digital_inputs(indices)` | `I` bit(s), 0/1 |
106
- | `read_digital_output(index)` / `read_digital_outputs(indices)` | `O` bit(s), 0/1 |
107
- | `read_analog_input(index)` / `read_analog_inputs(indices)` | Raw signed 32-bit `AI` value(s) |
108
- | `read_analog_output(index)` / `read_analog_outputs(indices)` | Raw signed 32-bit `AO` value(s) |
109
- | `read_io(digital_inputs=..., digital_outputs=..., analog_inputs=..., analog_outputs=...)` | Combined I/O dictionary |
110
-
111
- ### Marker memory
112
-
113
- | Method | Purpose |
114
- |---|---|
115
- | `read_marker(index)` / `read_markers(indices)` | Read M bit(s) |
116
- | `read_word(index)` | Read unsigned 16-bit MW |
117
- | `read_dword(index)` | Read unsigned 32-bit MD |
118
- | `read_memory(markers=..., words=..., dwords=...)` | Read selected M/MW/MD from one `MALL` response |
119
- | `write_marker(index, value)` | Write 0 or 1 to an allowed M address |
120
- | `write_word(index, value)` | Write 0..65535 to an allowed MW address |
121
- | `read_snapshot(...)` | Combine selected I/O and marker-memory reads |
122
-
123
- `read_snapshot()` accepts the four `read_io()` lists plus `markers`, `words`, and `dwords`. It uses up to five sequential HTTP requests, **not** an atomic PLC snapshot. A requested marker-memory group uses one request regardless of how many M/MW/MD values it selects.
124
-
125
- ```python
126
- with EasyE4.from_env() as easy:
127
- easy.connect()
128
- snapshot = easy.read_snapshot(
129
- digital_inputs=[1, 2],
130
- digital_outputs=[1, 2],
131
- analog_inputs=[1, 2],
132
- analog_outputs=[1],
133
- markers=[1, 2],
134
- words=[1, 2],
135
- dwords=[1],
136
- )
137
- print(snapshot)
138
- ```
139
-
140
- **Raw data:** No engineering units or scale factors are applied. Interpret values according to the connected easySoft program. `M`, `MB`, `MW`, and `MD` overlap in the same memory: `MW1` contains the bits of `M1` through `M16`, and `MD1` covers `MW1` and `MW2`. Do not assign unrelated variables to overlapping addresses.
141
-
142
- ## Writing safely
143
-
144
- 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. Automatic restoration cannot be guaranteed after network or power loss.
145
-
146
- ```python
147
- # Only on a verified safe test address, with appropriate authorization.
148
- with EasyE4.from_env() as easy:
149
- easy.connect()
150
- original = easy.read_marker(100)
151
- # Inspect and confirm safety before calling easy.write_marker(...).
152
- ```
153
-
154
- ## Examples
155
-
156
- Run from the project root, e.g. `python examples/01_connection.py`.
157
-
158
- | File | Demonstrates | Writes to PLC? |
159
- |---|---|---|
160
- | `01_connection.py` | Connect and close | No |
161
- | `02_system_info.py` | Firmware, state, names | No |
162
- | `03_digital_inputs.py` | IALL diagnostic read | No |
163
- | `04_digital_outputs.py` | OALL diagnostic read | No |
164
- | `05_analog_inputs.py` | AIALL raw values | No |
165
- | `06_analog_outputs.py` | AOALL raw values | No |
166
- | `07_read_markers.py` | Single and multiple M reads | No |
167
- | `08_read_words.py` | MW/MD, signed conversion and overlap | No |
168
- | `09_write_markers.py` | Interactive M/MW write and restore | **Yes, after confirmation** |
169
- | `10_combined_read.py` | `read_snapshot()` | No |
170
- | `11_live_monitor.py` | Polling and change detection; Ctrl+C to stop | No |
171
- | `12_error_handling.py` | Error scenarios (mostly mocks) | No |
172
-
173
- Some diagnostic examples intentionally use the internal `easy.api._get_json()` interface to inspect device responses. Application code should prefer the public `EasyE4` methods.
174
-
175
- ## Verified device response formats
176
-
177
- | Request (`GET /api/get/data?elm=...`) | Response key | Decoded length |
178
- |---|---|---:|
179
- | `I` | `IALL` | 16 bytes |
180
- | `O` | `OALL` | 16 bytes |
181
- | `AI` | `AIALL` | 2048 bytes |
182
- | `AO` | `AOALL` | 512 bytes |
183
- | `M` | `MALL` | 128 bytes |
184
-
185
- The physical device confirmed these response keys and sizes. The library decodes digital blocks bitwise (least-significant bit first) and analog blocks as signed little-endian 32-bit integers. **Exact physical channel-to-bit/index mapping has not been independently verified for every I/O channel.** Check against known hardware states before relying on a mapping in production.
186
-
187
- For writes, the tested endpoint is `GET /api/set/op?op=M&index=...&val=...` or `op=MW`; a successful write returned HTTP **204 No Content**. A write response is not a substitute for readback verification.
188
-
189
- ## Error handling
190
-
191
- The current release uses built-in exceptions rather than dedicated library exception classes:
192
-
193
- - `ConnectionError`: connection, timeout, TLS, or read authentication failures (inspect message).
194
- - `PermissionError`: rejected write authorization (401/403).
195
- - `ValueError`: invalid index/value, malformed response, or rejected write request (400).
196
- - `OSError`: local file/system problems.
197
-
198
- ```python
199
- try:
200
- with EasyE4.from_env() as easy:
201
- easy.connect()
202
- print(easy.read_marker(1))
203
- except (ConnectionError, PermissionError, ValueError, OSError) as error:
204
- print("easyE4 operation failed:", error)
205
- ```
206
-
207
- ## Troubleshooting
208
-
209
- | Symptom | Check |
210
- |---|---|
211
- | Connection refused / timeout | IP, port, network, webserver enabled |
212
- | HTTP 401 | Credentials and user rights; check read vs write permission |
213
- | HTTP 400 or device `ERROR` | Operand category, index, write range and device documentation |
214
- | No I/O data / operand error | **Enable Read I/Os** in easySoft and download configuration |
215
- | Write rejected | **Enable marker (write)**, permitted range, read/write account |
216
- | `Missing Authority Key Identifier` | Review CA/certificate; compatibility setting only for the verified device case |
217
- | Unexpected M/MW/MD values | Check shared-memory overlap and PLC program writes |
218
- | Zero values | May be valid; confirm PLC program and physical input/output states |
219
-
220
- ## Tests and validation
221
-
222
- The `tests/` directory contains mock-based tests for parsing, validation, connection and error handling. Examples were also exercised against a physical easyE4 firmware 2.46, build 3603. Tests using mocks do **not** prove all hardware address mappings or security behavior. Run regression tests after changing transport, TLS or decoders.
223
-
224
- ## Known limitations and next improvements
225
-
226
- - I/O index-to-physical-channel mappings need controlled hardware validation.
227
- - TLS compatibility exception needs production security review and ideally compliant device certificates.
228
- - `read_snapshot()` is sequential, not atomic.
229
- - No dedicated exception hierarchy yet.
230
- - No generic MD write method or asynchronous polling API in this version.
231
- - The examples and API have not been certified for safety-critical or unattended control.
232
-
233
- ## Project structure
234
-
235
- ```text
236
- easye4-python/
237
- easye4/
238
- __init__.py
239
- api.py
240
- client.py
241
- examples/
242
- 01_connection.py ... 12_error_handling.py
243
- tests/
244
- certificates/
245
- .env.example
246
- .gitignore
247
- pyproject.toml
248
- README.md
249
- ```
250
-
251
- For new applications, keep the library generic and place process-specific operand mappings, scaling, alarm logic, and logging in the consuming project.
@@ -1,9 +0,0 @@
1
- easye4/__init__.py,sha256=1zE_2rfQdfMC00998J8EzMznbCqyF_dM6-eVrosWM14,146
2
- easye4/api.py,sha256=g_4lBc_0trKYNEzStTSFUTITJwlGW7xKKv_A93d2rRQ,24314
3
- easye4/client.py,sha256=TQNiSVRj4j_Y68V5jw0n9PIwtsjCmdpjejFfmg890e0,11421
4
- easye4/certificates/easyRootCertV1.crt,sha256=XQtIJT2YBowCmg5MANLDXnN5aygSlXs2DtbsnABatIM,882
5
- easye4_python-1.0.1.dist-info/licenses/LICENSE,sha256=1A01jEVyoX9z-VjkgGr69UGznKlUUeZh57uXB1EXn3U,1069
6
- easye4_python-1.0.1.dist-info/METADATA,sha256=-8rEYN9km2sou81GMxdeeJHT0-aPcQyiiDx9ChMqBU0,11367
7
- easye4_python-1.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
- easye4_python-1.0.1.dist-info/top_level.txt,sha256=sBrQ_NyV5SPXLWLdL4FK0bAMN2HA8waTRqcFXzzUCIk,7
9
- easye4_python-1.0.1.dist-info/RECORD,,