syndesi 0.1.2__tar.gz → 0.1.3__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.
- {syndesi-0.1.2/syndesi.egg-info → syndesi-0.1.3}/PKG-INFO +1 -1
- {syndesi-0.1.2 → syndesi-0.1.3}/setup.py +1 -1
- syndesi-0.1.3/syndesi/protocols/__init__.py +5 -0
- syndesi-0.1.3/syndesi/protocols/commands.py +78 -0
- syndesi-0.1.3/syndesi/protocols/iprotocol.py +14 -0
- syndesi-0.1.2/syndesi/protocols/raw_stream.py → syndesi-0.1.3/syndesi/protocols/raw.py +24 -1
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/protocols/scpi.py +14 -4
- {syndesi-0.1.2 → syndesi-0.1.3/syndesi.egg-info}/PKG-INFO +1 -1
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi.egg-info/SOURCES.txt +0 -1
- syndesi-0.1.2/syndesi/protocols/__init__.py +0 -6
- syndesi-0.1.2/syndesi/protocols/commands.py +0 -57
- syndesi-0.1.2/syndesi/protocols/iprotocol.py +0 -5
- syndesi-0.1.2/syndesi/protocols/raw.py +0 -24
- {syndesi-0.1.2 → syndesi-0.1.3}/LICENSE +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/README.md +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/bin/syndesi +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/experiments/__init__.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/setup.cfg +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/__init__.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/adapters/__init__.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/adapters/iadapter.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/adapters/ip.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/adapters/serial.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/adapters/visa.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/Serial.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/__init__.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/descriptor.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/ip.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/syndesi/Syndesi.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/syndesi/__init__.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/syndesi/_device.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/syndesi/devices.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/syndesi/frame.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/syndesi/network.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/syndesi/payload.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/syndesi/sdid.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/descriptors/visa.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi/protocols/sdp.py +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi.egg-info/dependency_links.txt +0 -0
- {syndesi-0.1.2 → syndesi-0.1.3}/syndesi.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from .iprotocol import IProtocol
|
|
2
|
+
from ..adapters import IAdapter
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Commands(IProtocol):
|
|
6
|
+
def __init__(self, adapter : IAdapter, termination='\n', format_response=True) -> None:
|
|
7
|
+
"""
|
|
8
|
+
Command-based protocol, with LF, CR or CRLF termination
|
|
9
|
+
|
|
10
|
+
No presentation or application layers
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
adapter : IAdapter
|
|
15
|
+
end : bytearray
|
|
16
|
+
Command termination, '\n' by default
|
|
17
|
+
format_response : bool
|
|
18
|
+
Apply formatting to the response (i.e removing the termination)
|
|
19
|
+
"""
|
|
20
|
+
super().__init__(adapter)
|
|
21
|
+
|
|
22
|
+
if not isinstance(termination, str):
|
|
23
|
+
raise ValueError(f"end argument must be of type str, not {type(termination)}")
|
|
24
|
+
self._termination = termination
|
|
25
|
+
self._response_formatting = format_response
|
|
26
|
+
|
|
27
|
+
def _to_bytearray(self, command) -> bytearray:
|
|
28
|
+
if isinstance(command, str):
|
|
29
|
+
return command.encode('ASCII')
|
|
30
|
+
elif isinstance(command, bytes) or isinstance(command, bytearray):
|
|
31
|
+
return command
|
|
32
|
+
else:
|
|
33
|
+
raise ValueError(f'Invalid command type : {type(command)}')
|
|
34
|
+
|
|
35
|
+
def _from_bytearray(self, payload) -> str:
|
|
36
|
+
if isinstance(payload, bytearray):
|
|
37
|
+
return payload.decode('ASCII')
|
|
38
|
+
else:
|
|
39
|
+
raise ValueError(f"Invalid payload type : {type(payload)}")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _format_command(self, command : str) -> str:
|
|
43
|
+
return command + self._termination
|
|
44
|
+
|
|
45
|
+
def _format_response(self, response : str) -> str:
|
|
46
|
+
if response.endswith(self._termination):
|
|
47
|
+
response = response[:-len(self._termination)]
|
|
48
|
+
return response
|
|
49
|
+
|
|
50
|
+
def write(self, command : str):
|
|
51
|
+
command = self._format_command(command)
|
|
52
|
+
self._adapter.write(self._to_bytearray(command))
|
|
53
|
+
|
|
54
|
+
def query(self, command : str) -> str:
|
|
55
|
+
"""
|
|
56
|
+
Writes then reads from the device then return the result
|
|
57
|
+
|
|
58
|
+
"""
|
|
59
|
+
self._adapter.flushRead()
|
|
60
|
+
self.write(command)
|
|
61
|
+
return self.read()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def read(self) -> str:
|
|
65
|
+
"""
|
|
66
|
+
Reads command and formats it as an str
|
|
67
|
+
"""
|
|
68
|
+
output = self._from_bytearray(self._adapter.read())
|
|
69
|
+
if self._response_formatting:
|
|
70
|
+
return self._format_response(output)
|
|
71
|
+
else:
|
|
72
|
+
return output
|
|
73
|
+
|
|
74
|
+
def read_raw(self) -> bytearray:
|
|
75
|
+
"""
|
|
76
|
+
Returns the raw bytes instead of str
|
|
77
|
+
"""
|
|
78
|
+
return self._adapter.read()
|
|
@@ -2,7 +2,30 @@ from ..adapters import IAdapter
|
|
|
2
2
|
from .iprotocol import IProtocol
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# Raw protocols provide the user with the binary data directly,
|
|
6
|
+
# without converting it to string first
|
|
7
|
+
|
|
8
|
+
class Raw(IProtocol):
|
|
9
|
+
def __init__(self, adapter: IAdapter) -> None:
|
|
10
|
+
"""
|
|
11
|
+
Raw device, no presentation and application layers
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
adapter : IAdapter
|
|
16
|
+
"""
|
|
17
|
+
super().__init__(adapter)
|
|
18
|
+
|
|
19
|
+
def write(self, data : bytearray):
|
|
20
|
+
self._adapter.write(data)
|
|
21
|
+
|
|
22
|
+
def query(self, data : bytearray) -> bytearray:
|
|
23
|
+
self._adapter.flushRead()
|
|
24
|
+
self.write(data)
|
|
25
|
+
return self.read()
|
|
26
|
+
|
|
27
|
+
def read(self) -> bytearray:
|
|
28
|
+
return self._adapter.read()
|
|
6
29
|
|
|
7
30
|
class RawStream(IProtocol):
|
|
8
31
|
def __init__(self, adapter: IAdapter, delimiter = b'\n') -> None:
|
|
@@ -21,10 +21,14 @@ class SCPI(IProtocol):
|
|
|
21
21
|
def _to_bytearray(self, command):
|
|
22
22
|
if isinstance(command, str):
|
|
23
23
|
return command.encode('ASCII')
|
|
24
|
-
elif isinstance(command, bytes) or isinstance(command, bytearray):
|
|
25
|
-
return command
|
|
26
24
|
else:
|
|
27
25
|
raise ValueError(f'Invalid command type : {type(command)}')
|
|
26
|
+
|
|
27
|
+
def _from_bytearray(self, payload):
|
|
28
|
+
if isinstance(payload, bytearray):
|
|
29
|
+
return payload.decode('ASCII')
|
|
30
|
+
else:
|
|
31
|
+
raise ValueError(f"Invalid payload type : {type(payload)}")
|
|
28
32
|
|
|
29
33
|
def _formatCommand(self, command):
|
|
30
34
|
return command + self._end
|
|
@@ -48,5 +52,11 @@ class SCPI(IProtocol):
|
|
|
48
52
|
return self.read()
|
|
49
53
|
|
|
50
54
|
def read(self) -> str:
|
|
51
|
-
|
|
52
|
-
return self._unformatCommand(
|
|
55
|
+
output = self._from_bytearray(self._adapter.read())
|
|
56
|
+
return self._unformatCommand(output)
|
|
57
|
+
|
|
58
|
+
def read_raw(self) -> str:
|
|
59
|
+
"""
|
|
60
|
+
Return the raw bytes instead of str
|
|
61
|
+
"""
|
|
62
|
+
return self._adapter.read()
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
from .iprotocol import IProtocol
|
|
2
|
-
from ..adapters import IAdapter
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class RawCommands(IProtocol):
|
|
6
|
-
def __init__(self, adapter : IAdapter, end=b'\n', format_response=True) -> None:
|
|
7
|
-
"""
|
|
8
|
-
Command-based protocol, with LF, CR or CRLF termination
|
|
9
|
-
|
|
10
|
-
No presentation or application layers
|
|
11
|
-
|
|
12
|
-
Parameters
|
|
13
|
-
----------
|
|
14
|
-
adapter : IAdapter
|
|
15
|
-
end : bytearray
|
|
16
|
-
Command termination, '\n' by default
|
|
17
|
-
format_response : bool
|
|
18
|
-
Apply formatting to the response (i.e removing the termination)
|
|
19
|
-
"""
|
|
20
|
-
super().__init__(adapter)
|
|
21
|
-
|
|
22
|
-
if not isinstance(end, bytes):
|
|
23
|
-
raise ValueError(f"end argument must be of type bytes, not {type(end)}")
|
|
24
|
-
self._end = end
|
|
25
|
-
self._response_formatting = format_response
|
|
26
|
-
|
|
27
|
-
def _to_bytearray(self, command) -> bytearray:
|
|
28
|
-
if isinstance(command, str):
|
|
29
|
-
return command.encode('ASCII')
|
|
30
|
-
elif isinstance(command, bytes) or isinstance(command, bytearray):
|
|
31
|
-
return command
|
|
32
|
-
else:
|
|
33
|
-
raise ValueError(f'Invalid command type : {type(command)}')
|
|
34
|
-
|
|
35
|
-
def _format_command(self, command : bytearray) -> bytearray:
|
|
36
|
-
return command + self._end
|
|
37
|
-
|
|
38
|
-
def _format_response(self, response : bytearray) -> bytearray:
|
|
39
|
-
if response.endswith(self._end):
|
|
40
|
-
response = response[:-len(self._end)]
|
|
41
|
-
return response
|
|
42
|
-
|
|
43
|
-
def write(self, command : bytearray):
|
|
44
|
-
command = self._to_bytearray(command)
|
|
45
|
-
self._adapter.write(self._format_command(command))
|
|
46
|
-
|
|
47
|
-
def query(self, command : bytearray) -> bytearray:
|
|
48
|
-
data = self._to_bytearray(command)
|
|
49
|
-
self._adapter.flushRead()
|
|
50
|
-
self.write(data)
|
|
51
|
-
return self.read()
|
|
52
|
-
|
|
53
|
-
def read(self) -> bytearray:
|
|
54
|
-
if self._response_formatting:
|
|
55
|
-
return self._format_response(self._adapter.read())
|
|
56
|
-
else:
|
|
57
|
-
return self._adapter.read()
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from ..adapters import IAdapter
|
|
2
|
-
from .iprotocol import IProtocol
|
|
3
|
-
|
|
4
|
-
class Raw(IProtocol):
|
|
5
|
-
def __init__(self, adapter: IAdapter) -> None:
|
|
6
|
-
"""
|
|
7
|
-
Raw device, no presentation and application layers
|
|
8
|
-
|
|
9
|
-
Parameters
|
|
10
|
-
----------
|
|
11
|
-
adapter : IAdapter
|
|
12
|
-
"""
|
|
13
|
-
super().__init__(adapter)
|
|
14
|
-
|
|
15
|
-
def write(self, data : bytearray):
|
|
16
|
-
self._adapter.write(data)
|
|
17
|
-
|
|
18
|
-
def query(self, data : bytearray) -> bytearray:
|
|
19
|
-
self._adapter.flushRead()
|
|
20
|
-
self.write(data)
|
|
21
|
-
return self.read()
|
|
22
|
-
|
|
23
|
-
def read(self) -> bytearray:
|
|
24
|
-
return self._adapter.read()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|