Skip to content

Commit

Permalink
Pat's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesJeffryes committed May 20, 2020
1 parent f5305a1 commit ad45197
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ The entire API is `get` and `set`, and takes a range of inputs:
>>> await plc.set('y101', True) # Sets Y101 to true
```

If a path is provided to a tags file when the driver is initialized,
tag nicknames can be used to set values and calling `.get()` without
arguments returns all named tags.
#### Using named tags

The ClickPLC software provides the ability to export a file containing all the addresses in use
along with their user assign nicknames. To export this file, open the Address Picker, select
"Display MODBUS address" and export the file.
![Export Tags](tags_export.png)
If a path to this tags file is provided when the
driver is initialized, tag nicknames can be used to set values. Calling `.get()` without
arguments will return all named tags.
```python
async with ClickPLC('the-plc-ip-address', 'path-to-tags-csv') as plc:
await plc.set('Tag Nickname', True)
await plc.set('myTagNickname', True)
print(await plc.get())
```

Expand Down
6 changes: 3 additions & 3 deletions clickplc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def command_line():
import json

parser = argparse.ArgumentParser(description="Control a ClickPLC from "
"the command line.")
parser.add_argument('address', help="The IP address of the ClickPLC.")
"the command line")
parser.add_argument('address', help="The IP address of the ClickPLC")
parser.add_argument('tags_file', default=None,
help="Optional: Path to a tags file for this PLC" )
help="Optional: Path to a tags file for this PLC")
args = parser.parse_args()

async def get():
Expand Down
6 changes: 3 additions & 3 deletions clickplc/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ async def get(self, address: str = None) -> dict:
results = {}
for category, address in self.active_addresses.items():
results.update(await getattr(self, '_get_' + category)(address['min'], address['max']))
return {nickname: results[tag_info['id'].lower()]
for nickname, tag_info in self.tags.items()}
return {tag_name: results[tag_info['id'].lower()]
for tag_name, tag_info in self.tags.items()}

if '-' in address:
start, end = address.split('-')
Expand Down Expand Up @@ -115,7 +115,7 @@ async def set(self, address, data):
>>> plc.set('df1', 0.0) # Sets DF1 to 0.0
>>> plc.set('df1', [0.0, 0.0, 0.0]) # Sets DF1-DF3 to 0.0.
>>> plc.set('AV-101', True) # Sets address nicknamed AV-101 to true
>>> plc.set('myTagNickname', True) # Sets address named myTagNickname to true
This uses the ClickPLC's internal variable notation, which can be
found in the Address Picker of the ClickPLC software. If a tags file
Expand Down
1 change: 0 additions & 1 deletion clickplc/tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ async def test_tagged_driver(tagged_driver, expected_tags):
assert expected_tags.keys() == state.keys()



@pytest.mark.asyncio
@pytest.mark.parametrize('prefix', ['x', 'y'])
async def test_bool_roundtrip(plc_driver, prefix):
Expand Down
Binary file added tags_export.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ad45197

Please sign in to comment.