Skip to content

Commit 0e9fa4b

Browse files
authored
Merge pull request #51 from pjkundert/feature-enip-status-error-exception
Created specific exception class for enip status error
2 parents 3504223 + e0a99d5 commit 0e9fa4b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

server/enip/client.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
__all__ = ['parse_int', 'parse_path', 'parse_path_elements', 'parse_path_component',
2929
'format_path', 'format_context', 'parse_context', 'CIP_TYPES', 'parse_operations',
30-
'client', 'await_response', 'connector', 'recycle', 'main' ]
30+
'client', 'await_response', 'connector', 'recycle', 'main', 'ENIPStatusError' ]
3131

3232

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

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

73+
class ENIPStatusError( Exception ):
74+
def __init__(self, status=None):
75+
self.status = status
76+
super( ENIPStatusError, self ).__init__("Response EtherNet/IP status: %d" % ( status ))
77+
7378

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

0 commit comments

Comments
 (0)