Skip to content

Commit a44df3b

Browse files
authored
Merge pull request #4 from ottowayi/develop
v0.1.1
2 parents 22814d2 + 10e8608 commit a44df3b

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ use the ``slot`` kwarg if the PLC is not in slot 0. Controllers with on-board e
6060

6161
# Read a tag
6262
plc.read_tag('DINT1')
63+
# Returns: (1, 'DINT'), a (value, data type) tuple
64+
6365
# Read a list of tags
6466
plc.read_tag(['Tag1', 'Tag2', 'Tag3'])
6567
# or
6668
plc.read_tag('Tag1', 'Tag2', 'Tag3')
69+
# Returns: [('Tag1', 0, 'DINT'), ('Tag2', 1, 'DINT'), ('Tag3, 2, 'DINT')]
70+
# Reading multiple tags includes the tag name with each result
6771

6872
# To read all the DINT controller-scoped tags:
6973
dint_tags = [tag for tag in plc.tags if plc.tags[tag].get('data_type') == 'DINT']
@@ -93,7 +97,7 @@ use the ``slot`` kwarg if the PLC is not in slot 0. Controllers with on-board e
9397
# RETURN: True (if successful, False if not)
9498

9599
plc.write_tag([('DINT1', -1, 'DINT'), ('DINT2', 0, 'DINT'), ('DINT3', 1, 'DINT')])
96-
# RETURN: [('DINT1', -1, 'DINT', 'GOOD'), ('DINT2', 0, 'DINT', 'GOOD'), ('DINT3', 1, 'DINT', 'GOOD')]
100+
# RETURN: [('DINT1', -1, 'DINT', True), ('DINT2', 0, 'DINT', True), ('DINT3', 1, 'DINT', True)]
97101
# Writing multiple tags will return the Tag Name, Value written, Data Type, and True/False
98102

99103
# Writing Strings

pycomm3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# SOFTWARE.
2525
#
2626

27-
__version_info__ = (0, 1, 0)
27+
__version_info__ = (0, 1, 1)
2828
__version__ = '.'.join(f'{x}' for x in __version_info__)
2929

3030

pycomm3/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ def register_session(self):
226226
reply = self._receive()
227227
if self._check_reply(reply):
228228
self._session = unpack_dint(reply[4:8])
229-
self.__log.debug("Session ={0} has been registered.".format(print_bytes_line(reply[4:8])))
229+
if self._debug:
230+
self.__log.debug("Session ={0} has been registered.".format(print_bytes_line(reply[4:8])))
230231
return self._session
231232

232233
self._status = 'Warning ! the session has not been registered.'

pycomm3/clx.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(self, ip_address, *args, slot=0, large_packets=True, init_info=True
8383
self.use_instance_ids = self.info.get('version_major', 0) >= MIN_VER_INSTANCE_IDS
8484

8585
if init_tags:
86-
self._tags = self.get_tag_list()
86+
self.get_tag_list()
8787
self.close()
8888

8989
def _check_reply(self, reply):
@@ -127,7 +127,6 @@ def create_tag_rp(self, tag, multi_requests=False):
127127
If any error it returns none
128128
"""
129129
tags = tag.split('.')
130-
index = []
131130
if tags:
132131
base, *attrs = tags
133132

@@ -145,16 +144,13 @@ def create_tag_rp(self, tag, multi_requests=False):
145144
rp.append(PADDING_BYTE)
146145

147146
for attr in attrs:
148-
# Check if is an array tag
149-
if '[' in attr:
150-
# Remove the last square bracket
151-
attr = attr[:len(attr) - 1]
152-
# Isolate the value inside bracket
153-
inside_value = attr[attr.find('[') + 1:]
154-
# Now split the inside value in case part of multidimensional array
155-
index = inside_value.split(',')
156-
# Get only the tag part
157-
attr = attr[:attr.find('[')]
147+
if '[' in attr: # Check if is an array tag
148+
attr = attr[:len(attr) - 1] # Remove the last square bracket
149+
inside_value = attr[attr.find('[') + 1:] # Isolate the value inside bracket
150+
index = inside_value.split(',') # Now split the inside value in case part of multidimensional array
151+
attr = attr[:attr.find('[')] # Get only the tag part
152+
else:
153+
index = []
158154
tag_length = len(attr)
159155

160156
# Create the request path
@@ -175,8 +171,7 @@ def create_tag_rp(self, tag, multi_requests=False):
175171
elif val <= 0xfffffffff:
176172
attr_path += [ELEMENT_ID["32-bit"], PADDING_BYTE, pack_dint(val)]
177173
else:
178-
# Cannot create a valid request packet
179-
return None
174+
return None # Cannot create a valid request packet
180175

181176
rp += attr_path
182177

@@ -394,7 +389,7 @@ def _write_tag_multi_write(self, tags):
394389
rp = self.create_tag_rp(name, multi_requests=True)
395390
request = bytes([TAG_SERVICES_REQUEST["Read Modify Write Tag"]]) + rp
396391
request += b''.join(self._make_write_bit_data(bit, value, bool_ary='[' in name))
397-
if typ == 'BOOL' and name.endswith('['):
392+
if typ == 'BOOL' and name.endswith(']'):
398393
name = self._dword_to_boolarray(name, bit)
399394
else:
400395
name = f'{name}.{bit}'

pycomm3/const.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
MULTISERVICE_READ_OVERHEAD = 6
3232
MULTISERVICE_WRITE_OVERHEAD = 3
3333
MIN_VER_INSTANCE_IDS = 21 # using Symbol Instance Addressing not supported below version 21
34+
MIN_VER_LARGE_CONNECTIONS = 20 # >500 byte connections not supported below logix v20
3435
EXTENDED_SYMBOL = b'\x91'
3536
BOOL_ONE = 0xff
3637
REQUEST_SERVICE = 0
@@ -119,7 +120,7 @@
119120
CONNECTION_MANAGER_INSTANCE = {
120121
'Open Request': b'\x01',
121122
'Open Format Rejected': b'\x02',
122-
'Open Resource Rejected': b'\x03',
123+
'Open Resource Rejected': b'\x03',
123124
'Open Other Rejected': b'\x04',
124125
'Close Request': b'\x05',
125126
'Close Format Request': b'\x06',

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def read(file_name):
1313
author='Ian Ottoway',
1414
author_email="ian@ottoway.dev",
1515
url="https://github.com/ottowayi/pycomm3",
16-
download_url="",
1716
description="A PLC communication library for Python",
1817
long_description=read('README.rst'),
1918
license="MIT",

0 commit comments

Comments
 (0)