pySerialTransfer 2.1.7__tar.gz → 2.6.11__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.
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/PKG-INFO +13 -11
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/README.md +6 -5
- pyserialtransfer-2.6.11/pySerialTransfer/CRC.py +62 -0
- pyserialtransfer-2.6.11/pySerialTransfer/__init__.py +5 -0
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/pySerialTransfer/pySerialTransfer.py +159 -187
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/pySerialTransfer.egg-info/PKG-INFO +13 -11
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/pySerialTransfer.egg-info/SOURCES.txt +3 -1
- pyserialtransfer-2.6.11/pySerialTransfer.egg-info/requires.txt +6 -0
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/setup.py +10 -3
- pyserialtransfer-2.6.11/tests/test_crc.py +184 -0
- pyserialtransfer-2.6.11/tests/test_py_serial_transfer.py +451 -0
- pySerialTransfer-2.1.7/pySerialTransfer/CRC.py +0 -61
- pySerialTransfer-2.1.7/pySerialTransfer/__init__.py +0 -1
- pySerialTransfer-2.1.7/pySerialTransfer.egg-info/requires.txt +0 -1
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/LICENSE +0 -0
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/pySerialTransfer.egg-info/dependency_links.txt +0 -0
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/pySerialTransfer.egg-info/top_level.txt +0 -0
- {pySerialTransfer-2.1.7 → pyserialtransfer-2.6.11}/setup.cfg +0 -0
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pySerialTransfer
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.6.11
|
|
4
4
|
Summary: Python package used to transmit and receive low overhead byte packets - especially useful for PC<-->Arduino USB communication (compatible with https://github.com/PowerBroker2/SerialTransfer)
|
|
5
5
|
Home-page: https://github.com/PowerBroker2/pySerialTransfer
|
|
6
|
-
Download-URL: https://github.com/PowerBroker2/pySerialTransfer/archive/2.
|
|
6
|
+
Download-URL: https://github.com/PowerBroker2/pySerialTransfer/archive/2.6.11.tar.gz
|
|
7
7
|
Author: Power_Broker
|
|
8
8
|
Author-email: gitstuff2@gmail.com
|
|
9
|
-
License: UNKNOWN
|
|
10
9
|
Keywords: Arduino,serial,usb,protocol,communication
|
|
11
|
-
Platform: UNKNOWN
|
|
12
10
|
Description-Content-Type: text/markdown
|
|
13
11
|
License-File: LICENSE
|
|
12
|
+
Requires-Dist: pyserial
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=8.1.1; extra == "dev"
|
|
15
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-mock>=3.14.0; extra == "dev"
|
|
14
17
|
|
|
15
18
|
# pySerialTransfer
|
|
16
19
|
[](https://badge.fury.io/gh/PowerBroker2%2FpySerialTransfer) [](https://badge.fury.io/py/pySerialTransfer)<br /><br />
|
|
@@ -69,15 +72,16 @@ if __name__ == '__main__':
|
|
|
69
72
|
# Wait for a response and report any errors while receiving packets
|
|
70
73
|
###################################################################
|
|
71
74
|
while not link.available():
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
# A negative value for status indicates an error
|
|
76
|
+
if link.status.value < 0:
|
|
77
|
+
if link.status == txfer.Status.CRC_ERROR:
|
|
74
78
|
print('ERROR: CRC_ERROR')
|
|
75
|
-
elif link.status == txfer.PAYLOAD_ERROR:
|
|
79
|
+
elif link.status == txfer.Status.PAYLOAD_ERROR:
|
|
76
80
|
print('ERROR: PAYLOAD_ERROR')
|
|
77
|
-
elif link.status == txfer.STOP_BYTE_ERROR:
|
|
81
|
+
elif link.status == txfer.Status.STOP_BYTE_ERROR:
|
|
78
82
|
print('ERROR: STOP_BYTE_ERROR')
|
|
79
83
|
else:
|
|
80
|
-
print('ERROR: {}'.format(link.status))
|
|
84
|
+
print('ERROR: {}'.format(link.status.name))
|
|
81
85
|
|
|
82
86
|
###################################################################
|
|
83
87
|
# Parse response list
|
|
@@ -195,5 +199,3 @@ if __name__ == '__main__':
|
|
|
195
199
|
|
|
196
200
|
link.close()
|
|
197
201
|
```
|
|
198
|
-
|
|
199
|
-
|
|
@@ -55,15 +55,16 @@ if __name__ == '__main__':
|
|
|
55
55
|
# Wait for a response and report any errors while receiving packets
|
|
56
56
|
###################################################################
|
|
57
57
|
while not link.available():
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
# A negative value for status indicates an error
|
|
59
|
+
if link.status.value < 0:
|
|
60
|
+
if link.status == txfer.Status.CRC_ERROR:
|
|
60
61
|
print('ERROR: CRC_ERROR')
|
|
61
|
-
elif link.status == txfer.PAYLOAD_ERROR:
|
|
62
|
+
elif link.status == txfer.Status.PAYLOAD_ERROR:
|
|
62
63
|
print('ERROR: PAYLOAD_ERROR')
|
|
63
|
-
elif link.status == txfer.STOP_BYTE_ERROR:
|
|
64
|
+
elif link.status == txfer.Status.STOP_BYTE_ERROR:
|
|
64
65
|
print('ERROR: STOP_BYTE_ERROR')
|
|
65
66
|
else:
|
|
66
|
-
print('ERROR: {}'.format(link.status))
|
|
67
|
+
print('ERROR: {}'.format(link.status.name))
|
|
67
68
|
|
|
68
69
|
###################################################################
|
|
69
70
|
# Parse response list
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from functools import lru_cache
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class CRC:
|
|
6
|
+
def __init__(self, polynomial=0x9B, crc_len=8):
|
|
7
|
+
self.poly = polynomial & 0xFF
|
|
8
|
+
self.crc_len = crc_len
|
|
9
|
+
self.table_len = pow(2, crc_len)
|
|
10
|
+
|
|
11
|
+
@lru_cache(2 ^ 16)
|
|
12
|
+
def calculate_checksum(self, index: int):
|
|
13
|
+
"""Calculate the checksum for a given index.
|
|
14
|
+
An LRU cached version of the CRC calculation function, with an upper bound on the cache size of 2^16
|
|
15
|
+
"""
|
|
16
|
+
if index > self.table_len:
|
|
17
|
+
raise ValueError('Index out of range')
|
|
18
|
+
curr = index
|
|
19
|
+
for j in range(8):
|
|
20
|
+
if (curr & 0x80) != 0:
|
|
21
|
+
curr = ((curr << 1) & 0xFF) ^ self.poly
|
|
22
|
+
else:
|
|
23
|
+
curr <<= 1
|
|
24
|
+
return curr
|
|
25
|
+
|
|
26
|
+
def print_table(self):
|
|
27
|
+
for i in range(self.table_len):
|
|
28
|
+
sys.stdout.write(hex(self.calculate_checksum(i)).upper().replace('X', 'x'))
|
|
29
|
+
|
|
30
|
+
if (i + 1) % 16:
|
|
31
|
+
sys.stdout.write(' ')
|
|
32
|
+
else:
|
|
33
|
+
sys.stdout.write('\n')
|
|
34
|
+
|
|
35
|
+
def calculate(self, arr, dist=None):
|
|
36
|
+
crc = 0
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
if dist:
|
|
40
|
+
indicies = dist
|
|
41
|
+
else:
|
|
42
|
+
indicies = len(arr)
|
|
43
|
+
|
|
44
|
+
for i in range(indicies):
|
|
45
|
+
try:
|
|
46
|
+
nex_el = int(arr[i])
|
|
47
|
+
except ValueError:
|
|
48
|
+
nex_el = ord(arr[i])
|
|
49
|
+
|
|
50
|
+
crc = self.calculate_checksum(crc ^ nex_el)
|
|
51
|
+
|
|
52
|
+
except TypeError:
|
|
53
|
+
crc = self.calculate_checksum(arr)
|
|
54
|
+
|
|
55
|
+
return crc
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == '__main__':
|
|
59
|
+
crc_instance = CRC()
|
|
60
|
+
print(crc_instance.print_table())
|
|
61
|
+
print(' ')
|
|
62
|
+
print(hex(crc_instance.calculate(0x31)).upper().replace('X', 'x'))
|