Skip to content

Commit

Permalink
Added SetPLCTime() to set the PLC clock
Browse files Browse the repository at this point in the history
  • Loading branch information
dmroeder committed Feb 7, 2017
1 parent 5d62a3e commit c7ad84e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ USAGE - Python 2.7.11
Get all Ethernet I/P devices on the network test.Discover()
ex: stuff = test.Discover()
print stuff(1).IPAddress # prints the first devices IP Address

Get or Set the PLC clock: test.GetPLCTime() or test.SetPLCTime()
Note: SetPLCTime() will use your computers clock to set the PLC

6) Close the connection with test.Close()

Expand Down
1 change: 1 addition & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
02/06/17
-Use a different attribute in GetPLCTime()
-Added SetPLCTime() to set the PLC clock

11/23/16
-GetTagList() now includes program scoped tags
Expand Down
37 changes: 37 additions & 0 deletions eip.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def GetPLCTime(self):
'''
return _getPLCTime(self)

def SetPLCTime(self):
'''
Sets the PLC's clock time
'''
return _setPLCTime(self)

def GetTagList(self):
'''
Retrieves the tag list from the PLC
Expand Down Expand Up @@ -273,6 +279,37 @@ def _getPLCTime(self):

return humanTime

def _setPLCTime(self):
'''
Requests the PLC clock time
'''
if not self.SocketConnected: _connect(self)
if not self.SocketConnected: return None

AttributeService = 0x04
AttributeSize = 0x02
AttributeClassType = 0x20
AttributeClass = 0x8B
AttributeInstanceType = 0x24
AttributeInstance = 0x01
AttributeCount = 0x01
Attribute = 0x06
Time = time.time() * 1000000
AttributePacket = pack('<BBBBBBHHQ',
AttributeService,
AttributeSize,
AttributeClassType,
AttributeClass,
AttributeInstanceType,
AttributeInstance,
AttributeCount,
Attribute,
Time)

eipHeader = _buildEIPHeader(self, AttributePacket)
retData = _getBytes(self, eipHeader)
return

def _getTagList(self):
'''
Requests the controller tag list and returns a list of LgxTag type
Expand Down
7 changes: 7 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def ex_getPLCTime():
'''
ret = comm.GetPLCTime()
print ret

def ex_setPLCTime():
'''
set the PLC's clock time to the workstations time
'''
comm.SetPLCTime()

def ex_discover():
'''
Expand Down Expand Up @@ -95,5 +101,6 @@ def ex_getTags():
#ex_multiRead()
#ex_write('ThisTag.Thingy', '107')
#ex_getPLCTime()
#ex_setPLCTime()
#ex_discover()
#ex_getTags()

0 comments on commit c7ad84e

Please sign in to comment.