zlgcan 0.1.15__tar.gz → 0.1.17__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/.editorconfig +7 -0
- {zlgcan-0.1.15 → zlgcan-0.1.17}/Cargo.lock +32 -19
- {zlgcan-0.1.15 → zlgcan-0.1.17}/Cargo.toml +3 -3
- {zlgcan-0.1.15 → zlgcan-0.1.17}/PKG-INFO +5 -2
- {zlgcan-0.1.15 → zlgcan-0.1.17}/README.md +3 -0
- {zlgcan-0.1.15 → zlgcan-0.1.17}/pyproject.toml +1 -1
- {zlgcan-0.1.15 → zlgcan-0.1.17}/src/lib.rs +41 -50
- {zlgcan-0.1.15 → zlgcan-0.1.17}/src/wrappers/mod.rs +11 -39
- {zlgcan-0.1.15 → zlgcan-0.1.17}/zlgcan/zlgcan.py +8 -12
- {zlgcan-0.1.15 → zlgcan-0.1.17}/.github/workflows/CI.yml +0 -0
- {zlgcan-0.1.15 → zlgcan-0.1.17}/.github/workflows/label-check.yml +0 -0
- {zlgcan-0.1.15 → zlgcan-0.1.17}/.gitignore +0 -0
- {zlgcan-0.1.15 → zlgcan-0.1.17}/LICENSE.txt +0 -0
- {zlgcan-0.1.15 → zlgcan-0.1.17}/requirements.txt +0 -0
- {zlgcan-0.1.15 → zlgcan-0.1.17}/src/wrappers/constants.rs +0 -0
- {zlgcan-0.1.15 → zlgcan-0.1.17}/zlgcan/__init__.py +0 -0
@@ -26,6 +26,17 @@ version = "1.0.0"
|
|
26
26
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
27
27
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
28
28
|
|
29
|
+
[[package]]
|
30
|
+
name = "derive-getters"
|
31
|
+
version = "0.5.0"
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
33
|
+
checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff"
|
34
|
+
dependencies = [
|
35
|
+
"proc-macro2",
|
36
|
+
"quote",
|
37
|
+
"syn",
|
38
|
+
]
|
39
|
+
|
29
40
|
[[package]]
|
30
41
|
name = "dlopen2"
|
31
42
|
version = "0.7.0"
|
@@ -103,9 +114,9 @@ checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
|
|
103
114
|
|
104
115
|
[[package]]
|
105
116
|
name = "log"
|
106
|
-
version = "0.4.
|
117
|
+
version = "0.4.27"
|
107
118
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
108
|
-
checksum = "
|
119
|
+
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
109
120
|
|
110
121
|
[[package]]
|
111
122
|
name = "memoffset"
|
@@ -118,9 +129,9 @@ dependencies = [
|
|
118
129
|
|
119
130
|
[[package]]
|
120
131
|
name = "once_cell"
|
121
|
-
version = "1.21.
|
132
|
+
version = "1.21.3"
|
122
133
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
123
|
-
checksum = "
|
134
|
+
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
124
135
|
|
125
136
|
[[package]]
|
126
137
|
name = "portable-atomic"
|
@@ -139,9 +150,9 @@ dependencies = [
|
|
139
150
|
|
140
151
|
[[package]]
|
141
152
|
name = "pyo3"
|
142
|
-
version = "0.24.
|
153
|
+
version = "0.24.1"
|
143
154
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
144
|
-
checksum = "
|
155
|
+
checksum = "17da310086b068fbdcefbba30aeb3721d5bb9af8db4987d6735b2183ca567229"
|
145
156
|
dependencies = [
|
146
157
|
"cfg-if",
|
147
158
|
"indoc",
|
@@ -157,9 +168,9 @@ dependencies = [
|
|
157
168
|
|
158
169
|
[[package]]
|
159
170
|
name = "pyo3-build-config"
|
160
|
-
version = "0.24.
|
171
|
+
version = "0.24.1"
|
161
172
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
162
|
-
checksum = "
|
173
|
+
checksum = "e27165889bd793000a098bb966adc4300c312497ea25cf7a690a9f0ac5aa5fc1"
|
163
174
|
dependencies = [
|
164
175
|
"once_cell",
|
165
176
|
"target-lexicon",
|
@@ -167,9 +178,9 @@ dependencies = [
|
|
167
178
|
|
168
179
|
[[package]]
|
169
180
|
name = "pyo3-ffi"
|
170
|
-
version = "0.24.
|
181
|
+
version = "0.24.1"
|
171
182
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
172
|
-
checksum = "
|
183
|
+
checksum = "05280526e1dbf6b420062f3ef228b78c0c54ba94e157f5cb724a609d0f2faabc"
|
173
184
|
dependencies = [
|
174
185
|
"libc",
|
175
186
|
"pyo3-build-config",
|
@@ -177,9 +188,9 @@ dependencies = [
|
|
177
188
|
|
178
189
|
[[package]]
|
179
190
|
name = "pyo3-macros"
|
180
|
-
version = "0.24.
|
191
|
+
version = "0.24.1"
|
181
192
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
182
|
-
checksum = "
|
193
|
+
checksum = "5c3ce5686aa4d3f63359a5100c62a127c9f15e8398e5fdeb5deef1fed5cd5f44"
|
183
194
|
dependencies = [
|
184
195
|
"proc-macro2",
|
185
196
|
"pyo3-macros-backend",
|
@@ -189,9 +200,9 @@ dependencies = [
|
|
189
200
|
|
190
201
|
[[package]]
|
191
202
|
name = "pyo3-macros-backend"
|
192
|
-
version = "0.24.
|
203
|
+
version = "0.24.1"
|
193
204
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
194
|
-
checksum = "
|
205
|
+
checksum = "f4cf6faa0cbfb0ed08e89beb8103ae9724eb4750e3a78084ba4017cbe94f3855"
|
195
206
|
dependencies = [
|
196
207
|
"heck",
|
197
208
|
"proc-macro2",
|
@@ -211,12 +222,14 @@ dependencies = [
|
|
211
222
|
|
212
223
|
[[package]]
|
213
224
|
name = "rs-can"
|
214
|
-
version = "0.2.0
|
225
|
+
version = "0.2.0"
|
215
226
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
216
|
-
checksum = "
|
227
|
+
checksum = "4416620ec3f2141f73b5d0936481c9caf3aa27ba140e2a97f178b80b7f110f68"
|
217
228
|
dependencies = [
|
218
229
|
"bitflags",
|
230
|
+
"derive-getters",
|
219
231
|
"log",
|
232
|
+
"serde",
|
220
233
|
"thiserror",
|
221
234
|
]
|
222
235
|
|
@@ -338,9 +351,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
338
351
|
|
339
352
|
[[package]]
|
340
353
|
name = "zlgcan"
|
341
|
-
version = "0.2.0
|
354
|
+
version = "0.2.0"
|
342
355
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
343
|
-
checksum = "
|
356
|
+
checksum = "ad37441e238647c26ae9521b03bfb3abf3dbd37c74ac4f47219a624781b71f7a"
|
344
357
|
dependencies = [
|
345
358
|
"dlopen2",
|
346
359
|
"dotenvy",
|
@@ -352,7 +365,7 @@ dependencies = [
|
|
352
365
|
|
353
366
|
[[package]]
|
354
367
|
name = "zlgcan-driver"
|
355
|
-
version = "0.1.
|
368
|
+
version = "0.1.17"
|
356
369
|
dependencies = [
|
357
370
|
"anyhow",
|
358
371
|
"pyo3",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[package]
|
2
2
|
name = "zlgcan-driver"
|
3
|
-
version = "0.1.
|
3
|
+
version = "0.1.17"
|
4
4
|
edition = "2021"
|
5
5
|
|
6
6
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
@@ -13,8 +13,8 @@ pyo3 = "0.24"
|
|
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 = { version = "0.2.0
|
17
|
-
zlgcan = { version = "0.2.0
|
16
|
+
rs-can = { version = "0.2.0" }
|
17
|
+
zlgcan = { version = "0.2.0" }
|
18
18
|
|
19
19
|
[dev-dependencies]
|
20
20
|
anyhow = "1"
|
@@ -1,19 +1,22 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: zlgcan
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.17
|
4
4
|
Classifier: Programming Language :: Rust
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
7
7
|
Requires-Dist: python-can
|
8
8
|
License-File: LICENSE.txt
|
9
9
|
Summary: Python wrapper for zlgcan driver.
|
10
|
-
Author: Smith
|
10
|
+
Author: Jesse Smith
|
11
11
|
License: LGPL v3
|
12
12
|
Requires-Python: >=3.8
|
13
13
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
14
14
|
Project-URL: homepage, https://github.com/zhuyu4839/zlgcan-driver
|
15
15
|
Project-URL: repository, https://github.com/zhuyu4839/zlgcan-driver
|
16
16
|
|
17
|
+

|
18
|
+

|
19
|
+
|
17
20
|
# ZLGCAN驱动及集成到python-can(因内存模型不同,目前Windows下32位python会报内存非法访问的错误)
|
18
21
|
|
19
22
|
1. 准备
|
@@ -2,12 +2,14 @@ pub(crate) mod wrappers;
|
|
2
2
|
|
3
3
|
use std::sync::{Arc, Mutex};
|
4
4
|
use pyo3::{exceptions, prelude::*};
|
5
|
-
use rs_can::{CanError, CanFrame, CanType};
|
5
|
+
use rs_can::{CanError, CanFrame, CanType, ChannelConfig, DeviceBuilder};
|
6
6
|
use zlgcan_rs::{
|
7
|
-
can::{
|
8
|
-
|
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
|
9
11
|
};
|
10
|
-
use crate::wrappers::{
|
12
|
+
use crate::wrappers::{ZCanChlCfgPy, ZCanDriverWrap, ZCanMessagePy, ZDeriveInfoPy};
|
11
13
|
|
12
14
|
#[pyfunction]
|
13
15
|
fn convert_to_python<'py>(py: Python<'py>, rust_message: ZCanMessagePy) -> PyResult<Bound<'py, PyAny>> {
|
@@ -21,26 +23,35 @@ fn convert_from_python<'py>(py: Python<'py>, py_message: &Bound<'py, PyAny>) ->
|
|
21
23
|
}
|
22
24
|
|
23
25
|
#[pyfunction]
|
24
|
-
fn
|
25
|
-
let factory = CanChlCfgFactory::new()
|
26
|
-
.map_err(|e| PyErr::new::<exceptions::PyRuntimeError, String>(e.to_string()))?;
|
27
|
-
Ok(ZCanChlCfgFactoryWrap { inner: Arc::new(factory) })
|
28
|
-
}
|
29
|
-
|
30
|
-
#[pyfunction]
|
31
|
-
#[pyo3(signature = (dev_type, dev_idx, derive=None))]
|
32
|
-
fn zlgcan_open(
|
26
|
+
fn zlgcan_init_can(
|
33
27
|
dev_type: u32,
|
34
28
|
dev_idx: u32,
|
35
|
-
|
29
|
+
cfgs: Vec<ZCanChlCfgPy>,
|
30
|
+
derive_info: Option<ZDeriveInfoPy>,
|
36
31
|
) -> PyResult<ZCanDriverWrap> {
|
37
|
-
let
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
let mut builder = DeviceBuilder::new();
|
33
|
+
builder.add_other(DEVICE_TYPE, Box::new(dev_type))
|
34
|
+
.add_other(DEVICE_INDEX, Box::new(dev_idx));
|
35
|
+
derive_info.map(
|
36
|
+
|info| builder.add_other(DERIVE_INFO, Box::<DeriveInfo>::new(info.into()))
|
37
|
+
);
|
38
|
+
|
39
|
+
for (i, cfg) in cfgs.into_iter().enumerate() {
|
40
|
+
let mut c = ChannelConfig::new(cfg.bitrate);
|
41
|
+
c.add_other(CHANNEL_TYPE, Box::new(cfg.chl_type))
|
42
|
+
.add_other(CHANNEL_MODE, Box::new(cfg.chl_mode));
|
43
|
+
|
44
|
+
cfg.dbitrate.map(|dbitrate| c.set_data_bitrate(dbitrate));
|
45
|
+
cfg.resistance.map(|resistance| c.set_resistance(resistance));
|
46
|
+
cfg.filter.map(|filter| c.add_other(FILTER_TYPE, Box::new(filter)));
|
47
|
+
cfg.acc_code.map(|acc_code| c.add_other(ACC_CODE, Box::new(acc_code)));
|
48
|
+
cfg.acc_mask.map(|acc_mask| c.add_other(ACC_MASK, Box::new(acc_mask)));
|
49
|
+
cfg.brp.map(|brp| c.add_other(BRP, Box::new(brp)));
|
50
|
+
|
51
|
+
builder.add_config(i.to_string(), c);
|
52
|
+
}
|
53
|
+
|
54
|
+
let device: ZCanDriver = builder.build()
|
44
55
|
.map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
|
45
56
|
|
46
57
|
Ok(ZCanDriverWrap { inner: Arc::new(Mutex::new(device)) })
|
@@ -57,22 +68,6 @@ fn zlgcan_device_info(device: &ZCanDriverWrap) -> PyResult<String> {
|
|
57
68
|
)
|
58
69
|
}
|
59
70
|
|
60
|
-
#[pyfunction]
|
61
|
-
fn zlgcan_init_can(
|
62
|
-
device: &ZCanDriverWrap,
|
63
|
-
factory: ZCanChlCfgFactoryWrap,
|
64
|
-
cfg: Vec<ZCanChlCfgPy>
|
65
|
-
) -> PyResult<()> {
|
66
|
-
let mut device = device.inner.lock()
|
67
|
-
.map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
|
68
|
-
let cfg = cfg.into_iter()
|
69
|
-
.map(|c| c.try_convert(&factory))
|
70
|
-
.collect::<Result<Vec<_>, _>>()
|
71
|
-
.map_err(|e| e)?;
|
72
|
-
device.init_can_chl(cfg)
|
73
|
-
.map_err(|e| exceptions::PyValueError::new_err(e.to_string()))
|
74
|
-
}
|
75
|
-
|
76
71
|
#[pyfunction]
|
77
72
|
fn zlgcan_clear_can_buffer(
|
78
73
|
device: &ZCanDriverWrap,
|
@@ -148,22 +143,20 @@ fn set_message_mode(msg: &mut ZCanMessagePy, mode: u8) {
|
|
148
143
|
msg.tx_mode = mode;
|
149
144
|
}
|
150
145
|
|
146
|
+
// 此方法名必须与Cargo.toml-[lib]配置下name保持一致
|
151
147
|
#[pymodule]
|
152
|
-
fn
|
148
|
+
fn zlgcan_driver(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
153
149
|
m.add_class::<ZCanChlCfgPy>()?;
|
154
150
|
m.add_class::<ZCanMessagePy>()?;
|
155
151
|
m.add_class::<ZDeriveInfoPy>()?;
|
156
|
-
m.add_class::<ZCanChlCfgFactoryWrap>()?;
|
157
152
|
m.add_class::<ZCanDriverWrap>()?;
|
158
153
|
|
159
154
|
m.add_function(wrap_pyfunction!(convert_to_python, m)?)?;
|
160
155
|
m.add_function(wrap_pyfunction!(convert_from_python, m)?)?;
|
161
156
|
m.add_function(wrap_pyfunction!(set_message_mode, m)?)?;
|
162
157
|
|
163
|
-
m.add_function(wrap_pyfunction!(zlgcan_cfg_factory_can, m)?)?;
|
164
|
-
m.add_function(wrap_pyfunction!(zlgcan_open, m)?)?;
|
165
|
-
m.add_function(wrap_pyfunction!(zlgcan_device_info, m)?)?;
|
166
158
|
m.add_function(wrap_pyfunction!(zlgcan_init_can, m)?)?;
|
159
|
+
m.add_function(wrap_pyfunction!(zlgcan_device_info, m)?)?;
|
167
160
|
m.add_function(wrap_pyfunction!(zlgcan_clear_can_buffer, m)?)?;
|
168
161
|
m.add_function(wrap_pyfunction!(zlgcan_send, m)?)?;
|
169
162
|
m.add_function(wrap_pyfunction!(zlgcan_recv, m)?)?;
|
@@ -185,14 +178,9 @@ mod tests {
|
|
185
178
|
fn test_receive() -> anyhow::Result<()> {
|
186
179
|
pyo3::prepare_freethreaded_python();
|
187
180
|
|
188
|
-
let
|
189
|
-
let
|
190
|
-
|
191
|
-
let dev_info = zlgcan_device_info(&device)?;
|
192
|
-
println!("{}", dev_info);
|
193
|
-
|
181
|
+
let dev_type = ZCanDeviceType::ZCAN_USBCANFD_200U as u32;
|
182
|
+
let dev_idx = 0;
|
194
183
|
let cfg = ZCanChlCfgPy::new(
|
195
|
-
ZCanDeviceType::ZCAN_USBCANFD_200U as u32,
|
196
184
|
ZCanChlType::CANFD_ISO as u8,
|
197
185
|
ZCanChlMode::Normal as u8,
|
198
186
|
500_000,
|
@@ -203,7 +191,10 @@ mod tests {
|
|
203
191
|
None,
|
204
192
|
None,
|
205
193
|
);
|
206
|
-
|
194
|
+
|
195
|
+
let device = zlgcan_init_can(dev_type, dev_idx, vec![cfg, ], None)?;
|
196
|
+
let dev_info = zlgcan_device_info(&device)?;
|
197
|
+
println!("{}", dev_info);
|
207
198
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
208
199
|
|
209
200
|
let start = Instant::now();
|
@@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex};
|
|
5
5
|
use pyo3::{exceptions, prelude::*, types::PyDict};
|
6
6
|
use rs_can::{CanDirect, CanFrame, CanId, CanType};
|
7
7
|
use zlgcan_rs::{
|
8
|
-
can::
|
8
|
+
can::CanMessage,
|
9
9
|
device::DeriveInfo,
|
10
10
|
driver::ZCanDriver
|
11
11
|
};
|
@@ -31,12 +31,6 @@ impl Into<DeriveInfo> for ZDeriveInfoPy {
|
|
31
31
|
}
|
32
32
|
}
|
33
33
|
|
34
|
-
#[pyclass]
|
35
|
-
#[derive(Clone)]
|
36
|
-
pub struct ZCanChlCfgFactoryWrap {
|
37
|
-
pub(crate) inner: Arc<CanChlCfgFactory>
|
38
|
-
}
|
39
|
-
|
40
34
|
#[pyclass]
|
41
35
|
#[derive(Clone)]
|
42
36
|
pub struct ZCanDriverWrap {
|
@@ -46,24 +40,22 @@ pub struct ZCanDriverWrap {
|
|
46
40
|
#[pyclass]
|
47
41
|
#[derive(Clone)]
|
48
42
|
pub struct ZCanChlCfgPy {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
brp: Option<u32>,
|
43
|
+
pub(crate) chl_type: u8,
|
44
|
+
pub(crate) chl_mode: u8,
|
45
|
+
pub(crate) bitrate: u32,
|
46
|
+
pub(crate) filter: Option<u8>,
|
47
|
+
pub(crate) dbitrate: Option<u32>,
|
48
|
+
pub(crate) resistance: Option<bool>,
|
49
|
+
pub(crate) acc_code: Option<u32>,
|
50
|
+
pub(crate) acc_mask: Option<u32>,
|
51
|
+
pub(crate) brp: Option<u32>,
|
59
52
|
}
|
60
53
|
|
61
54
|
#[pymethods]
|
62
55
|
impl ZCanChlCfgPy {
|
63
56
|
#[new]
|
64
|
-
#[pyo3(signature = (
|
57
|
+
#[pyo3(signature = (chl_type, chl_mode, bitrate, filter=None, dbitrate=None, resistance=None, acc_code=None, acc_mask=None, brp=None))]
|
65
58
|
pub fn new(
|
66
|
-
dev_type: u32,
|
67
59
|
chl_type: u8,
|
68
60
|
chl_mode: u8,
|
69
61
|
bitrate: u32,
|
@@ -75,7 +67,6 @@ impl ZCanChlCfgPy {
|
|
75
67
|
brp: Option<u32>,
|
76
68
|
) -> Self {
|
77
69
|
ZCanChlCfgPy {
|
78
|
-
dev_type,
|
79
70
|
chl_type,
|
80
71
|
chl_mode,
|
81
72
|
bitrate,
|
@@ -89,25 +80,6 @@ impl ZCanChlCfgPy {
|
|
89
80
|
}
|
90
81
|
}
|
91
82
|
|
92
|
-
impl ZCanChlCfgPy {
|
93
|
-
pub fn try_convert(&self, factory: &ZCanChlCfgFactoryWrap) -> PyResult<CanChlCfg> {
|
94
|
-
factory.inner.new_can_chl_cfg(
|
95
|
-
self.dev_type,
|
96
|
-
self.chl_type,
|
97
|
-
self.chl_mode,
|
98
|
-
self.bitrate,
|
99
|
-
CanChlCfgExt::new(
|
100
|
-
self.filter,
|
101
|
-
self.dbitrate,
|
102
|
-
self.resistance,
|
103
|
-
self.acc_code,
|
104
|
-
self.acc_mask,
|
105
|
-
self.brp
|
106
|
-
)
|
107
|
-
).map_err(|e| exceptions::PyValueError::new_err(e.to_string()))
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
83
|
#[pyclass]
|
112
84
|
#[derive(Debug, Clone)]
|
113
85
|
pub struct ZCanMessagePy {
|
@@ -11,8 +11,8 @@ from can.bus import LOG
|
|
11
11
|
|
12
12
|
from typing import Optional, Union, Sequence, Deque, Tuple, List, Dict
|
13
13
|
try:
|
14
|
-
from
|
15
|
-
convert_to_python, convert_from_python, set_message_mode,
|
14
|
+
from zlgcan_driver import ZCanChlCfgPy, ZCanMessagePy, ZDeriveInfoPy, ZCanDriverWrap, \
|
15
|
+
convert_to_python, convert_from_python, set_message_mode, \
|
16
16
|
zlgcan_device_info, zlgcan_init_can, zlgcan_clear_can_buffer, zlgcan_send, zlgcan_recv, zlgcan_close
|
17
17
|
except ModuleNotFoundError:
|
18
18
|
import sys
|
@@ -20,7 +20,7 @@ except ModuleNotFoundError:
|
|
20
20
|
_system_bit, _ = platform.architecture()
|
21
21
|
_platform = sys.platform
|
22
22
|
not_support = CanError(f"The system {_platform}'.'{_system_bit} is not supported!")
|
23
|
-
require_lib = CanError("Please install library `zlgcan-driver
|
23
|
+
require_lib = CanError("Please install library `zlgcan-driver`!")
|
24
24
|
raise {
|
25
25
|
"win32": {"32bit": not_support}.get(_system_bit, require_lib),
|
26
26
|
"darwin": not_support,
|
@@ -161,20 +161,12 @@ class ZCanBus(can.BusABC):
|
|
161
161
|
) # type: Deque[can.Message] # channel, raw_msg
|
162
162
|
self.channels = []
|
163
163
|
|
164
|
-
factory = zlgcan_cfg_factory_can()
|
165
|
-
self.device = zlgcan_open(device_type, device_index, derive)
|
166
|
-
|
167
|
-
self.dev_info = zlgcan_device_info(self.device)
|
168
|
-
if self.dev_info is not None:
|
169
|
-
LOG.info(f"Device: {self.dev_info} has opened")
|
170
|
-
|
171
164
|
cfg_list = []
|
172
165
|
for idx, cfg in enumerate(configs):
|
173
166
|
bitrate = cfg.get("bitrate", None)
|
174
167
|
dbitrate = cfg.get("dbitrate", None)
|
175
168
|
assert bitrate is not None, "bitrate is required!"
|
176
169
|
_cfg = ZCanChlCfgPy(
|
177
|
-
dev_type=device_type,
|
178
170
|
chl_type=cfg.get("chl_type", ZCanChlType.CANFD_ISO if dbitrate else ZCanChlType.CAN),
|
179
171
|
chl_mode=cfg.get("chl_mode", 0),
|
180
172
|
bitrate=bitrate,
|
@@ -188,7 +180,11 @@ class ZCanBus(can.BusABC):
|
|
188
180
|
cfg_list.append(_cfg)
|
189
181
|
self.channels.append(idx)
|
190
182
|
|
191
|
-
|
183
|
+
self.device = zlgcan_init_can(device_type, device_index, cfg_list, derive)
|
184
|
+
|
185
|
+
self.dev_info = zlgcan_device_info(self.device)
|
186
|
+
if self.dev_info is not None:
|
187
|
+
LOG.info(f"Device: {self.dev_info} has opened")
|
192
188
|
except Exception as e:
|
193
189
|
self.shutdown()
|
194
190
|
raise e
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|