How do I talk Python to it? (and when not to) Table of Contents https: // jonasneubert.com / nbpy2019 @jonemo Q: What was THE acronym “PLC” for again? A: Programmable Logic Controller slides: twitter:
at Wikimedia Commons (CC-BY-SA 3.0 Unported) https://commons.wikimedia.org/wiki/File:Siemens_Logo.jpg Photo of Beckhoff CX by Beckhoff Automation GmbH at Wikimedia Commons (CC-BY-SA-3.0-DE) https://commons.wikimedia.org/wiki/File:Embedded-PC_Beckhoff_CX1020.jpg This is what a PLC looks like* “Modular” Backplane with fixed number of slots “Expansible” Infinitely* stackable modules * when it’s new
Scan Step 3: Output Scan Read process variables from Field Instruments into PLC memory Create “Process Image In” (PII) Execute application program (this is the Programmable Logic!) Creates “Process Image Out (PIQ)” STEP 2 is the one we have control over! Read “Process Image Out” (PIQ) Set output signals
Control Loops of “Industrial Internet of Things” Field Devices PLC Python Code “Inner Loop” “Outer Loop” milliseconds per iteration interfaces to the physical world timing critical & safety critical logic release process might be regulated minutes to months per iteration interfaces to databases and APIs optimization & customization regular software release cycle a.k.a. Industry 4.0
[unnamed?] Vendor/Brand Allen Bradley Siemens S7 Series Beckhoff Koyo (Autom. Direct) Allen Bradley Unitronics Fatek Python libraries pycomm python-snap7 chwiede.pyads bfabio.pyads, adshli, pyads clickplc df1 pcom fatek-fbs-lib Technology Ethernet + TCP/IP Ethernet + TCP/IP Ethernet + TCP/IP RS-232/485 RS-232/485 Ethernet + TCP/IP Ethernet + TCP/IP see also: http://blog.jonasneubert.com/2019/04/27/list-of-plc-brand-names-and-products/ and “List of PLC Manufacturers“ on Wikipedia Best Case Scenario: You’re using one of these PLC BrAnds Otherwise: go to next slide Difficulty Level 1: pip-install-let’s-see-what-happens
pyads.PLCTYPE_BOOL) # → False plc.write_by_name('GLOBAL.YELLOW_DURATION', 300, pyads.PLCTYPE_INT) @plc.notification(pyads.PLCTYPE_BOOL) def callback(handle, name, timestamp, value): print(f"Notification: {name} has new value {value}") plc.add_device_notification('GLOBAL.PEDESTRIAN_WAITING', callback) Reference Variables by Name
pyads.PLCTYPE_BOOL) # → False plc.write_by_name('GLOBAL.YELLOW_DURATION', 300, pyads.PLCTYPE_INT) @plc.notification(pyads.PLCTYPE_BOOL) def callback(handle, name, timestamp, value): print(f"Notification: {name} has new value {value}") plc.add_device_notification('GLOBAL.PEDESTRIAN_WAITING', callback) Subscription to value changes
OPC-UA Python libraries pymodbus, pyModbusTCP, cpppo pycomm, cpppo GH: devkid/profinet opcua, asyncua, opcua-client (GUI), opcua-webclient Technology Ethernet + TCP/IP Ethernet + TCP/IP Ethernet + TCP/IP Ethernet + TCP/IP see also: “List of Automation Protocols“ on Wikipedia Difficulty Level 2: Ethernet cables and IP addresses … and many more with no existing Python libraries. You can DIY an implementation using sockets and ctypes from the Python standard library! Our old friend modbus lives on this slide!
Difficulty Level 3: Networking without IP addresses . No Python support: CC-Link IE, Ethernet Powerlink, PROFINET, Ethernet/IP SERCOS III. Utility libraries like rawsocketpy and dnet are handy for implementing Ethernet-but-not-TCP/IP protocols.
OPC-UA) Python libraries pyprofibus canopen j1939 OpenOPC Technology RS-232/485 CAN bus CAN bus Windows OLE Difficulty Level 4: What are these weird cables? These protocols use cables and connectors that require converters or other specialized hardware in order to connect to most computers made in the 2010s. pyserial is the canonical tool for working with RS-232 and RS-485, python-can is a common starting point for working with CAN bus. Photo of RS-485 connector by Gerben Wierda on Flickr (CC-BY-SA-2.0) https://www.flickr.com/photos/45480083@N03/4227669345/
approximately If you want to do this: Try out ladder logic Try software the pros use Program your like a PLC Buy a cheap “real” PLC Hack some real gear Learn about the market leaders Contribute to a Python project Own a traffic signal Then take a look at that: OpenPLC, plcfiddle.com List of free software in appendix Codesys for , OpenPLC Automation Direct, Siemens Logo! Ebay1, industrial surplus sales Allen Bradley (US), Siemens (Europe) FreeOpcUA, package list in appendix County/state surplus auctions, Ebay 1 On Ebay, this is where you want to look: Business & Industrial → Automation, Motors & Drives → Control Systems & PLCs → PLC Processors free free $70 $200 $500 — — $250
work with me? https://www.zymergen.com/careers/ Watching this on Youtube? The best ways to contact me are Twitter (@jonemo) and email ([email protected]) Thank you
Codesys — editor is free download, addons and device-specific runtimes are not free Inforteam OpenPCS — same concept and pricing model as Codesys, but smaller market share logi.CAD3 — base edition is free download OpenPLC — open source Vendor/brand specific software platforms Beckhoff Twincat — trial license may be renewed indefinitely for personal use ABB — free basic version Vendors whose programming software is generally free: Automation Direct, Bedrock Automation, Phoenix Contact, Unistream. Generally, smaller brands offer cheap or free software while market leaders use software as a revenue stream. Avoid over-simplified “basic editions” that don’t resemble the full version or don’t use IEC-61131-3 languages, for example Allen Bradley’s “Connected Components Workbench”. Software with free trial versions that have reasonable limitations Siemens TIA Portal — 21 day free trial, requires registration Schneider Electric EcoStruxure Machine Expert — 42 day free trial Panasonic — limits program complexity, no time limit Keyence — only opens 50 times