advantech-adc 0.1.0__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.
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ ## 0.0.5
4
+
5
+ - Include the CODESYS example_linux.project alongside the Python examples.
6
+
7
+ ## 0.0.4
8
+
9
+ - Limit the source distribution to the Python API, examples, Windows DLLs,
10
+ user documentation, license notices and files required for source installation.
11
+ - Keep publishing scripts, maintainer documentation and tests in Git only.
12
+
13
+ ## 0.0.3
14
+
15
+ - Add ErrorCode and ThreadPriority IntEnum classes while preserving legacy constant aliases.
16
+ - Update all Python examples to use the enum classes.
17
+ - Document native ADC worker-thread priority behavior on Windows and Linux.
18
+ - Provide a concise English user guide covering installation, API use and examples.
19
+
20
+ ## 0.0.2
21
+
22
+ - Lower the runtime Python requirement to 3.7.
23
+ - Support source builds with the older setuptools/wheel versions available to Python 3.7.
24
+ - Correct author metadata to Advantech/MA and yuhsiang.lin@advantech.com.tw.
25
+
26
+ ## 0.0.1
27
+
28
+ - Initial Python API for Advantech Data Connect (ADC).
29
+ - Bind the 31 public ADC functions, callback types, structures and constants.
30
+ - Publish separate Windows x86 and x64 wheels with matching AdvHandler.dll files.
31
+ - Select the Windows DLL or Linux .so based on Python process pointer size.
32
+ - Load /usr/lib/libADCLibrary-x86.so or /usr/lib/libADCLibrary-x64.so on Linux.
33
+ - Provide asynchronous, local memory, synchronous and structured data examples.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,11 @@
1
+ include LICENSE NOTICE README.md CHANGELOG.md
2
+ include pyproject.toml setup.py
3
+ include advantech_adc/library/x64/AdvHandler.dll
4
+ include advantech_adc/library/x86/AdvHandler.dll
5
+ recursive-include examples *.py
6
+ include examples/example_linux.project
7
+ prune tests
8
+ prune tools
9
+ exclude PUBLISHING.md requirements-dev.txt release.ps1 release.sh
10
+ exclude testpypi.bat pypi.bat .pypirc
11
+ global-exclude __pycache__ *.py[cod] *.lib *.so *.so.*
@@ -0,0 +1,8 @@
1
+ advantech-adc
2
+ Copyright 2026 Advantech/MA
3
+ Maintainer: yuhsiang.lin
4
+
5
+ Python API for Advantech Data Connect (ADC).
6
+ https://github.com/Adv-Yuhsiang/Codesys_ADC
7
+
8
+ Licensed under the Apache License, Version 2.0. See LICENSE.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: advantech-adc
3
+ Version: 0.1.0
4
+ Summary: Python API for Advantech Data Connect (ADC) to access CODESYS PLC symbols and memory.
5
+ Author: Advantech/MA
6
+ Author-email: yuhsiang.lin@advantech.com.tw
7
+ License: Apache-2.0
8
+ Project-URL: Homepage, https://github.com/Adv-Yuhsiang/Codesys_ADC
9
+ Keywords: Advantech,ADC,CODESYS,PLC,automation
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ License-File: NOTICE
17
+ Dynamic: license-file
18
+
19
+ # Advantech Data Connect Python API
20
+
21
+ `advantech-adc` provides Python access to Advantech Data Connect (ADC) for
22
+ reading and writing CODESYS PLC symbols and memory on Windows and Linux.
23
+ It supports synchronous communication, asynchronous polling, local memory
24
+ access.
25
+
26
+ ## Requirements
27
+
28
+ - Python 3.7 or later.
29
+ - Windows x86/x64 or Linux x86/x64.
30
+ - A configured CODESYS controller for remote communication, or the local ADC
31
+ shared memory environment for local memory access.
32
+
33
+ The native library architecture must match the Python process architecture.
34
+ For example, 32-bit Python on 64-bit Windows uses the x86 DLL.
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ python -m pip install advantech-adc
40
+ ```
41
+
42
+ ### Windows
43
+
44
+ The matching x86 or x64 `AdvHandler.dll` is included in the Python package
45
+ and loaded automatically. No manual DLL copying or path selection is required.
46
+
47
+ ### Linux
48
+
49
+ Install CODESYS RTE or `adc-package` first. These installers place the ADC
50
+ shared libraries in `/usr/lib`. The Python package uses the matching library:
51
+
52
+ | Python architecture | Library path |
53
+ | --- | --- |
54
+ | 32-bit | `/usr/lib/libADCLibrary-x86.so` |
55
+ | 64-bit | `/usr/lib/libADCLibrary-x64.so` |
56
+
57
+ Linux shared libraries are provided by the CODESYS RTE or `adc-package`
58
+ installation, not by the Python package.
59
+
60
+ ## Using the API
61
+
62
+ ```python
63
+ from advantech_adc import ADCAPI, ErrorCode, ThreadPriority
64
+
65
+ api = ADCAPI
66
+ ```
67
+
68
+ Call the ADC functions directly through `api`. Most operations return a status
69
+ code; compare it with `ErrorCode.SUCCESS` before continuing. `ErrorCode` groups
70
+ success, error, and connection-status codes. Its members can be compared directly
71
+ with integer API results without using `.value`.
72
+
73
+ - **Synchronous access:** initialize ADC, create a connection with
74
+ `ADC_NewDataConnect()`, connect with `ADC_ConnectSync()`, then read or write
75
+ symbols and memory using the synchronous APIs.
76
+ - **Asynchronous polling:** create a connection and data sectors, register
77
+ callbacks, and call `ADC_StartDataPolling()`.
78
+ - **Local memory access:** initialize ADC and use the `*_Local()` memory APIs.
79
+
80
+ When finished, stop polling if active, disconnect synchronous connections,
81
+ release ADC resources, and call `ADC_Terminate()`. Pass connection names,
82
+ symbol names, and memory addresses as bytes, such as `b"CONN1"` and `b"%MW0"`.
83
+ See the example programs for complete usage.
84
+
85
+ After polling starts, use `api.ADC_SetADCPriority(ThreadPriority.NORMAL)` to
86
+ change the native ADC worker-thread priority. `ThreadPriority` includes `IDLE`,
87
+ `LOWEST`, `BELOW_NORMAL`, `NORMAL`, `ABOVE_NORMAL`, `HIGHEST`, and `TIME_CRITICAL`.
88
+ This does not change the Python main-thread priority. The current Linux library
89
+ requires root for this setting; a non-root call keeps the default priority and
90
+ still returns success. Windows applies the native thread-priority setting.
91
+
92
+ The original constants, such as `ADC_SUCCESS` and `THREAD_PRIORITY_NORMAL`,
93
+ remain available for existing applications.
94
+
95
+ ## Example programs
96
+
97
+ Download the **source distribution** (`advantech_adc-<version>.tar.gz`) from the
98
+ [PyPI files page](https://pypi.org/project/advantech-adc/#files).
99
+ For a TestPyPI installation, use the corresponding
100
+ [TestPyPI files page](https://test.pypi.org/project/advantech-adc/#files).
101
+ Choose the same version as your installed package.
102
+
103
+ After extracting the archive, the examples are located in:
104
+
105
+ ```text
106
+ advantech_adc-<version>/examples/
107
+ ```
108
+
109
+ | Example path | Description |
110
+ | --- | --- |
111
+ | `examples/Example1_async.py` | Reads and writes PLC symbols and memory using asynchronous polling and callbacks. |
112
+ | `examples/Example2_local.py` | Reads and writes local flag memory. Optional full-memory access is disabled by default. |
113
+ | `examples/Example3_sync.py` | Lists PLC symbols and performs synchronous symbol and memory reads and writes. |
114
+ | `examples/Example4_sync_struct.py` | Synchronously reads and writes a PLC structure containing BYTE, WORD, and DWORD fields. |
115
+ | `examples/example_linux.project` | CODESYS sample project for use with the Python examples and a Linux CODESYS runtime. |
116
+
117
+ Open `examples/example_linux.project` in CODESYS, configure the target device,
118
+ and download and run the application before using the remote Python examples.
119
+ Adjust the connection settings in the Python examples to match your controller.
120
+
121
+ Keep `_common.py` in the `examples` directory. Edit the IP address, credentials,
122
+ symbols, and memory settings in each example before running it. The examples
123
+ perform writes to the configured PLC or local memory.
124
+
125
+ From the extracted directory, run an example with the Python environment where
126
+ the package is installed:
127
+
128
+ ```bash
129
+ python examples/Example1_async.py
130
+ ```
131
+
132
+ ## Downloads and support
133
+
134
+ - [Library downloads, manuals and documentation](https://github.com/Adv-Yuhsiang/Codesys_ADC)
135
+ - [Official releases](https://github.com/Adv-Yuhsiang/Codesys_ADC/releases)
136
+ - Author: Advantech/MA
137
+ - Contact: yuhsiang.lin@advantech.com.tw
138
+ - License: Apache License 2.0
@@ -0,0 +1,120 @@
1
+ # Advantech Data Connect Python API
2
+
3
+ `advantech-adc` provides Python access to Advantech Data Connect (ADC) for
4
+ reading and writing CODESYS PLC symbols and memory on Windows and Linux.
5
+ It supports synchronous communication, asynchronous polling, local memory
6
+ access.
7
+
8
+ ## Requirements
9
+
10
+ - Python 3.7 or later.
11
+ - Windows x86/x64 or Linux x86/x64.
12
+ - A configured CODESYS controller for remote communication, or the local ADC
13
+ shared memory environment for local memory access.
14
+
15
+ The native library architecture must match the Python process architecture.
16
+ For example, 32-bit Python on 64-bit Windows uses the x86 DLL.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ python -m pip install advantech-adc
22
+ ```
23
+
24
+ ### Windows
25
+
26
+ The matching x86 or x64 `AdvHandler.dll` is included in the Python package
27
+ and loaded automatically. No manual DLL copying or path selection is required.
28
+
29
+ ### Linux
30
+
31
+ Install CODESYS RTE or `adc-package` first. These installers place the ADC
32
+ shared libraries in `/usr/lib`. The Python package uses the matching library:
33
+
34
+ | Python architecture | Library path |
35
+ | --- | --- |
36
+ | 32-bit | `/usr/lib/libADCLibrary-x86.so` |
37
+ | 64-bit | `/usr/lib/libADCLibrary-x64.so` |
38
+
39
+ Linux shared libraries are provided by the CODESYS RTE or `adc-package`
40
+ installation, not by the Python package.
41
+
42
+ ## Using the API
43
+
44
+ ```python
45
+ from advantech_adc import ADCAPI, ErrorCode, ThreadPriority
46
+
47
+ api = ADCAPI
48
+ ```
49
+
50
+ Call the ADC functions directly through `api`. Most operations return a status
51
+ code; compare it with `ErrorCode.SUCCESS` before continuing. `ErrorCode` groups
52
+ success, error, and connection-status codes. Its members can be compared directly
53
+ with integer API results without using `.value`.
54
+
55
+ - **Synchronous access:** initialize ADC, create a connection with
56
+ `ADC_NewDataConnect()`, connect with `ADC_ConnectSync()`, then read or write
57
+ symbols and memory using the synchronous APIs.
58
+ - **Asynchronous polling:** create a connection and data sectors, register
59
+ callbacks, and call `ADC_StartDataPolling()`.
60
+ - **Local memory access:** initialize ADC and use the `*_Local()` memory APIs.
61
+
62
+ When finished, stop polling if active, disconnect synchronous connections,
63
+ release ADC resources, and call `ADC_Terminate()`. Pass connection names,
64
+ symbol names, and memory addresses as bytes, such as `b"CONN1"` and `b"%MW0"`.
65
+ See the example programs for complete usage.
66
+
67
+ After polling starts, use `api.ADC_SetADCPriority(ThreadPriority.NORMAL)` to
68
+ change the native ADC worker-thread priority. `ThreadPriority` includes `IDLE`,
69
+ `LOWEST`, `BELOW_NORMAL`, `NORMAL`, `ABOVE_NORMAL`, `HIGHEST`, and `TIME_CRITICAL`.
70
+ This does not change the Python main-thread priority. The current Linux library
71
+ requires root for this setting; a non-root call keeps the default priority and
72
+ still returns success. Windows applies the native thread-priority setting.
73
+
74
+ The original constants, such as `ADC_SUCCESS` and `THREAD_PRIORITY_NORMAL`,
75
+ remain available for existing applications.
76
+
77
+ ## Example programs
78
+
79
+ Download the **source distribution** (`advantech_adc-<version>.tar.gz`) from the
80
+ [PyPI files page](https://pypi.org/project/advantech-adc/#files).
81
+ For a TestPyPI installation, use the corresponding
82
+ [TestPyPI files page](https://test.pypi.org/project/advantech-adc/#files).
83
+ Choose the same version as your installed package.
84
+
85
+ After extracting the archive, the examples are located in:
86
+
87
+ ```text
88
+ advantech_adc-<version>/examples/
89
+ ```
90
+
91
+ | Example path | Description |
92
+ | --- | --- |
93
+ | `examples/Example1_async.py` | Reads and writes PLC symbols and memory using asynchronous polling and callbacks. |
94
+ | `examples/Example2_local.py` | Reads and writes local flag memory. Optional full-memory access is disabled by default. |
95
+ | `examples/Example3_sync.py` | Lists PLC symbols and performs synchronous symbol and memory reads and writes. |
96
+ | `examples/Example4_sync_struct.py` | Synchronously reads and writes a PLC structure containing BYTE, WORD, and DWORD fields. |
97
+ | `examples/example_linux.project` | CODESYS sample project for use with the Python examples and a Linux CODESYS runtime. |
98
+
99
+ Open `examples/example_linux.project` in CODESYS, configure the target device,
100
+ and download and run the application before using the remote Python examples.
101
+ Adjust the connection settings in the Python examples to match your controller.
102
+
103
+ Keep `_common.py` in the `examples` directory. Edit the IP address, credentials,
104
+ symbols, and memory settings in each example before running it. The examples
105
+ perform writes to the configured PLC or local memory.
106
+
107
+ From the extracted directory, run an example with the Python environment where
108
+ the package is installed:
109
+
110
+ ```bash
111
+ python examples/Example1_async.py
112
+ ```
113
+
114
+ ## Downloads and support
115
+
116
+ - [Library downloads, manuals and documentation](https://github.com/Adv-Yuhsiang/Codesys_ADC)
117
+ - [Official releases](https://github.com/Adv-Yuhsiang/Codesys_ADC/releases)
118
+ - Author: Advantech/MA
119
+ - Contact: yuhsiang.lin@advantech.com.tw
120
+ - License: Apache License 2.0
@@ -0,0 +1,128 @@
1
+ """Direct ctypes bindings for ADC.h, following AcmP's class-level API style.
2
+
3
+ Importing this module loads the fixed native library and binds its exports.
4
+ Keep callbacks and asynchronous buffers alive until native work has stopped.
5
+ """
6
+
7
+ from ctypes import CDLL, POINTER, c_char_p, c_int, c_long, c_ulong, c_ushort, c_void_p, sizeof
8
+ import os
9
+ from pathlib import Path
10
+ import sys
11
+
12
+ from .ADCType import (
13
+ ADC_SYMBOL_INFO, OnConnectCompletedEvent, OnDisconnectCompletedEvent,
14
+ OnSymdataReadCompletedEvent, OnMemdataReadCompletedEvent,
15
+ OnSymdataWriteCompletedEvent, OnMemdataWriteCompletedEvent,
16
+ )
17
+
18
+ __all__ = ["ADCAPI"]
19
+
20
+ # Fixed paths. Keep the Windows dependency search directory alive with the module.
21
+ _dll_directory = None
22
+ _ARCH = "x64" if sizeof(c_void_p) == 8 else "x86"
23
+ if sys.platform == "win32":
24
+ LIBRARY_PATH = str(Path(__file__).resolve().parent / "library" / _ARCH / "AdvHandler.dll")
25
+ if hasattr(os, "add_dll_directory"):
26
+ _dll_directory = os.add_dll_directory(str(Path(LIBRARY_PATH).parent))
27
+ elif sys.platform.startswith("linux"):
28
+ LIBRARY_PATH = f"/usr/lib/libADCLibrary-{_ARCH}.so"
29
+ else:
30
+ raise OSError("ADC supports Windows and Linux only")
31
+
32
+ lib = CDLL(LIBRARY_PATH) # ADC exports and callbacks use cdecl.
33
+
34
+
35
+ def _bind(name, argtypes=None, restype=c_long):
36
+ try:
37
+ function = getattr(lib, name)
38
+ except AttributeError:
39
+ def missing(*args, **kwargs):
40
+ raise NotImplementedError(f"{name} is not exported by the loaded ADC library")
41
+ # Keep the same call signature through ADCAPI and ADCAPI().
42
+ return staticmethod(missing)
43
+ if argtypes is not None:
44
+ function.argtypes = argtypes
45
+ function.restype = restype
46
+ return function
47
+
48
+
49
+ class ADCAPI:
50
+ """Call ADCAPI.ADC_Initialize(), etc.; native state is process-global."""
51
+
52
+ # General
53
+ ADC_Initialize = _bind("ADC_Initialize", [])
54
+ ADC_Terminate = _bind("ADC_Terminate", [])
55
+ ADC_GetVersion = _bind("ADC_GetVersion", [])
56
+ ADC_StartDataPolling = _bind("ADC_StartDataPolling", [])
57
+ ADC_StopDataPolling = _bind("ADC_StopDataPolling", [])
58
+ ADC_SetADCPriority = _bind("ADC_SetADCPriority", [c_int])
59
+ ADC_ReleaseADCResource = _bind("ADC_ReleaseADCResource", [])
60
+ # Connections
61
+ ADC_NewDataConnect = _bind("ADC_NewDataConnect", [
62
+ c_char_p, c_char_p, c_char_p, c_char_p,
63
+ c_int, c_int, c_int,
64
+ OnConnectCompletedEvent, OnDisconnectCompletedEvent, c_void_p,
65
+ ])
66
+ ADC_SetMemConnectPort = _bind("ADC_SetMemConnectPort", [c_char_p, c_ushort])
67
+ ADC_ConnectSync = _bind("ADC_ConnectSync", [c_char_p])
68
+ ADC_DisconnectSync = _bind("ADC_DisconnectSync", [c_char_p])
69
+ # Polling sectors
70
+ ADC_NewSymdataSector = _bind("ADC_NewSymdataSector", [
71
+ c_char_p, c_char_p, OnSymdataReadCompletedEvent,
72
+ ])
73
+ ADC_AddSymbolToSector = _bind("ADC_AddSymbolToSector", [
74
+ c_char_p, c_char_p, c_char_p,
75
+ ])
76
+ ADC_NewMemdataSector = _bind("ADC_NewMemdataSector", [
77
+ c_char_p, c_char_p, c_char_p, c_int, OnMemdataReadCompletedEvent,
78
+ ])
79
+ # Symbols
80
+ ADC_ReadSymbolValue = _bind("ADC_ReadSymbolValue", [
81
+ c_char_p, c_char_p, c_void_p, POINTER(c_int),
82
+ ])
83
+ ADC_WriteSymbolValue = _bind("ADC_WriteSymbolValue", [
84
+ c_char_p, c_char_p, c_void_p, OnSymdataWriteCompletedEvent,
85
+ ])
86
+ ADC_ReadSymbolValueSync = _bind("ADC_ReadSymbolValueSync", [
87
+ c_char_p, c_char_p, c_void_p, c_ulong,
88
+ ])
89
+ ADC_WriteSymbolValueSync = _bind("ADC_WriteSymbolValueSync", [
90
+ c_char_p, c_char_p, c_void_p, c_ulong,
91
+ ])
92
+ ADC_GetSymbolList = _bind("ADC_GetSymbolList", [
93
+ c_char_p, POINTER(POINTER(ADC_SYMBOL_INFO)), POINTER(c_ulong),
94
+ ])
95
+ ADC_FreeSymbolList = _bind("ADC_FreeSymbolList", [POINTER(ADC_SYMBOL_INFO)], None)
96
+ # Remote memory
97
+ ADC_ReadMemoryValueSync = _bind("ADC_ReadMemoryValueSync", [
98
+ c_char_p, c_char_p, c_void_p, c_ulong,
99
+ ])
100
+ ADC_WriteMemoryValueSync = _bind("ADC_WriteMemoryValueSync", [
101
+ c_char_p, c_char_p, c_void_p, c_ulong,
102
+ ])
103
+ ADC_ReadSingleMemoryValue = _bind("ADC_ReadSingleMemoryValue", [
104
+ c_char_p, c_char_p, c_void_p, POINTER(c_int),
105
+ ])
106
+ ADC_ReadMultipleMemoryValue = _bind("ADC_ReadMultipleMemoryValue", [
107
+ c_char_p, c_char_p, c_int, c_void_p, POINTER(c_int),
108
+ ])
109
+ ADC_WriteSingleMemoryValue = _bind("ADC_WriteSingleMemoryValue", [
110
+ c_char_p, c_char_p, c_void_p, POINTER(c_int), OnMemdataWriteCompletedEvent,
111
+ ])
112
+ ADC_WriteMultipleMemoryValue = _bind("ADC_WriteMultipleMemoryValue", [
113
+ c_char_p, c_char_p, c_int, c_void_p, POINTER(c_int), OnMemdataWriteCompletedEvent,
114
+ ])
115
+ ADC_ShowConnection = _bind("ADC_ShowConnection", [])
116
+ # Local memory
117
+ ADC_ReadSingleMemoryValue_Local = _bind("ADC_ReadSingleMemoryValue_Local", [
118
+ c_char_p, c_void_p, POINTER(c_int),
119
+ ])
120
+ ADC_ReadMultipleMemoryValue_Local = _bind("ADC_ReadMultipleMemoryValue_Local", [
121
+ c_char_p, c_int, c_void_p, POINTER(c_int),
122
+ ])
123
+ ADC_WriteSingleMemoryValue_Local = _bind("ADC_WriteSingleMemoryValue_Local", [
124
+ c_char_p, c_void_p, POINTER(c_int),
125
+ ])
126
+ ADC_WriteMultipleMemoryValue_Local = _bind("ADC_WriteMultipleMemoryValue_Local", [
127
+ c_char_p, c_int, c_void_p, POINTER(c_int),
128
+ ])