Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created specific exception class for enip status error #51

Merged
merged 1 commit into from
Apr 26, 2018
Merged
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
9 changes: 7 additions & 2 deletions server/enip/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

__all__ = ['parse_int', 'parse_path', 'parse_path_elements', 'parse_path_component',
'format_path', 'format_context', 'parse_context', 'CIP_TYPES', 'parse_operations',
'client', 'await_response', 'connector', 'recycle', 'main' ]
'client', 'await_response', 'connector', 'recycle', 'main', 'ENIPStatusError' ]


"""enip.client -- EtherNet/IP client API and module entry point
Expand Down Expand Up @@ -70,6 +70,11 @@ def parse_path_component( *args, **kwds ):

log = logging.getLogger( "enip.cli" )

class ENIPStatusError( Exception ):
def __init__(self, status=None):
self.status = status
super( ENIPStatusError, self ).__init__("Response EtherNet/IP status: %d" % ( status ))


def format_path( segments, count=None ):
"""Format some simple path segment lists in a human-readable form. Raises an Exception if
Expand Down Expand Up @@ -1153,7 +1158,7 @@ def collect( self, timeout=None ):
elif not response: # empty response indicates clean EOF
raise StopIteration( "Session terminated" )
elif 'enip.status' in response and response.enip.status != 0:
raise Exception( "Response EtherNet/IP status: %d" % ( response.enip.status ))
raise ENIPStatusError( status=response.enip.status )
elif 'enip.CIP.send_data.CPF.item[1].unconnected_send.request.multiple.request' in response:
# Multiple Service Packet; request.multiple.request is an array of read/write_tag/frag
replies = response.enip.CIP.send_data.CPF.item[1].unconnected_send.request.multiple.request
Expand Down