Skip to content

Commit

Permalink
Merge pull request #180 from ottowayi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ottowayi authored Nov 2, 2021
2 parents 915c7ab + ab8f92e commit bfde1c1
Show file tree
Hide file tree
Showing 5 changed files with 1,967 additions and 333 deletions.
7 changes: 5 additions & 2 deletions pycomm3/logix_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def get_tag_list(self, program: str = None, cache: bool = True) -> List[dict]:

self._cache = None

self.__log.info("Completed tag list upload.")
self.__log.info(f"Completed tag list upload. Uploaded {len(self._tags)} tags.")
return tags

def _get_tag_list(self, program=None):
Expand Down Expand Up @@ -1330,7 +1330,7 @@ def _parse_tag_request(self, tag: str, rw="r") -> dict:

if len(attrs) and attrs[-1].isdigit():
bit = int(attrs.pop(-1))
tag = base if not len(attrs) else f"{base}.{''.join(attrs)}"
tag = base if not len(attrs) else f"{base}.{'.'.join(attrs)}"

tag_info = self._get_tag_info(base, attrs)

Expand Down Expand Up @@ -1419,6 +1419,9 @@ def _send_read_fragmented(
self._sequence, request, offset
)
else:
if response.error:
self.__log.error(f"Fragment failed with error: {response.error}")

offset = None

if all(responses):
Expand Down
34 changes: 9 additions & 25 deletions pycomm3/packets/logix.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def __init__(
self.request_path = None

def tag_only_message(self):
return b"".join(
(self.tag_service, self.request_path, UINT.encode(self.elements))
)
return b"".join((self.tag_service, self.request_path, UINT.encode(self.elements)))


class ReadTagResponsePacket(TagServiceResponsePacket):
Expand Down Expand Up @@ -107,20 +105,16 @@ class ReadTagRequestPacket(TagServiceRequestPacket):
def _setup_message(self):
super()._setup_message()
if self.request_path is None:
self.request_path = tag_request_path(
self.tag, self.tag_info, self._use_instance_id
)
self.request_path = tag_request_path(self.tag, self.tag_info, self._use_instance_id)
if self.request_path is None:
self.error = f"Failed to build request path for tag"
self._error = "Failed to build request path for tag"
self._msg.append(self.tag_only_message())


class ReadTagFragmentedResponsePacket(ReadTagResponsePacket):
__log = logging.getLogger(f"{__module__}.{__qualname__}")

def __init__(
self, request: "ReadTagFragmentedRequestPacket", raw_data: bytes = None
):
def __init__(self, request: "ReadTagFragmentedRequestPacket", raw_data: bytes = None):
self.value = None
self._data_type = None
self.value_bytes = None
Expand Down Expand Up @@ -201,9 +195,7 @@ def from_request(
return new_request

def __repr__(self):
return (
f"{self.__class__.__name__}(tag={self.tag!r}, elements={self.elements!r})"
)
return f"{self.__class__.__name__}(tag={self.tag!r}, elements={self.elements!r})"


class WriteTagResponsePacket(TagServiceResponsePacket):
Expand Down Expand Up @@ -251,9 +243,7 @@ def __init__(
def _setup_message(self):
super()._setup_message()
if self.request_path is None:
self.request_path = tag_request_path(
self.tag, self.tag_info, self._use_instance_id
)
self.request_path = tag_request_path(self.tag, self.tag_info, self._use_instance_id)
if self.request_path is None:
self.error = f"Failed to build request path for tag"
self._msg.append(self.tag_only_message())
Expand Down Expand Up @@ -368,9 +358,7 @@ def __init__(
self._mask_size = DataTypes.get(self.data_type).size

if self._mask_size is None:
raise RequestError(
f'Invalid data type {tag_info["data_type"]} for writing bits'
)
raise RequestError(f'Invalid data type {tag_info["data_type"]} for writing bits')

if self.request_path is None:
self.error = "Failed to create request path for tag"
Expand Down Expand Up @@ -414,9 +402,7 @@ def _parse_reply(self):
super()._parse_reply()
num_replies = UINT.decode(self.data)
offset_data = self.data[2 : 2 + 2 * num_replies]
offsets = (
UINT.decode(offset_data[i : i + 2]) for i in range(0, len(offset_data), 2)
)
offsets = (UINT.decode(offset_data[i : i + 2]) for i in range(0, len(offset_data), 2))
start, end = tee(offsets) # split offsets into start/end indexes
next(end) # advance end by 1 so 2nd item is the end index for the first item
reply_data = [self.data[i:j] for i, j in zip_longest(start, end)]
Expand All @@ -429,9 +415,7 @@ def _parse_reply(self):
self.responses.append(response)

def __repr__(self):
return (
f"{self.__class__.__name__}(values={_r(self.values)}, error={self.error!r})"
)
return f"{self.__class__.__name__}(values={_r(self.values)}, error={self.error!r})"


class MultiServiceRequestPacket(SendUnitDataRequestPacket):
Expand Down
Loading

0 comments on commit bfde1c1

Please sign in to comment.