Skip to content

Commit

Permalink
Created method for returning raw system time. (dmroeder#57)
Browse files Browse the repository at this point in the history
* Created method for returning raw system time.
Human-readable time is now a separate method (but still the default for GetPLCTime()) and uses this new method.

* Added missing "self"

* Added back lines accidentally deleted.
Refactored to remove separate GetRawPLCTime() routine - now GetPLCTime() is still a single
method but with keyword raw=False (default).
  • Loading branch information
dgilbank authored and dmroeder committed Jun 25, 2019
1 parent c2ad216 commit 2fd71c5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pylogix/eip.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def MultiRead(self, tags):
'''
return _multiRead(self, tags)

def GetPLCTime(self):
def GetPLCTime(self, raw=False):
'''
Get the PLC's clock time
Get the PLC's clock time, return as human readable (default) or raw if raw=True
'''
return _getPLCTime(self)
return _getPLCTime(self, raw)

def SetPLCTime(self):
'''
Expand Down Expand Up @@ -348,7 +348,7 @@ def _multiRead(self, tags):
err = 'Unknown error {}'.format(status)
raise ValueError('Multi-read failed: {}'.format(err))

def _getPLCTime(self):
def _getPLCTime(self, raw=False):
'''
Requests the PLC clock time
'''
Expand Down Expand Up @@ -379,6 +379,8 @@ def _getPLCTime(self):
if status == 0:
# get the time from the packet
plcTime = unpack_from('<Q', retData, 56)[0]
if raw:
return plcTime
humanTime = datetime(1970, 1, 1) + timedelta(microseconds=plcTime)
return humanTime
else:
Expand Down

0 comments on commit 2fd71c5

Please sign in to comment.