syndesi 0.1.1__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.
Files changed (41) hide show
  1. {syndesi-0.1.1/syndesi.egg-info → syndesi-0.1.3}/PKG-INFO +1 -1
  2. {syndesi-0.1.1 → syndesi-0.1.3}/README.md +0 -0
  3. {syndesi-0.1.1 → syndesi-0.1.3}/setup.cfg +0 -0
  4. {syndesi-0.1.1 → syndesi-0.1.3}/setup.py +1 -1
  5. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/adapters/iadapter.py +0 -0
  6. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/adapters/visa.py +0 -0
  7. syndesi-0.1.3/syndesi/protocols/__init__.py +5 -0
  8. syndesi-0.1.3/syndesi/protocols/commands.py +78 -0
  9. syndesi-0.1.3/syndesi/protocols/iprotocol.py +14 -0
  10. syndesi-0.1.1/syndesi/protocols/raw_stream.py → syndesi-0.1.3/syndesi/protocols/raw.py +24 -1
  11. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/protocols/scpi.py +19 -10
  12. {syndesi-0.1.1 → syndesi-0.1.3/syndesi.egg-info}/PKG-INFO +1 -1
  13. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi.egg-info/SOURCES.txt +2 -3
  14. syndesi-0.1.3/syndesi.egg-info/top_level.txt +2 -0
  15. syndesi-0.1.1/syndesi/protocols/__init__.py +0 -6
  16. syndesi-0.1.1/syndesi/protocols/commands.py +0 -57
  17. syndesi-0.1.1/syndesi/protocols/iprotocol.py +0 -5
  18. syndesi-0.1.1/syndesi/protocols/raw.py +0 -24
  19. syndesi-0.1.1/syndesi.egg-info/top_level.txt +0 -2
  20. {syndesi-0.1.1 → syndesi-0.1.3}/LICENSE +0 -0
  21. {syndesi-0.1.1 → syndesi-0.1.3}/bin/syndesi +0 -0
  22. {syndesi-0.1.1/syndesi → syndesi-0.1.3/experiments}/__init__.py +0 -0
  23. {syndesi-0.1.1/syndesi/descriptors → syndesi-0.1.3}/syndesi/__init__.py +0 -0
  24. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/adapters/__init__.py +0 -0
  25. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/adapters/ip.py +0 -0
  26. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/adapters/serial.py +0 -0
  27. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/Serial.py +0 -0
  28. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/__init__.py +0 -0
  29. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/descriptor.py +0 -0
  30. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/ip.py +0 -0
  31. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/syndesi/Syndesi.py +0 -0
  32. {syndesi-0.1.1/tests → syndesi-0.1.3/syndesi/descriptors/syndesi}/__init__.py +0 -0
  33. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/syndesi/_device.py +0 -0
  34. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/syndesi/devices.py +0 -0
  35. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/syndesi/frame.py +0 -0
  36. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/syndesi/network.py +0 -0
  37. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/syndesi/payload.py +0 -0
  38. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/syndesi/sdid.py +0 -0
  39. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/descriptors/visa.py +0 -0
  40. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi/protocols/sdp.py +0 -0
  41. {syndesi-0.1.1 → syndesi-0.1.3}/syndesi.egg-info/dependency_links.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: syndesi
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Syndesi
5
5
  Author: Sebastien Deriaz
6
6
  Author-email: sebastien.deriaz1@gmail.com
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  from setuptools import setup, find_packages
2
2
 
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.3'
4
4
  DESCRIPTION = 'Syndesi'
5
5
 
6
6
  with open("README.md", "r", encoding="utf-8") as fh:
@@ -0,0 +1,5 @@
1
+ from syndesi.protocols.iprotocol import IProtocol
2
+ from .commands import Commands
3
+ from .raw import Raw, RawStream
4
+ from .scpi import SCPI
5
+ from .sdp import SDP
@@ -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()
@@ -0,0 +1,14 @@
1
+ from ..adapters import IAdapter
2
+
3
+ class IProtocol:
4
+ def __init__(self, adapter : IAdapter) -> None:
5
+ self._adapter = adapter
6
+
7
+ def write(self, data):
8
+ pass
9
+
10
+ def query(self, data):
11
+ pass
12
+
13
+ def read(self):
14
+ pass
@@ -2,7 +2,30 @@ from ..adapters import IAdapter
2
2
  from .iprotocol import IProtocol
3
3
 
4
4
 
5
- # This is a temporary class to manage continuously streaming devices (Arduino for datalogging, some RS-232 multimeters, etc...)
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
@@ -32,22 +36,27 @@ class SCPI(IProtocol):
32
36
  def _unformatCommand(self, payload):
33
37
  return payload.replace(self._end, '')
34
38
 
35
- def _checkCommand(self, command : bytearray):
39
+ def _checkCommand(self, command : str):
36
40
  for c in ['\n', '\r']:
37
41
  if c in command:
38
42
  raise ValueError(f"Invalid char '{c}' in command")
39
43
 
40
- def write(self, command : bytearray) -> None:
44
+ def write(self, command : str) -> None:
41
45
  self._checkCommand(command)
42
- command = self._to_bytearray(command)
43
- self._adapter.write(self._formatCommand(command))
46
+ payload = self._to_bytearray(self._formatCommand(command))
47
+ self._adapter.write(payload)
44
48
 
45
49
  def query(self, command : str) -> str:
46
- data = self._to_bytearray(command)
47
50
  self._adapter.flushRead()
48
- self.write(data)
51
+ self.write(command)
49
52
  return self.read()
50
53
 
51
54
  def read(self) -> str:
52
- data = self._adapter.read().decode('ASCII')
53
- return self._unformatCommand(data)
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: syndesi
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Syndesi
5
5
  Author: Sebastien Deriaz
6
6
  Author-email: sebastien.deriaz1@gmail.com
@@ -2,6 +2,7 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  bin/syndesi
5
+ experiments/__init__.py
5
6
  syndesi/__init__.py
6
7
  syndesi.egg-info/PKG-INFO
7
8
  syndesi.egg-info/SOURCES.txt
@@ -29,7 +30,5 @@ syndesi/protocols/__init__.py
29
30
  syndesi/protocols/commands.py
30
31
  syndesi/protocols/iprotocol.py
31
32
  syndesi/protocols/raw.py
32
- syndesi/protocols/raw_stream.py
33
33
  syndesi/protocols/scpi.py
34
- syndesi/protocols/sdp.py
35
- tests/__init__.py
34
+ syndesi/protocols/sdp.py
@@ -0,0 +1,2 @@
1
+ experiments
2
+ syndesi
@@ -1,6 +0,0 @@
1
- from syndesi.protocols.iprotocol import IProtocol
2
- from .commands import RawCommands
3
- from .raw_stream import RawStream
4
- from .raw import Raw
5
- from .scpi import SCPI
6
- from .sdp import SDP
@@ -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,5 +0,0 @@
1
- from ..adapters import IAdapter
2
-
3
- class IProtocol:
4
- def __init__(self, adapter : IAdapter) -> None:
5
- self._adapter = adapter
@@ -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()
@@ -1,2 +0,0 @@
1
- syndesi
2
- tests
File without changes
File without changes
File without changes