baltech-sdk 3.19.4__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.
- baltech_sdk-3.19.4/PKG-INFO +128 -0
- baltech_sdk-3.19.4/README.md +110 -0
- baltech_sdk-3.19.4/baltech_sdk/__init__.py +103 -0
- baltech_sdk-3.19.4/baltech_sdk/baltech_api/__init__.py +15924 -0
- baltech_sdk-3.19.4/baltech_sdk/baltech_api/baltech_script.py +782 -0
- baltech_sdk-3.19.4/baltech_sdk/baltech_api/commands.py +10546 -0
- baltech_sdk-3.19.4/baltech_sdk/baltech_api/common.py +133 -0
- baltech_sdk-3.19.4/baltech_sdk/baltech_api/configuration.py +58686 -0
- baltech_sdk-3.19.4/baltech_sdk/baltech_api/template.py +1257 -0
- baltech_sdk-3.19.4/baltech_sdk/baltech_api/typedefs.py +6111 -0
- baltech_sdk-3.19.4/baltech_sdk/brp_lib/__init__.py +0 -0
- baltech_sdk-3.19.4/baltech_sdk/brp_lib/brp_lib.win32.dll +0 -0
- baltech_sdk-3.19.4/baltech_sdk/brp_lib/brp_lib.win64.dll +0 -0
- baltech_sdk-3.19.4/baltech_sdk/brp_lib/dll_wrapper.py +195 -0
- baltech_sdk-3.19.4/baltech_sdk/brp_lib/protocols.py +232 -0
- baltech_sdk-3.19.4/baltech_sdk/errors.py +214 -0
- baltech_sdk-3.19.4/baltech_sdk/py.typed +0 -0
- baltech_sdk-3.19.4/pyproject.toml +26 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: baltech-sdk
|
|
3
|
+
Version: 3.19.4
|
|
4
|
+
Summary: SDK to communicate with Baltech RFID readers.
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Baltech AG
|
|
7
|
+
Author-email: info@baltech.de
|
|
8
|
+
Requires-Python: >=3.9,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Dist: typing-extensions
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# Baltech SDK
|
|
19
|
+
|
|
20
|
+
***Warning: While the underlying SDK is stable, the Python API is not stable yet, and future releases are not guaranteed to be backwards compatible. Pinning this project to a specific version in your dependency management is recommended.***
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
```bash
|
|
24
|
+
pip install baltech-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from baltech_sdk import Brp, UsbHid
|
|
31
|
+
|
|
32
|
+
# Sample code for GetInfo
|
|
33
|
+
with Brp(UsbHid()) as brp:
|
|
34
|
+
print(brp.Sys_GetInfo())
|
|
35
|
+
|
|
36
|
+
# This is a shortcut for:
|
|
37
|
+
io = UsbHid()
|
|
38
|
+
brp = Brp(io, open=False)
|
|
39
|
+
brp.open()
|
|
40
|
+
print(brp.Sys_GetInfo())
|
|
41
|
+
brp.close()
|
|
42
|
+
```
|
|
43
|
+
A complete reference of the supported commands can be found [here](https://docs.baltech.de/refman/cmds/index.html).
|
|
44
|
+
|
|
45
|
+
### Supported IO protocols
|
|
46
|
+
```python
|
|
47
|
+
from baltech_sdk import Brp, UsbHid, RS232, Tcp
|
|
48
|
+
|
|
49
|
+
# USB HID autodetect connected reader
|
|
50
|
+
brp = Brp(UsbHid())
|
|
51
|
+
|
|
52
|
+
# USB HID by serialnumber
|
|
53
|
+
brp = Brp(UsbHid(serialnumber=99999999))
|
|
54
|
+
|
|
55
|
+
# Serial with (optional) custom settings
|
|
56
|
+
brp = Brp(RS232("COM1", baudrate=115200, parity=b"N"))
|
|
57
|
+
|
|
58
|
+
# TCP by ip address
|
|
59
|
+
brp = Brp(Tcp(ipaddr="192.168.0.1"))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Access Reader Configuration
|
|
63
|
+
```python
|
|
64
|
+
from baltech_sdk import Config
|
|
65
|
+
|
|
66
|
+
cfg_src = {(0x0201, 0x02): b'\x01'} # instead of a confDict also a brp object
|
|
67
|
+
# can be passed to modify reader's
|
|
68
|
+
# configuration directly
|
|
69
|
+
cfg = Config(cfg_src)
|
|
70
|
+
|
|
71
|
+
# set value
|
|
72
|
+
cfg.Device_Boot_StartAutoreadAtPowerup("EnableOnce")
|
|
73
|
+
|
|
74
|
+
# get value
|
|
75
|
+
print(cfg.Device_Boot_StartAutoreadAtPowerup.get())
|
|
76
|
+
|
|
77
|
+
# delete value
|
|
78
|
+
cfg.Device_Boot_StartAutoreadAtPowerup.delete()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Templates and BaltechScripts
|
|
82
|
+
```python
|
|
83
|
+
from baltech_sdk import Config, Template, BaltechScript, TemplateFilter
|
|
84
|
+
|
|
85
|
+
confdict = {}
|
|
86
|
+
cfg = Config(confdict)
|
|
87
|
+
|
|
88
|
+
cfg.Scripts_Events_OnAccepted(
|
|
89
|
+
BaltechScript()
|
|
90
|
+
.ToggleInverted("RedLed", RepeatCount=3, Delay=20)
|
|
91
|
+
.Toggle("GreenLed", RepeatCount=1, Delay=20)
|
|
92
|
+
.DefaultAction()
|
|
93
|
+
)
|
|
94
|
+
cfg.Autoread_Rule_Template(
|
|
95
|
+
0,
|
|
96
|
+
Template()
|
|
97
|
+
.Static(b"SNR:")
|
|
98
|
+
.Serialnr(TemplateFilter(BinToAscii=True, Unpack=True, BinToBcd=True))
|
|
99
|
+
)
|
|
100
|
+
print(confdict)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Linux or macOS
|
|
104
|
+
To use ``baltech-sdk`` under Linux or macOS you need to build your own binary of the [BaltechSDK](https://docs.baltech.de/developers/sdk.html) and manually set the path to your binary.
|
|
105
|
+
```python
|
|
106
|
+
from pathlib import Path
|
|
107
|
+
from baltech_sdk import set_brp_lib_path
|
|
108
|
+
|
|
109
|
+
set_brp_lib_path(Path("path/to/brp_lib"))
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### Further parameters on connections fors sensible data
|
|
114
|
+
|
|
115
|
+
Additional Options:
|
|
116
|
+
* [AES based Encryption](https://docs.baltech.de/developers/add-aes-auth-and-encryption.html) can be activated
|
|
117
|
+
* [Enabled monitoring](https://docs.baltech.de/developers/analyze-communication.html#enable-monitoring) can be suppressed or extended to plaintext
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from baltech_sdk import Brp, UsbHid, SecureChannel
|
|
121
|
+
|
|
122
|
+
KEY = b'abcdefghijklmnuk'
|
|
123
|
+
brp = Brp(UsbHid(),
|
|
124
|
+
crypto=SecureChannel(security_level=1, key=KEY), # encrypt communication
|
|
125
|
+
monitor="plaintext" # log unencrypted data (if activated by user)
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Baltech SDK
|
|
2
|
+
|
|
3
|
+
***Warning: While the underlying SDK is stable, the Python API is not stable yet, and future releases are not guaranteed to be backwards compatible. Pinning this project to a specific version in your dependency management is recommended.***
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
```bash
|
|
7
|
+
pip install baltech-sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from baltech_sdk import Brp, UsbHid
|
|
14
|
+
|
|
15
|
+
# Sample code for GetInfo
|
|
16
|
+
with Brp(UsbHid()) as brp:
|
|
17
|
+
print(brp.Sys_GetInfo())
|
|
18
|
+
|
|
19
|
+
# This is a shortcut for:
|
|
20
|
+
io = UsbHid()
|
|
21
|
+
brp = Brp(io, open=False)
|
|
22
|
+
brp.open()
|
|
23
|
+
print(brp.Sys_GetInfo())
|
|
24
|
+
brp.close()
|
|
25
|
+
```
|
|
26
|
+
A complete reference of the supported commands can be found [here](https://docs.baltech.de/refman/cmds/index.html).
|
|
27
|
+
|
|
28
|
+
### Supported IO protocols
|
|
29
|
+
```python
|
|
30
|
+
from baltech_sdk import Brp, UsbHid, RS232, Tcp
|
|
31
|
+
|
|
32
|
+
# USB HID autodetect connected reader
|
|
33
|
+
brp = Brp(UsbHid())
|
|
34
|
+
|
|
35
|
+
# USB HID by serialnumber
|
|
36
|
+
brp = Brp(UsbHid(serialnumber=99999999))
|
|
37
|
+
|
|
38
|
+
# Serial with (optional) custom settings
|
|
39
|
+
brp = Brp(RS232("COM1", baudrate=115200, parity=b"N"))
|
|
40
|
+
|
|
41
|
+
# TCP by ip address
|
|
42
|
+
brp = Brp(Tcp(ipaddr="192.168.0.1"))
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Access Reader Configuration
|
|
46
|
+
```python
|
|
47
|
+
from baltech_sdk import Config
|
|
48
|
+
|
|
49
|
+
cfg_src = {(0x0201, 0x02): b'\x01'} # instead of a confDict also a brp object
|
|
50
|
+
# can be passed to modify reader's
|
|
51
|
+
# configuration directly
|
|
52
|
+
cfg = Config(cfg_src)
|
|
53
|
+
|
|
54
|
+
# set value
|
|
55
|
+
cfg.Device_Boot_StartAutoreadAtPowerup("EnableOnce")
|
|
56
|
+
|
|
57
|
+
# get value
|
|
58
|
+
print(cfg.Device_Boot_StartAutoreadAtPowerup.get())
|
|
59
|
+
|
|
60
|
+
# delete value
|
|
61
|
+
cfg.Device_Boot_StartAutoreadAtPowerup.delete()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Templates and BaltechScripts
|
|
65
|
+
```python
|
|
66
|
+
from baltech_sdk import Config, Template, BaltechScript, TemplateFilter
|
|
67
|
+
|
|
68
|
+
confdict = {}
|
|
69
|
+
cfg = Config(confdict)
|
|
70
|
+
|
|
71
|
+
cfg.Scripts_Events_OnAccepted(
|
|
72
|
+
BaltechScript()
|
|
73
|
+
.ToggleInverted("RedLed", RepeatCount=3, Delay=20)
|
|
74
|
+
.Toggle("GreenLed", RepeatCount=1, Delay=20)
|
|
75
|
+
.DefaultAction()
|
|
76
|
+
)
|
|
77
|
+
cfg.Autoread_Rule_Template(
|
|
78
|
+
0,
|
|
79
|
+
Template()
|
|
80
|
+
.Static(b"SNR:")
|
|
81
|
+
.Serialnr(TemplateFilter(BinToAscii=True, Unpack=True, BinToBcd=True))
|
|
82
|
+
)
|
|
83
|
+
print(confdict)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Linux or macOS
|
|
87
|
+
To use ``baltech-sdk`` under Linux or macOS you need to build your own binary of the [BaltechSDK](https://docs.baltech.de/developers/sdk.html) and manually set the path to your binary.
|
|
88
|
+
```python
|
|
89
|
+
from pathlib import Path
|
|
90
|
+
from baltech_sdk import set_brp_lib_path
|
|
91
|
+
|
|
92
|
+
set_brp_lib_path(Path("path/to/brp_lib"))
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Further parameters on connections fors sensible data
|
|
97
|
+
|
|
98
|
+
Additional Options:
|
|
99
|
+
* [AES based Encryption](https://docs.baltech.de/developers/add-aes-auth-and-encryption.html) can be activated
|
|
100
|
+
* [Enabled monitoring](https://docs.baltech.de/developers/analyze-communication.html#enable-monitoring) can be suppressed or extended to plaintext
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from baltech_sdk import Brp, UsbHid, SecureChannel
|
|
104
|
+
|
|
105
|
+
KEY = b'abcdefghijklmnuk'
|
|
106
|
+
brp = Brp(UsbHid(),
|
|
107
|
+
crypto=SecureChannel(security_level=1, key=KEY), # encrypt communication
|
|
108
|
+
monitor="plaintext" # log unencrypted data (if activated by user)
|
|
109
|
+
)
|
|
110
|
+
```
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import importlib.resources
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Protocol, Tuple, Optional, Union
|
|
5
|
+
|
|
6
|
+
from .baltech_api import Commands, ConfigAccessor
|
|
7
|
+
from .baltech_api.typedefs import Sys_ErrCfgNotFound
|
|
8
|
+
from .brp_lib.protocols import BrpStack, UsbHid, RS232, SecureChannel, PKI, Tcp
|
|
9
|
+
from .brp_lib.dll_wrapper import c_brp_lib
|
|
10
|
+
|
|
11
|
+
from .baltech_api.typedefs import *
|
|
12
|
+
from .baltech_api.template import *
|
|
13
|
+
from .baltech_api.baltech_script import *
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Brp(BrpStack, Commands):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ConfDict(Protocol):
|
|
21
|
+
def __getitem__(self, item: Tuple[int, Optional[int]]) -> bytes: ...
|
|
22
|
+
def __setitem__(self, key: Tuple[int, Optional[int]], content: Optional[bytes]) -> None: ...
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _CommandsConfDictWrapper(ConfDict):
|
|
26
|
+
def __init__(self, cmds: Commands) -> None:
|
|
27
|
+
self.cmds = cmds
|
|
28
|
+
|
|
29
|
+
def __getitem__(self, item: Tuple[int, Optional[int]]) -> bytes:
|
|
30
|
+
key, value = item
|
|
31
|
+
if value is None:
|
|
32
|
+
raise KeyError(item)
|
|
33
|
+
try:
|
|
34
|
+
return self.cmds.Sys_CfgGetValue(Key=key, Value=value)
|
|
35
|
+
except Sys_ErrCfgNotFound:
|
|
36
|
+
raise KeyError(item)
|
|
37
|
+
|
|
38
|
+
def __setitem__(self, item: Tuple[int, Optional[int]], content: Optional[bytes]) -> None:
|
|
39
|
+
key, value = item
|
|
40
|
+
if content is None:
|
|
41
|
+
try:
|
|
42
|
+
self.cmds.Sys_CfgDelValues(Key=key, Value=value if value is not None else 0xFF)
|
|
43
|
+
except Sys_ErrCfgNotFound:
|
|
44
|
+
raise KeyError(item)
|
|
45
|
+
else:
|
|
46
|
+
if value is None:
|
|
47
|
+
raise KeyError(item)
|
|
48
|
+
try:
|
|
49
|
+
self.cmds.Sys_CfgSetValue(Key=key, Value=value, Content=content)
|
|
50
|
+
except Sys_ErrCfgNotFound:
|
|
51
|
+
raise KeyError(item)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Config(ConfigAccessor):
|
|
55
|
+
def __init__(self, cfg_src: Union[ConfDict, Commands]) -> None:
|
|
56
|
+
self.confdict = _CommandsConfDictWrapper(cfg_src) if isinstance(cfg_src, Commands) else cfg_src
|
|
57
|
+
|
|
58
|
+
def execute(self, frame: bytes) -> bytes:
|
|
59
|
+
mode = frame[0]
|
|
60
|
+
masterkey = frame[1]
|
|
61
|
+
subkey = frame[2] if len(frame) > 2 else 0xFF
|
|
62
|
+
value = frame[3] if len(frame) > 3 else None
|
|
63
|
+
content = frame[4:] if len(frame) > 4 else b""
|
|
64
|
+
key = (masterkey << 8) | subkey
|
|
65
|
+
|
|
66
|
+
if mode == 0: # get
|
|
67
|
+
return self.confdict[(key, value)]
|
|
68
|
+
|
|
69
|
+
if mode == 1: # set
|
|
70
|
+
self.confdict[(key, value)] = content
|
|
71
|
+
return b""
|
|
72
|
+
|
|
73
|
+
if mode == 2:
|
|
74
|
+
self.confdict[(key, value)] = None
|
|
75
|
+
return b""
|
|
76
|
+
|
|
77
|
+
raise ValueError(f"unknown mode '{mode}' in configuration frame {frame!r}")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def get_brp_lib_path() -> Optional[Path]:
|
|
81
|
+
return c_brp_lib.dll_path
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def set_brp_lib_path(path: Union[Path, str]) -> None:
|
|
85
|
+
c_brp_lib.dll_path = Path(path)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _autodetect_brp_lib() -> None:
|
|
89
|
+
arch = 64 if sys.maxsize > 2 ** 32 else 32
|
|
90
|
+
platform = sys.platform.replace("win32", "win")
|
|
91
|
+
extension = {
|
|
92
|
+
"win": "dll"
|
|
93
|
+
}.get(platform, "unknown")
|
|
94
|
+
dll_name = f"brp_lib.{platform}{arch}.{extension}"
|
|
95
|
+
|
|
96
|
+
root_resource = importlib.resources.files("baltech_sdk")
|
|
97
|
+
dll_resource = root_resource / "brp_lib" / dll_name
|
|
98
|
+
dll_path = Path(str(dll_resource))
|
|
99
|
+
if dll_path.exists():
|
|
100
|
+
set_brp_lib_path(dll_path)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
_autodetect_brp_lib()
|