Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 52 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,89 +19,75 @@ python_thingset @ git+https://github.com/Brill-Power/python-thingset.git@fix-pac
### To get a value

```python
from python_thingset.thingset import ThingSet
from python_thingset import ThingSet

with ThingSet() as ts:
""" node_id=0x36, value_id=0xF03 """
response = ts.get(0x36, 0xF03)
with ThingSet(backend="can", can_bus="vcan0") as ts:
response = ts.get(0xF03, 0x01)

print(response)
print(f"0x{response.status_code:02X}")
print(response.status_string)
print(response.data)
print(response) # 0x85 (CONTENT): native_posix
print(f"0x{response.status_code:02X}") # 0x85
print(response.status_string) # CONTENT
print(response.data) # native_posix

for v in response.values:
print(v)
print(v.name, f"0x{v.id:02X}", v.value)
print(v) # Build/rBoard (0xF03): native_posix
print(v.name, f"0x{v.id:02X}", v.value) # Build/rBoard 0xF03 native_posix
```

### To fetch multiple values

```python
from python_thingset.thingset import ThingSet
from python_thingset import ThingSet

with ThingSet() as ts:
""" node_id=0x36, parent_id=0xF, child_ids=0xF03, 0xF02, 0xF01 """
response = ts.fetch(0x36, 0xF, [0xF03, 0xF02, 0xF01])
with ThingSet(backend="can", can_bus="vcan0") as ts:
response = ts.fetch(0xF, [0xF03, 0xF01], 0x01)

print(response)
print(f"0x{response.status_code:02X}")
print(response.status_string)
print(response.data)

for v in response.values:
print(v)
print(v.name, f"0x{v.id:02X}", v.value)
print(response) # 0x85 (CONTENT): ['native_posix', '947c30f8']
print(f"0x{response.status_code:02X}") # 0x85
print(response.status_string) # CONTENT
print(response.data) # ['native_posix', '947c30f8']
```

### To fetch all child IDs of a parent

```python
from python_thingset.thingset import ThingSet
from python_thingset import ThingSet

with ThingSet() as ts:
""" node_id=0x36, parent_id=0xF, empty list invokes fetch of child IDs """
response = ts.fetch(0x36, 0xF, [])
with ThingSet(backend="can", can_bus="vcan0") as ts:
response = ts.fetch(0xF, [], 0x01)

print(response)
print(f"0x{response.status_code:02X}")
print(response.status_string)
print(response.data)

if response.values is not None:
for v in response.values:
print(v)
print(v.name, f"0x{v.id:02X}", [f"0x{i:02X}" for i in v.value])
print(response) # 0x85 (CONTENT): [3841, 3842, 3843, 3845, 3849]
print(f"0x{response.status_code:02X}") # 0x85
print(response.status_string) # CONTENT
print(response.data) # [3841, 3842, 3843, 3845, 3849]
```

### To execute a function

```python
from python_thingset.thingset import ThingSet
from python_thingset import ThingSet

with ThingSet() as ts:
""" node_id=0x36, value_id=0x20, value_args="let-me-in" """
response = ts.exec(0x36, 0x20, ["let-me-in"])
with ThingSet(backend="can", can_bus="vcan0") as ts:
response = ts.exec(0x20, ["some-text"], 0x1)

print(response)
print(f"0x{response.status_code:02X}")
print(response.status_string)
print(response.data)
print(response) # 0x84 (CHANGED): 0
print(f"0x{response.status_code:02X}") # 0x84
print(response.status_string) # CHANGED
print(response.data) # 0
```

### To update a value

```python
from python_thingset.thingset import ThingSet
from python_thingset import ThingSet

with ThingSet() as ts:
""" node_id=0x36, parent_id=0x00, value_id=0x6F, value=21 """
response = ts.update(0x36, 0x00, 0x6F, 21)
with ThingSet(backend="can", can_bus="vcan0") as ts:
response = ts.update(0x4F, 1, 0x1, 0x0)

print(response)
print(f"0x{response.status_code:02X}")
print(response.status_string)
print(response.data)
print(response) # 0x84 (CHANGED): 0
print(f"0x{response.status_code:02X}") # 0x84
print(response.status_string) # CHANGED
print(response.data) # 0
```

## To use from terminal
Expand All @@ -110,14 +96,10 @@ with ThingSet() as ts:

```bash
1. git clone git@github.com:Brill-Power/python-thingset.git
2. cd python_thingset
3. pip install -r requirements.txt
3. chmod +x thingset
4. export PATH="$PATH:$(pwd)"
2. pip install .
3. pip install .[dev] (optional)
```

This will clone the latest version of the repository, make the file `thingset` executable and then add the directory containing the file `thingset` to your `PATH` such that it will be executable from any directory.

### Serial examples

```
Expand Down Expand Up @@ -160,15 +142,19 @@ thingset schema f -c vcan0 -t 2f

### Socket examples

```python
if __name__ == "__main__":
s = ThingSetSock("192.0.2.1")
```
thingset get f -i 127.0.0.1
thingset get f03 -i 127.0.0.1

thingset fetch f -i 127.0.0.1
thingset fetch f f01 f02 -i 127.0.0.1

thingset update 0 6f 3 -i 127.0.0.1

print(s.get(0x300))
print(s.update(0x300, [77.8], parent_id=0x0))
print(s.get(0x300))
print(s.fetch(0, []))
print(s.exec(0x1000, [4, 5]))
thingset exec 44 aFunctionArgument -i 127.0.0.1
thingset exec 55 -i 127.0.0.1
thingset exec 66 1.2 2.3 3.55 -i 127.0.0.1

s.disconnect()
thingset schema -i 127.0.0.1
thingset schema f -i 127.0.0.1
```
23 changes: 0 additions & 23 deletions mkdocs.yml

This file was deleted.

8 changes: 4 additions & 4 deletions python_thingset/thingset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
class ThingSet(object):
def __init__(
self,
backend: str = "can",
backend: str = ThingSetBackend.Socket,
can_bus: str = "vcan0",
can_addr: int = 0x00,
init_block: bool = True,
source_bus: int = 0x00,
target_bus: int = 0x00,
port: str = "/dev/pts/5",
port: str = "/dev/ttyACM0",
baud: int = 115200,
ip_addr: str = "192.0.2.1",
ip_addr: str = "127.0.0.1",
) -> "ThingSet":
"""Constructor for ThingSet object

Args:
backend: communications backend to use - one of `'can'` or `'serial'`
backend: communications backend to use - one of `'can'` or `'serial'` or `'socket'`
can_bus: physical (or virtual) CAN device to use if using CAN backend
can_addr: intended node address of this ThingSet CAN instance if using CAN backend
init_block: whether to block during instantation whilst backend connects
Expand Down