feat: add EskinDeviceFunc FFI bindings and update Python/README
- Add FFI wrappers for all EskinDeviceFunc trait methods: eskin_read_hdw_version, eskin_read_matrix_row/col, eskin_read_device_config1/2, eskin_write_device_config1/2, eskin_write_matrix_row/col - Extract sdk_error_to_code() helper for SdkError -> SdkErrorCode conversion - Update C header (include/eskin_ffi.h) with new function declarations - Update Python FFI bindings (example/python/eskin_ffi.py) with new methods - Update README with Python usage instructions and full FFI interface table
This commit is contained in:
25
README.md
25
README.md
@@ -98,18 +98,30 @@ int main() {
|
||||
|
||||
## 使用 Python
|
||||
|
||||
### 构建 & 准备
|
||||
|
||||
```bash
|
||||
cargo build --release
|
||||
# 将生成的 .so 文件复制到 python 示例目录下
|
||||
cp target/release/libeskin_finger_sdk.so example/python/
|
||||
cd example/python
|
||||
LD_LIBRARY_PATH=../../target/release python3 example.py
|
||||
python3 example.py
|
||||
```
|
||||
|
||||
> **注意:** Python 示例默认从当前目录加载 `libeskin_finger_sdk.so`,请确保 `.so` 文件已复制到 `example/python/` 目录下,或修改 `example.py` 中的 `LIB_PATH` 指向正确的路径。
|
||||
|
||||
```python
|
||||
from eskin_ffi import EskinDevice
|
||||
|
||||
with EskinDevice("target/release/libeskin_finger_sdk.so") as dev:
|
||||
with EskinDevice("libeskin_finger_sdk.so") as dev:
|
||||
dev.open("/dev/ttyUSB0")
|
||||
|
||||
# 读取硬件版本
|
||||
print(f"Hardware version: {dev.read_hdw_version()}")
|
||||
|
||||
# 读取矩阵尺寸
|
||||
print(f"Matrix: {dev.read_matrix_row()} x {dev.read_matrix_col()}")
|
||||
|
||||
# 读寄存器
|
||||
data = dev.read_register(0x0000, 4)
|
||||
print(f"Serial: {data.hex()}")
|
||||
@@ -129,6 +141,15 @@ with EskinDevice("target/release/libeskin_finger_sdk.so") as dev:
|
||||
| `eskin_close(handle)` | 关闭设备,释放 handle |
|
||||
| `eskin_read_register(handle, addr, length, buf, buf_len, actual_len)` | 读寄存器原始字节 |
|
||||
| `eskin_write_register(handle, addr, data, data_len, return_count)` | 写寄存器原始字节 |
|
||||
| `eskin_read_hdw_version(handle, buf, buf_len, actual_len)` | 读取硬件版本号 |
|
||||
| `eskin_read_matrix_row(handle, out)` | 读取矩阵行数 |
|
||||
| `eskin_read_matrix_col(handle, out)` | 读取矩阵列数 |
|
||||
| `eskin_read_device_config1(handle, out)` | 读取设备配置寄存器1 |
|
||||
| `eskin_read_device_config2(handle, out)` | 读取设备配置寄存器2 |
|
||||
| `eskin_write_device_config1(handle, enable, return_count)` | 写入设备配置寄存器1 |
|
||||
| `eskin_write_device_config2(handle, enable, return_count)` | 写入设备配置寄存器2 |
|
||||
| `eskin_write_matrix_row(handle, row, return_count)` | 写入矩阵行数 |
|
||||
| `eskin_write_matrix_col(handle, col, return_count)` | 写入矩阵列数 |
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user