anekrasov / pylogix Goto Github PK
View Code? Open in Web Editor NEWThis project forked from dmroeder/pylogix
Read/Write data from Allen Bradley Compact/Control Logix PLC's
License: Apache License 2.0
This project forked from dmroeder/pylogix
Read/Write data from Allen Bradley Compact/Control Logix PLC's
License: Apache License 2.0
**************************************** 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).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.