Skip to content

Commit

Permalink
Raise error for unsupported features, CIP service failures
Browse files Browse the repository at this point in the history
  • Loading branch information
dmroeder committed Oct 24, 2017
1 parent 4bef2bc commit 0d9538c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
10/23/17
-Raise error for unsupported features

10/06/17
-Added Micro8xx support
-Cleaned up formatting of lgxDevice.py
Expand Down
42 changes: 36 additions & 6 deletions eip.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,16 @@ def _readTag(self, tag, elements):

eipHeader = _buildEIPHeader(self, readRequest)
retData = _getBytes(self, eipHeader)
if retData:
status = unpack_from('<h', retData, 48)[0]

if status == 0 or status == 6:
return _parseReply(self, tag, elements, retData)
else:
return None
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Read failed, ' + err)

def _writeTag(self, tag, value):
'''
Expand Down Expand Up @@ -229,7 +235,16 @@ def _writeTag(self, tag, value):

eipHeader = _buildEIPHeader(self, writeRequest)
retData = _getBytes(self, eipHeader)
return
status = unpack_from('<h', retData, 48)[0]

if status == 0:
return
else:
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Write failed, ' + err)

def _multiRead(self, args):
'''
Expand Down Expand Up @@ -268,10 +283,16 @@ def _multiRead(self, args):
readRequest = header+segmentCount+offsets+segments
eipHeader = _buildEIPHeader(self, readRequest)
retData = _getBytes(self, eipHeader)
if retData:
status = unpack_from('<h', retData, 48)[0]

if status == 0:
return MultiParser(self, retData)
else:
return None
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Multi-read failed, ' + err)

def _getPLCTime(self):
'''
Expand Down Expand Up @@ -342,7 +363,16 @@ def _setPLCTime(self):

eipHeader = _buildEIPHeader(self, AttributePacket)
retData = _getBytes(self, eipHeader)
return
status = unpack_from('<h', retData, 48)[0]

if status == 0:
return
else:
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to set PLC time, ' + err)

def _getTagList(self):
'''
Expand Down

0 comments on commit 0d9538c

Please sign in to comment.