zlgcan 0.1.17__tar.gz → 0.2.1__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.
- {zlgcan-0.1.17 → zlgcan-0.2.1}/.github/workflows/CI.yml +2 -4
- zlgcan-0.2.1/CHANGELOG.md +12 -0
- {zlgcan-0.1.17 → zlgcan-0.2.1}/Cargo.lock +45 -53
- {zlgcan-0.1.17 → zlgcan-0.2.1}/Cargo.toml +4 -4
- {zlgcan-0.1.17 → zlgcan-0.2.1}/PKG-INFO +17 -29
- {zlgcan-0.1.17 → zlgcan-0.2.1}/README.md +16 -28
- {zlgcan-0.1.17 → zlgcan-0.2.1}/src/lib.rs +18 -14
- {zlgcan-0.1.17 → zlgcan-0.2.1}/src/wrappers/mod.rs +6 -6
- {zlgcan-0.1.17 → zlgcan-0.2.1}/zlgcan/zlgcan.py +6 -2
- {zlgcan-0.1.17 → zlgcan-0.2.1}/.editorconfig +0 -0
- {zlgcan-0.1.17 → zlgcan-0.2.1}/.github/workflows/label-check.yml +0 -0
- {zlgcan-0.1.17 → zlgcan-0.2.1}/.gitignore +0 -0
- {zlgcan-0.1.17 → zlgcan-0.2.1}/LICENSE.txt +0 -0
- {zlgcan-0.1.17 → zlgcan-0.2.1}/pyproject.toml +0 -0
- {zlgcan-0.1.17 → zlgcan-0.2.1}/requirements.txt +0 -0
- {zlgcan-0.1.17 → zlgcan-0.2.1}/src/wrappers/constants.rs +0 -0
- {zlgcan-0.1.17 → zlgcan-0.2.1}/zlgcan/__init__.py +0 -0
@@ -48,8 +48,6 @@ jobs:
|
|
48
48
|
platform:
|
49
49
|
- runner: windows-latest
|
50
50
|
target: x64
|
51
|
-
- runner: windows-latest
|
52
|
-
target: x86
|
53
51
|
steps:
|
54
52
|
- uses: actions/checkout@v4
|
55
53
|
- uses: actions/setup-python@v5
|
@@ -93,8 +91,8 @@ jobs:
|
|
93
91
|
- name: Publish to PyPI
|
94
92
|
uses: PyO3/maturin-action@v1
|
95
93
|
env:
|
96
|
-
MATURIN_PYPI_TOKEN: ${{ secrets.
|
94
|
+
MATURIN_PYPI_TOKEN: ${{ secrets.ZLGCAN_TOKEN }}
|
97
95
|
with:
|
98
|
-
token: ${{ secrets.
|
96
|
+
token: ${{ secrets.ZLGCAN_TOKEN }}
|
99
97
|
command: upload
|
100
98
|
args: --non-interactive --skip-existing wheels-*/*
|
@@ -4,27 +4,21 @@ version = 4
|
|
4
4
|
|
5
5
|
[[package]]
|
6
6
|
name = "anyhow"
|
7
|
-
version = "1.0.
|
7
|
+
version = "1.0.98"
|
8
8
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
9
|
-
checksum = "
|
9
|
+
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
|
10
10
|
|
11
11
|
[[package]]
|
12
12
|
name = "autocfg"
|
13
|
-
version = "1.
|
13
|
+
version = "1.5.0"
|
14
14
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
15
|
-
checksum = "
|
15
|
+
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
16
16
|
|
17
17
|
[[package]]
|
18
18
|
name = "bitflags"
|
19
|
-
version = "2.9.
|
19
|
+
version = "2.9.1"
|
20
20
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
21
|
-
checksum = "
|
22
|
-
|
23
|
-
[[package]]
|
24
|
-
name = "cfg-if"
|
25
|
-
version = "1.0.0"
|
26
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
27
|
-
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
21
|
+
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
28
22
|
|
29
23
|
[[package]]
|
30
24
|
name = "derive-getters"
|
@@ -39,9 +33,9 @@ dependencies = [
|
|
39
33
|
|
40
34
|
[[package]]
|
41
35
|
name = "dlopen2"
|
42
|
-
version = "0.
|
36
|
+
version = "0.8.0"
|
43
37
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
44
|
-
checksum = "
|
38
|
+
checksum = "b54f373ccf864bf587a89e880fb7610f8d73f3045f13580948ccbcaff26febff"
|
45
39
|
dependencies = [
|
46
40
|
"dlopen2_derive",
|
47
41
|
"libc",
|
@@ -51,21 +45,15 @@ dependencies = [
|
|
51
45
|
|
52
46
|
[[package]]
|
53
47
|
name = "dlopen2_derive"
|
54
|
-
version = "0.4.
|
48
|
+
version = "0.4.1"
|
55
49
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
56
|
-
checksum = "
|
50
|
+
checksum = "788160fb30de9cdd857af31c6a2675904b16ece8fc2737b2c7127ba368c9d0f4"
|
57
51
|
dependencies = [
|
58
52
|
"proc-macro2",
|
59
53
|
"quote",
|
60
54
|
"syn",
|
61
55
|
]
|
62
56
|
|
63
|
-
[[package]]
|
64
|
-
name = "dotenvy"
|
65
|
-
version = "0.15.7"
|
66
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
67
|
-
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
68
|
-
|
69
57
|
[[package]]
|
70
58
|
name = "equivalent"
|
71
59
|
version = "1.0.2"
|
@@ -74,9 +62,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
|
74
62
|
|
75
63
|
[[package]]
|
76
64
|
name = "hashbrown"
|
77
|
-
version = "0.15.
|
65
|
+
version = "0.15.4"
|
78
66
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
79
|
-
checksum = "
|
67
|
+
checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
80
68
|
|
81
69
|
[[package]]
|
82
70
|
name = "heck"
|
@@ -86,9 +74,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
86
74
|
|
87
75
|
[[package]]
|
88
76
|
name = "indexmap"
|
89
|
-
version = "2.
|
77
|
+
version = "2.10.0"
|
90
78
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
91
|
-
checksum = "
|
79
|
+
checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
|
92
80
|
dependencies = [
|
93
81
|
"equivalent",
|
94
82
|
"hashbrown",
|
@@ -108,9 +96,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
|
108
96
|
|
109
97
|
[[package]]
|
110
98
|
name = "libc"
|
111
|
-
version = "0.2.
|
99
|
+
version = "0.2.174"
|
112
100
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
113
|
-
checksum = "
|
101
|
+
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
|
114
102
|
|
115
103
|
[[package]]
|
116
104
|
name = "log"
|
@@ -135,26 +123,25 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
|
135
123
|
|
136
124
|
[[package]]
|
137
125
|
name = "portable-atomic"
|
138
|
-
version = "1.11.
|
126
|
+
version = "1.11.1"
|
139
127
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
140
|
-
checksum = "
|
128
|
+
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
|
141
129
|
|
142
130
|
[[package]]
|
143
131
|
name = "proc-macro2"
|
144
|
-
version = "1.0.
|
132
|
+
version = "1.0.95"
|
145
133
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
146
|
-
checksum = "
|
134
|
+
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
147
135
|
dependencies = [
|
148
136
|
"unicode-ident",
|
149
137
|
]
|
150
138
|
|
151
139
|
[[package]]
|
152
140
|
name = "pyo3"
|
153
|
-
version = "0.
|
141
|
+
version = "0.25.1"
|
154
142
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
155
|
-
checksum = "
|
143
|
+
checksum = "8970a78afe0628a3e3430376fc5fd76b6b45c4d43360ffd6cdd40bdde72b682a"
|
156
144
|
dependencies = [
|
157
|
-
"cfg-if",
|
158
145
|
"indoc",
|
159
146
|
"libc",
|
160
147
|
"memoffset",
|
@@ -168,9 +155,9 @@ dependencies = [
|
|
168
155
|
|
169
156
|
[[package]]
|
170
157
|
name = "pyo3-build-config"
|
171
|
-
version = "0.
|
158
|
+
version = "0.25.1"
|
172
159
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
173
|
-
checksum = "
|
160
|
+
checksum = "458eb0c55e7ece017adeba38f2248ff3ac615e53660d7c71a238d7d2a01c7598"
|
174
161
|
dependencies = [
|
175
162
|
"once_cell",
|
176
163
|
"target-lexicon",
|
@@ -178,9 +165,9 @@ dependencies = [
|
|
178
165
|
|
179
166
|
[[package]]
|
180
167
|
name = "pyo3-ffi"
|
181
|
-
version = "0.
|
168
|
+
version = "0.25.1"
|
182
169
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
183
|
-
checksum = "
|
170
|
+
checksum = "7114fe5457c61b276ab77c5055f206295b812608083644a5c5b2640c3102565c"
|
184
171
|
dependencies = [
|
185
172
|
"libc",
|
186
173
|
"pyo3-build-config",
|
@@ -188,9 +175,9 @@ dependencies = [
|
|
188
175
|
|
189
176
|
[[package]]
|
190
177
|
name = "pyo3-macros"
|
191
|
-
version = "0.
|
178
|
+
version = "0.25.1"
|
192
179
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
193
|
-
checksum = "
|
180
|
+
checksum = "a8725c0a622b374d6cb051d11a0983786448f7785336139c3c94f5aa6bef7e50"
|
194
181
|
dependencies = [
|
195
182
|
"proc-macro2",
|
196
183
|
"pyo3-macros-backend",
|
@@ -200,9 +187,9 @@ dependencies = [
|
|
200
187
|
|
201
188
|
[[package]]
|
202
189
|
name = "pyo3-macros-backend"
|
203
|
-
version = "0.
|
190
|
+
version = "0.25.1"
|
204
191
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
205
|
-
checksum = "
|
192
|
+
checksum = "4109984c22491085343c05b0dbc54ddc405c3cf7b4374fc533f5c3313a572ccc"
|
206
193
|
dependencies = [
|
207
194
|
"heck",
|
208
195
|
"proc-macro2",
|
@@ -222,17 +209,23 @@ dependencies = [
|
|
222
209
|
|
223
210
|
[[package]]
|
224
211
|
name = "rs-can"
|
225
|
-
version = "0.
|
226
|
-
source = "
|
227
|
-
checksum = "4416620ec3f2141f73b5d0936481c9caf3aa27ba140e2a97f178b80b7f110f68"
|
212
|
+
version = "0.3.0"
|
213
|
+
source = "git+https://github.com/jesses2025smith/rust-can.git?rev=e76db38dd2e6d66f0afa9374e9a9513d984b6be2#e76db38dd2e6d66f0afa9374e9a9513d984b6be2"
|
228
214
|
dependencies = [
|
229
215
|
"bitflags",
|
230
216
|
"derive-getters",
|
231
217
|
"log",
|
218
|
+
"rsutil",
|
232
219
|
"serde",
|
233
220
|
"thiserror",
|
234
221
|
]
|
235
222
|
|
223
|
+
[[package]]
|
224
|
+
name = "rsutil"
|
225
|
+
version = "0.1.12"
|
226
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
227
|
+
checksum = "2db82abc50469bbff9ce708b13b3ff27c779a8ddbbe5640017278608bf33b820"
|
228
|
+
|
236
229
|
[[package]]
|
237
230
|
name = "ryu"
|
238
231
|
version = "1.0.20"
|
@@ -274,9 +267,9 @@ dependencies = [
|
|
274
267
|
|
275
268
|
[[package]]
|
276
269
|
name = "syn"
|
277
|
-
version = "2.0.
|
270
|
+
version = "2.0.104"
|
278
271
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
279
|
-
checksum = "
|
272
|
+
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
280
273
|
dependencies = [
|
281
274
|
"proc-macro2",
|
282
275
|
"quote",
|
@@ -351,21 +344,20 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
351
344
|
|
352
345
|
[[package]]
|
353
346
|
name = "zlgcan"
|
354
|
-
version = "0.
|
355
|
-
source = "
|
356
|
-
checksum = "ad37441e238647c26ae9521b03bfb3abf3dbd37c74ac4f47219a624781b71f7a"
|
347
|
+
version = "0.3.0"
|
348
|
+
source = "git+https://github.com/jesses2025smith/rust-can.git?rev=e76db38dd2e6d66f0afa9374e9a9513d984b6be2#e76db38dd2e6d66f0afa9374e9a9513d984b6be2"
|
357
349
|
dependencies = [
|
358
350
|
"dlopen2",
|
359
|
-
"dotenvy",
|
360
351
|
"log",
|
361
352
|
"rs-can",
|
353
|
+
"rsutil",
|
362
354
|
"serde",
|
363
355
|
"serde_yaml",
|
364
356
|
]
|
365
357
|
|
366
358
|
[[package]]
|
367
359
|
name = "zlgcan-driver"
|
368
|
-
version = "0.1
|
360
|
+
version = "0.2.1"
|
369
361
|
dependencies = [
|
370
362
|
"anyhow",
|
371
363
|
"pyo3",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[package]
|
2
2
|
name = "zlgcan-driver"
|
3
|
-
version = "0.1
|
3
|
+
version = "0.2.1"
|
4
4
|
edition = "2021"
|
5
5
|
|
6
6
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
@@ -9,12 +9,12 @@ name = "zlgcan_driver"
|
|
9
9
|
crate-type = ["cdylib"]
|
10
10
|
|
11
11
|
[dependencies]
|
12
|
-
pyo3 = "0.
|
12
|
+
pyo3 = "0.25"
|
13
13
|
#iso15765-2 = { version = "0.1.0-alpha0" }
|
14
14
|
#iso14229-1 = { version = "0.1.0-alpha0" }
|
15
15
|
#docan = { version = "0.1.0-alpha0" }
|
16
|
-
rs-can = {
|
17
|
-
zlgcan = {
|
16
|
+
rs-can = { git = "https://github.com/jesses2025smith/rust-can.git", package = "rs-can", rev = "e76db38dd2e6d66f0afa9374e9a9513d984b6be2" }
|
17
|
+
zlgcan = { git = "https://github.com/jesses2025smith/rust-can.git", package = "zlgcan", rev = "e76db38dd2e6d66f0afa9374e9a9513d984b6be2" }
|
18
18
|
|
19
19
|
[dev-dependencies]
|
20
20
|
anyhow = "1"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: zlgcan
|
3
|
-
Version: 0.1
|
3
|
+
Version: 0.2.1
|
4
4
|
Classifier: Programming Language :: Rust
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
@@ -17,45 +17,31 @@ Project-URL: repository, https://github.com/zhuyu4839/zlgcan-driver
|
|
17
17
|

|
18
18
|

|
19
19
|
|
20
|
-
# ZLGCAN驱动及集成到python-can(
|
20
|
+
# ZLGCAN驱动及集成到python-can(不支持32位)
|
21
21
|
|
22
22
|
1. 准备
|
23
23
|
* 确保安装相关驱动(USBCAN-I/II驱动得额外安装)
|
24
24
|
* 确保安装相[VC++运行环境](https://manual.zlg.cn/web/#/152?page_id=5332)
|
25
25
|
* 下载[library](https://github.com/zhuyu4839/rust-can/tree/master/zlgcan/library)文件夹(里面包含[bitrate.cfg.yaml](https://github.com/zhuyu4839/rust-can/tree/master/zlgcan/library/bitrate.cfg.yaml))
|
26
|
-
*
|
27
|
-
* 默认(相对运行脚本)路径文件夹内容示例:
|
26
|
+
* 库文件示例:
|
28
27
|
```shell
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
│ │ └─x86_64
|
33
|
-
│ └─windows
|
34
|
-
│ ├─x86
|
35
|
-
│ └─x86_64
|
36
|
-
└─ bitrate.cfg.yaml
|
37
|
-
```
|
38
|
-
* (相对运行脚本)`zcan.env`文件指定`library`示例:
|
39
|
-
```shell
|
40
|
-
├─main.py
|
41
|
-
├─zcan.env
|
42
|
-
└─library
|
43
|
-
├─linux
|
44
|
-
│ └─x86_64
|
45
|
-
├─windows
|
46
|
-
│ ├─x86
|
28
|
+
library
|
29
|
+
├──bitrate.cfg.yaml
|
30
|
+
├──linux
|
47
31
|
│ └─x86_64
|
48
|
-
└─
|
32
|
+
└─windows
|
33
|
+
└─x86_64
|
34
|
+
```
|
35
|
+
* 在初始化can.Bus的时候指定zlgcan库路径(从0.2.0开始移除`zcan.env`配置), 默认为相对工程运行文件同级目录下`library`
|
36
|
+
```python
|
37
|
+
libpath=r"C:\your\library\path"
|
49
38
|
```
|
50
|
-
* 以下为`zcan.env`文件内容示例
|
51
|
-
```shell
|
52
|
-
ZCAN_LIBRARY="C:/your_library_path"
|
53
|
-
```
|
54
39
|
|
55
|
-
2. 安装zlgcan
|
40
|
+
2. 安装zlgcan(不建议使用低于0.2.0版本)
|
56
41
|
|
57
42
|
```shell
|
58
|
-
pip install zlgcan >= 0.
|
43
|
+
pip install zlgcan >= 0.2.0
|
44
|
+
```
|
59
45
|
|
60
46
|
3. 使用:
|
61
47
|
```python
|
@@ -63,6 +49,7 @@ Project-URL: repository, https://github.com/zhuyu4839/zlgcan-driver
|
|
63
49
|
from zlgcan.zlgcan import ZCanTxMode, ZCANDeviceType
|
64
50
|
|
65
51
|
with can.Bus(interface="zlgcan", device_type=ZCANDeviceType.ZCAN_USBCANFD_200U,
|
52
|
+
libpath="library/",
|
66
53
|
configs=[{'bitrate': 500000, 'resistance': 1}, {'bitrate': 500000, 'resistance': 1}]) as bus:
|
67
54
|
bus.send(can.Message(
|
68
55
|
arbitration_id=0x123,
|
@@ -75,6 +62,7 @@ Project-URL: repository, https://github.com/zhuyu4839/zlgcan-driver
|
|
75
62
|
# time.sleep(0.1)
|
76
63
|
_msg = bus.recv()
|
77
64
|
print(_msg)
|
65
|
+
```
|
78
66
|
|
79
67
|
4. CAN测试列表:
|
80
68
|
* USBCAN-I-mini - ZCAN_USBCAN1, ZCAN_USBCAN2
|
@@ -1,45 +1,31 @@
|
|
1
1
|

|
2
2
|

|
3
3
|
|
4
|
-
# ZLGCAN驱动及集成到python-can(
|
4
|
+
# ZLGCAN驱动及集成到python-can(不支持32位)
|
5
5
|
|
6
6
|
1. 准备
|
7
7
|
* 确保安装相关驱动(USBCAN-I/II驱动得额外安装)
|
8
8
|
* 确保安装相[VC++运行环境](https://manual.zlg.cn/web/#/152?page_id=5332)
|
9
9
|
* 下载[library](https://github.com/zhuyu4839/rust-can/tree/master/zlgcan/library)文件夹(里面包含[bitrate.cfg.yaml](https://github.com/zhuyu4839/rust-can/tree/master/zlgcan/library/bitrate.cfg.yaml))
|
10
|
-
*
|
11
|
-
* 默认(相对运行脚本)路径文件夹内容示例:
|
10
|
+
* 库文件示例:
|
12
11
|
```shell
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
│ │ └─x86_64
|
17
|
-
│ └─windows
|
18
|
-
│ ├─x86
|
19
|
-
│ └─x86_64
|
20
|
-
└─ bitrate.cfg.yaml
|
21
|
-
```
|
22
|
-
* (相对运行脚本)`zcan.env`文件指定`library`示例:
|
23
|
-
```shell
|
24
|
-
├─main.py
|
25
|
-
├─zcan.env
|
26
|
-
└─library
|
27
|
-
├─linux
|
28
|
-
│ └─x86_64
|
29
|
-
├─windows
|
30
|
-
│ ├─x86
|
12
|
+
library
|
13
|
+
├──bitrate.cfg.yaml
|
14
|
+
├──linux
|
31
15
|
│ └─x86_64
|
32
|
-
└─
|
16
|
+
└─windows
|
17
|
+
└─x86_64
|
18
|
+
```
|
19
|
+
* 在初始化can.Bus的时候指定zlgcan库路径(从0.2.0开始移除`zcan.env`配置), 默认为相对工程运行文件同级目录下`library`
|
20
|
+
```python
|
21
|
+
libpath=r"C:\your\library\path"
|
33
22
|
```
|
34
|
-
* 以下为`zcan.env`文件内容示例
|
35
|
-
```shell
|
36
|
-
ZCAN_LIBRARY="C:/your_library_path"
|
37
|
-
```
|
38
23
|
|
39
|
-
2. 安装zlgcan
|
24
|
+
2. 安装zlgcan(不建议使用低于0.2.0版本)
|
40
25
|
|
41
26
|
```shell
|
42
|
-
pip install zlgcan >= 0.
|
27
|
+
pip install zlgcan >= 0.2.0
|
28
|
+
```
|
43
29
|
|
44
30
|
3. 使用:
|
45
31
|
```python
|
@@ -47,6 +33,7 @@
|
|
47
33
|
from zlgcan.zlgcan import ZCanTxMode, ZCANDeviceType
|
48
34
|
|
49
35
|
with can.Bus(interface="zlgcan", device_type=ZCANDeviceType.ZCAN_USBCANFD_200U,
|
36
|
+
libpath="library/",
|
50
37
|
configs=[{'bitrate': 500000, 'resistance': 1}, {'bitrate': 500000, 'resistance': 1}]) as bus:
|
51
38
|
bus.send(can.Message(
|
52
39
|
arbitration_id=0x123,
|
@@ -59,6 +46,7 @@
|
|
59
46
|
# time.sleep(0.1)
|
60
47
|
_msg = bus.recv()
|
61
48
|
print(_msg)
|
49
|
+
```
|
62
50
|
|
63
51
|
4. CAN测试列表:
|
64
52
|
* USBCAN-I-mini - ZCAN_USBCAN1, ZCAN_USBCAN2
|
@@ -3,12 +3,7 @@ pub(crate) mod wrappers;
|
|
3
3
|
use std::sync::{Arc, Mutex};
|
4
4
|
use pyo3::{exceptions, prelude::*};
|
5
5
|
use rs_can::{CanError, CanFrame, CanType, ChannelConfig, DeviceBuilder};
|
6
|
-
use
|
7
|
-
can::{CanMessage, ZCanFrameType},
|
8
|
-
device::DeriveInfo,
|
9
|
-
driver::{ZCanDriver, ZDevice},
|
10
|
-
ACC_CODE, ACC_MASK, BRP, CHANNEL_MODE, CHANNEL_TYPE, DERIVE_INFO, DEVICE_INDEX, DEVICE_TYPE, FILTER_TYPE
|
11
|
-
};
|
6
|
+
use zlgcan::{*, can::*, device::*, driver::*};
|
12
7
|
use crate::wrappers::{ZCanChlCfgPy, ZCanDriverWrap, ZCanMessagePy, ZDeriveInfoPy};
|
13
8
|
|
14
9
|
#[pyfunction]
|
@@ -24,22 +19,31 @@ fn convert_from_python<'py>(py: Python<'py>, py_message: &Bound<'py, PyAny>) ->
|
|
24
19
|
|
25
20
|
#[pyfunction]
|
26
21
|
fn zlgcan_init_can(
|
22
|
+
libpath: String,
|
27
23
|
dev_type: u32,
|
28
24
|
dev_idx: u32,
|
29
25
|
cfgs: Vec<ZCanChlCfgPy>,
|
30
26
|
derive_info: Option<ZDeriveInfoPy>,
|
31
27
|
) -> PyResult<ZCanDriverWrap> {
|
28
|
+
let dev_type = ZCanDeviceType::try_from(dev_type)
|
29
|
+
.map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
|
32
30
|
let mut builder = DeviceBuilder::new();
|
33
|
-
builder
|
31
|
+
builder
|
32
|
+
.add_other(LIBPATH, Box::new(libpath))
|
33
|
+
.add_other(DEVICE_TYPE, Box::new(dev_type))
|
34
34
|
.add_other(DEVICE_INDEX, Box::new(dev_idx));
|
35
35
|
derive_info.map(
|
36
36
|
|info| builder.add_other(DERIVE_INFO, Box::<DeriveInfo>::new(info.into()))
|
37
37
|
);
|
38
38
|
|
39
39
|
for (i, cfg) in cfgs.into_iter().enumerate() {
|
40
|
+
let chl_type = ZCanChlType::try_from(cfg.chl_type)
|
41
|
+
.map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
|
42
|
+
let chl_mode = ZCanChlMode::try_from(cfg.chl_mode)
|
43
|
+
.map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
|
40
44
|
let mut c = ChannelConfig::new(cfg.bitrate);
|
41
|
-
c.add_other(CHANNEL_TYPE, Box::new(
|
42
|
-
.add_other(CHANNEL_MODE, Box::new(
|
45
|
+
c.add_other(CHANNEL_TYPE, Box::new(chl_type))
|
46
|
+
.add_other(CHANNEL_MODE, Box::new(chl_mode));
|
43
47
|
|
44
48
|
cfg.dbitrate.map(|dbitrate| c.set_data_bitrate(dbitrate));
|
45
49
|
cfg.resistance.map(|resistance| c.set_resistance(resistance));
|
@@ -48,10 +52,10 @@ fn zlgcan_init_can(
|
|
48
52
|
cfg.acc_mask.map(|acc_mask| c.add_other(ACC_MASK, Box::new(acc_mask)));
|
49
53
|
cfg.brp.map(|brp| c.add_other(BRP, Box::new(brp)));
|
50
54
|
|
51
|
-
builder.add_config(i
|
55
|
+
builder.add_config(i as u8, c);
|
52
56
|
}
|
53
57
|
|
54
|
-
let device
|
58
|
+
let device = builder.build::<ZDriver>()
|
55
59
|
.map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
|
56
60
|
|
57
61
|
Ok(ZCanDriverWrap { inner: Arc::new(Mutex::new(device)) })
|
@@ -168,7 +172,7 @@ fn zlgcan_driver(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
168
172
|
#[cfg(test)]
|
169
173
|
mod tests {
|
170
174
|
use std::time::Instant;
|
171
|
-
use
|
175
|
+
use zlgcan::{
|
172
176
|
can::{ZCanChlMode, ZCanChlType},
|
173
177
|
device::ZCanDeviceType,
|
174
178
|
};
|
@@ -192,7 +196,7 @@ mod tests {
|
|
192
196
|
None,
|
193
197
|
);
|
194
198
|
|
195
|
-
let device = zlgcan_init_can(dev_type, dev_idx, vec![cfg, ], None)?;
|
199
|
+
let device = zlgcan_init_can("../../RustProjects/rust-can/zlgcan/library".into(), dev_type, dev_idx, vec![cfg, ], None)?;
|
196
200
|
let dev_info = zlgcan_device_info(&device)?;
|
197
201
|
println!("{}", dev_info);
|
198
202
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
@@ -201,8 +205,8 @@ mod tests {
|
|
201
205
|
let mut flag = false;
|
202
206
|
while start.elapsed().as_secs() < 15 {
|
203
207
|
let msgs = zlgcan_recv(&device, 0, None)?;
|
204
|
-
println!("{:?}", msgs);
|
205
208
|
if !msgs.is_empty() {
|
209
|
+
println!("{:?}", msgs);
|
206
210
|
flag = true;
|
207
211
|
}
|
208
212
|
drop(msgs);
|
@@ -4,10 +4,10 @@ use constants::*;
|
|
4
4
|
use std::sync::{Arc, Mutex};
|
5
5
|
use pyo3::{exceptions, prelude::*, types::PyDict};
|
6
6
|
use rs_can::{CanDirect, CanFrame, CanId, CanType};
|
7
|
-
use
|
8
|
-
can::CanMessage,
|
7
|
+
use zlgcan::{
|
8
|
+
can::{CanMessage, ZCanTxMode},
|
9
9
|
device::DeriveInfo,
|
10
|
-
driver::
|
10
|
+
driver::ZDriver
|
11
11
|
};
|
12
12
|
|
13
13
|
#[pyclass]
|
@@ -27,14 +27,14 @@ impl ZDeriveInfoPy {
|
|
27
27
|
|
28
28
|
impl Into<DeriveInfo> for ZDeriveInfoPy {
|
29
29
|
fn into(self) -> DeriveInfo {
|
30
|
-
DeriveInfo
|
30
|
+
DeriveInfo { canfd: self.canfd, channels: self.channels }
|
31
31
|
}
|
32
32
|
}
|
33
33
|
|
34
34
|
#[pyclass]
|
35
35
|
#[derive(Clone)]
|
36
36
|
pub struct ZCanDriverWrap {
|
37
|
-
pub(crate) inner: Arc<Mutex<
|
37
|
+
pub(crate) inner: Arc<Mutex<ZDriver>>,
|
38
38
|
}
|
39
39
|
|
40
40
|
#[pyclass]
|
@@ -135,7 +135,7 @@ impl TryInto<CanMessage> for ZCanMessagePy {
|
|
135
135
|
msg.set_timestamp(None)
|
136
136
|
.set_direct(if self.is_rx { CanDirect::Receive } else { CanDirect::Transmit })
|
137
137
|
.set_channel(self.channel)
|
138
|
-
.set_tx_mode(self.tx_mode)
|
138
|
+
.set_tx_mode(ZCanTxMode::try_from(self.tx_mode).map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?)
|
139
139
|
.set_can_type(if self.is_fd { CanType::CanFd } else { CanType::Can })
|
140
140
|
.set_bitrate_switch(self.bitrate_switch)
|
141
141
|
.set_esi(self.error_state_indicator)
|
@@ -131,6 +131,7 @@ class ZCanBus(can.BusABC):
|
|
131
131
|
|
132
132
|
def __init__(self,
|
133
133
|
channel: Union[int, Sequence[int], str] = None, *,
|
134
|
+
libpath: str = "library/",
|
134
135
|
device_type: int,
|
135
136
|
device_index: int = 0,
|
136
137
|
derive: ZDeriveInfoPy = None,
|
@@ -142,6 +143,7 @@ class ZCanBus(can.BusABC):
|
|
142
143
|
Constructor
|
143
144
|
|
144
145
|
:param channel: Not used(from super).
|
146
|
+
:param libpath: The library root path.
|
145
147
|
:param device_type: The device type that your device belongs, see `ZCANDeviceType`.
|
146
148
|
:param device_index: The device index.
|
147
149
|
:param derive: The deriver info for specifying the channels and canfd supported if your device is not official.
|
@@ -180,7 +182,7 @@ class ZCanBus(can.BusABC):
|
|
180
182
|
cfg_list.append(_cfg)
|
181
183
|
self.channels.append(idx)
|
182
184
|
|
183
|
-
self.device = zlgcan_init_can(device_type, device_index, cfg_list, derive)
|
185
|
+
self.device = zlgcan_init_can(libpath, device_type, device_index, cfg_list, derive)
|
184
186
|
|
185
187
|
self.dev_info = zlgcan_device_info(self.device)
|
186
188
|
if self.dev_info is not None:
|
@@ -235,7 +237,9 @@ class ZCanBus(can.BusABC):
|
|
235
237
|
|
236
238
|
|
237
239
|
if __name__ == '__main__':
|
238
|
-
with ZCanBus(interface="zlgcan",
|
240
|
+
with ZCanBus(interface="zlgcan",
|
241
|
+
libpath="../../../RustProjects/rust-can/zlgcan/library",
|
242
|
+
device_type=ZCANDeviceType.ZCAN_USBCANFD_200U,
|
239
243
|
configs=[{'bitrate': 500000, 'dbitrate': 1_000_000, 'resistance': 1}]) as bus:
|
240
244
|
# bus.send(can.Message(
|
241
245
|
# arbitration_id=0x7DF,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|