Skip to content

Commit

Permalink
Update for more consistent error raising, formatting (issue dmroeder#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmroeder committed Mar 13, 2019
1 parent 7d51180 commit 704846b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
6 changes: 6 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
03/13/19
-Update for more consistant catching of errors, formatting

03/07/19
-Restructured project, added setup.py for install

02/10/19
-Check status before parsing tag list packets

Expand Down
2 changes: 1 addition & 1 deletion pylogix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .lgxDevice import LGXDevice
from .eip import PLC
__version_info__ = (0, 3, 0)
__version_info__ = (0, 3, 1)
__version__ = '.'.join(str(x) for x in __version_info__)
53 changes: 27 additions & 26 deletions pylogix/eip.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def Read(self, tag, count=1, datatype=None):
'''
if isinstance(tag, list):
if datatype:
raise Exception('Datatype should be set to None when reading lists')
raise TypeError('Datatype should be set to None when reading lists')
return _multiRead(self, tag)
else:
return _readTag(self, tag, count, datatype)
Expand Down Expand Up @@ -234,8 +234,8 @@ def _readTag(self, tag, elements, dt):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Read failed, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Read failed: {}'.format(err))

def _writeTag(self, tag, value, dt):
'''
Expand Down Expand Up @@ -286,8 +286,8 @@ def _writeTag(self, tag, value, dt):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Write failed, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Write Failed: {}'.format(err))

def _multiRead(self, args):
'''
Expand Down Expand Up @@ -338,8 +338,8 @@ def _multiRead(self, args):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Multi-read failed, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Multi-read failed: {}'.format(err))

def _getPLCTime(self):
'''
Expand Down Expand Up @@ -378,8 +378,8 @@ def _getPLCTime(self):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to get PLC time, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to get PLC time: {}'.format(err))

def _setPLCTime(self):
'''
Expand Down Expand Up @@ -416,8 +416,8 @@ def _setPLCTime(self):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to set PLC time, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to set PLC time: {}'.format(err))

def _getTagList(self):
'''
Expand All @@ -438,8 +438,8 @@ def _getTagList(self):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to get tag list, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to get tag list {}'.format(err))

while status == 6:
self.Offset += 1
Expand All @@ -452,8 +452,8 @@ def _getTagList(self):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to get tag list, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to get tag list: {}'.format(err))

return

Expand All @@ -478,8 +478,8 @@ def _getAllProgramsTags(self):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to get program tag list, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to get program tag list: {}'.format(err))

while status == 6:
self.Offset += 1
Expand All @@ -492,8 +492,8 @@ def _getAllProgramsTags(self):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to get program tag list, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to get program tag list: {}'.format(err))

return

Expand All @@ -515,8 +515,8 @@ def _getProgramTagList(self, programName):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to get program tag list, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to get program tag list: {}'.format(err))

while status == 6:
self.Offset += 1
Expand All @@ -529,8 +529,8 @@ def _getProgramTagList(self, programName):
if status in cipErrorCodes.keys():
err = cipErrorCodes[status]
else:
err = 'Unknown error'
raise Exception('Failed to get program tag list, ' + err)
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to get program tag list: {}'.format(err))

return

Expand Down Expand Up @@ -1404,7 +1404,7 @@ def _getReplyValues(self, tag, elements, data):
err = cipErrorCodes[status]
else:
err = 'Unknown error'
return "Failed to read tag: " + tag + ' - ' + err
return 'Failed to read tag: {} - {}'.format(tag, err)

def _getBitOfWord(tag, value):
'''
Expand Down Expand Up @@ -1491,9 +1491,10 @@ def InitialRead(self, tag, baseTag, dt):
return True
else:
if status in cipErrorCodes.keys():
raise ValueError(cipErrorCodes[status])
err = cipErrorCodes[status]
else:
raise ValueError("Failed to read tag: " + tag + ' - unknown error ' + str(status))
err = 'Unknown error {}'.format(status)
raise ValueError('Failed to read tag: {}'.format(err))

def TagNameParser(tag, offset):
'''
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pylogix",
version="0.3.0",
version="0.3.1",
author="Dustin Roeder",
author_email="[email protected]",
description="Read/Write Rockwell Automation Logix based PLC's",
Expand Down

0 comments on commit 704846b

Please sign in to comment.