Giter Club home page Giter Club logo

pylogix's Introduction

****************************************
USAGE - Python 2.7.11
****************************************

1) from eip import PLC

2) test = PLC()

3) Set the IP Address: test.IPAddress = "192.168.1.10"

4) If your processor is in a slot other than 0, set that: test.ProcessorSlot = 1

5) Do one of the following:

    Read a value:  value = test.Read("tagname")
	ex: value = test.Read("MyTimer.ACC")
		    print value
	
    Read an array: value = test.Read("tagname", length)
	ex: value = test.Read("MyDINT", 10)
		    print value(3)
		    
    Read multiple tags at once: test.MultiRead("tag1", "tag2", "tag3")
	ex: values = test.MultiRead("MyDINT", "MyTimer.ACC", "AnotherDINT")
	    print values
		    
    Write a value: test.Write("tagname", value)
	ex: test.Write("MyDINT", 1337)
	
    Get the controller scoped tags
	ex: tags = test.GetTagList()
	    (returns a structure of .TagName, .DataType and .Offset)
	
    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()
		    
So a complete script to read a tag would look like this:

from eip import PLC
test = PLC()
test.IPAddress = "192.168.1.64"
value = test.Read("MyTimer.ACC")
print value
test.Close()


Another method is by using a with statement:

from eip import PLC
with PLC() as test:
    test.IPAddress = "192.168.1.64"
    print test.Read("MyTimer.ACC")




****************************************
NOTES
****************************************

Several things take place when making a connection to a PLC.

1) Standard TCP connection
2) Session Registration, PLC will respond with a Session Handle
3) Forward Open.  Using the Session Handle, this establishes
        the parameters for connection
4) Command (read/write/etc) and payload

The initial connections (TCP, Session Registration, Forward Open)
    only need to be made once, after that, we can exchange data
    until the connection is closed or lost.

A number events that take place on the command end, they should
    be invisible to the user, but it's good to know (and a reminder for me).
    The user can be reading/writing simple tags, UDT's arrays, bits of a word,
    bools out of atomic arrays, custom length strings, array reads that
    won't fit in a single reply and so on.  Each has to be handled in a
    different way.

    It basically happens like this:  Figure out if its a single tag to be
    read/written or an array.  Open the connection to the PLC (1,2,3 above),
    parse the tag name, add the command (read/write), send the data to the PLC,
    handle the reply

In order to perform a typical read/write, the data type needs to be known, or
    more specifically, the number of bytes the tag is.  It would be pretty
    annoying for the user to have to specify this each time, so to get around
    this, we have the InitialRead function.  This is called on any data exchange
    where the tag name has never been read/written before.  It uses a different
    CIP command than a typical read (0x52 vs 0x4C) which will respond with the
    data type.  This helps us in two ways:  First, the user won't need to specify
    the data type.  Second, we can keep track of this information so the next
    time the particular tag is called, we already know it's type so we can just
    do the normal read/write (0x4C/0x4D/0x4E).

pylogix's People

Contributors

dmroeder avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.