SlideShare a Scribd company logo
1 of 52
Moderator
Don Pearson
Chief Strategy Officer
Inductive Automation
Today’s Agenda
• Introduction to Ignition
• Things to Remember When Scripting
• Scripting Best Practices
• Q&A
About Inductive Automation
• Founded in 2003
• HMI, SCADA, MES, and IIoT software
• Installed in 100+ countries
• Over 1,500 integrators
• Used by 44% of Fortune 100 companies
Learn more at: inductiveautomation.com/about
Used By Industries Worldwide
Ignition: Industrial Application Platform
One Universal Platform for SCADA, MES & IIoT:
• Unlimited licensing model
• Cross-platform compatibility
• Based on IT-standard technologies
• Scalable server-client architecture
• Web-managed
• Web-launched on desktop or mobile
• Modular configurability
• Rapid development and deployment
Presenter
Kevin McClusky
Co-Director of Sales Engineering,
Inductive Automation
Why Scripting Exists
• It’s possible to create complete, powerful projects with HMI/SCADA
software without writing code
• However, many designers find that to complete all project
requirements, they need to use scripting.
• Typically, 80-90% of required functionality can be accomplished
through native features. Scripting exists to fill the other 10-20%.
Why Use Scripting?
• More flexibility
• Extend the logic
• Do more with the product than what’s built into it
• But it has to be used in the right way
When to Use Scripting and When Not To
• Use scripting when you simply can’t accomplish a requirement with
built-in tools.
• Don’t just use scripting for scripting’s sake.
• You may want to ask other users in forums or call tech support.
• Scripting can make it more difficult for another engineer to
understand, so make sure it is applicable and comment your code.
When to Use Scripting: Examples
• Exporting data through scripting that wasn’t built-in to binding or
component
• Custom calculations
When Not to Use Scripting: Examples
• Dynamic SQL query in binding vs. scripting
• Logging data (contextually) from a tag change script when you can
use transaction groups
Which Scripting Language?
Best programming languages to use:
• Use the scripting language that comes with your HMI, SCADA, IIoT
or MES platform.
• Although scripting outside the platform may be possible, it’s best to
use native scripting tools because it eases maintainability and has
the fullest possible integration with the platform.
Understanding Where and When Your Script is Running
• Extremely important to know exactly where and when your code is
running
• Requires knowledge of the software platform you are using
• Avoid unnecessary code from running and performing duplicate
work
Understanding Where and When Your Script is Running
• Where scripts run in Ignition:
• Gateway (server)
• Client
• When scripts run in Ignition:
• Timer
• Tag change
• User in client (button press)
• SFC
• Alarm pipeline
• Etc.
Organization and Standards
• Develop a code standard and be consistent
• Organize well and make sure folders, functions & variables are
named appropriately
• Avoid language shortcuts
• Indent style (tabs or spaces)
• Programming style
• Comment conventions
• Naming conventions
Organization and Standards
• Develop a code standard and be consistent
• Organize well and make sure folders, functions & variables are
named appropriately
• Avoid language shortcuts
• Indent style (tabs or spaces)
• Programming style
• Comment conventions
• Naming conventions
Organization and Standards
• Avoid language shortcuts (example)
1. Example with shortcut:
numbers = [1,2,3,4,5,6]
even = [number for number in numbers if number%2 == 0]
2. Example without:
numbers = [1,2,3,4,5,6]
even = []
for number in numbers:
if number%2 == 0:
even.append(number)
Organization and Standards
• Develop a code standard and be consistent
• Organize well and make sure folders, functions & variables are
named appropriately
• Avoid language shortcuts
• Indent style (tabs or spaces)
• Programming style
• Comment conventions
• Naming conventions
Commenting Code
• A comment is a programmer-readable explanation or annotation in
the source code.
• Added to make the source code easier for humans to understand,
generally ignored by compilers and interpreters.
• You need to do it!
• Helps the next developers and makes code easier to understand
and troubleshoot
Commenting Code (Examples)
• Individual Lines:
# this is a comment
print 'Hello world' # this is also a valid comment
• Blocks of Lines:
'''
This is a lot of text
that you want to show as multiple lines of
comments
Script written by Professor X.
Jan 5, 1990
'''
print 'Hello world'
Commenting Code (Examples)
• Use the Ctrl-/ keyboard shortcut to comment several lines of code at
once. Just highlight one or more lines of code and hold the Ctrl key
and press /
Organization and Standards
• Develop a code standard and be consistent
• Organize well and make sure folders, functions & variables are
named appropriately
• Avoid language shortcuts
• Indent style (tabs or spaces)
• Programming style
• Comment conventions
• Naming conventions
Best Practice: Variables
• Use naming conventions
• Define variables at the top of the script
Example:
name = event.source.parent.getComponent('Name').text
desc = event.source.parent.getComponent('Description').text
building = event.source.parent.getComponent('Building').selectedValue
id = system.db.runPrepUpdate("INSERT INTO machines (machine_name,
description) VALUES (?, ?)", [name, desc])
Best Practice: Define Scripting Functions
• Functions are code that can be called repeatedly from other places
• Can have parameters passed into them, and may return a resulting
value
• Types of functions:
1. Built-in to the language, like len()
2. Part of software package, like system.gui.getMessageBox() for
Ignition
3. Provided by language standard library, like math.sqrt()
4. User-defined functions
Best Practice: Define Scripting Functions
Benefits:
• Keeps code organized
• Easier to find and troubleshoot
• Keeps windows and tags cleaner
• Ability to re-use
Best Practice: Define Scripting Functions
• Default values for arguments (keyword arguments)
Argument specified by position:
print checkBounds(150, 0, 250)
Argument specified by keyword:
print checkBounds(150, range=250)
Best Practice: Define Scripting Functions
• Variable arguments (*args and **kwargs)
Example:
def add(firstValue, *args):
finalValue = firstValue
for value in args:
finalValue = finalValue + value
return finalValue
def checkBounds(value, offset=0, range=200):
if value + offset > range:
return true
else:
return false
Best Practice: Exception Handling
• Exceptions are errors detected during execution
• Not unconditionally fatal
• Most exceptions aren't handled by programs
• You can write programs that handle exceptions
Example:
try:
window = system.gui.getWindow('Overview')
system.gui.closeWindow(window)
except:
system.gui.warningBox("The Overview window isn't open")
Best Practice: Error Console
• One of the most important troubleshooting tools of any package
• Shows a wealth of information about the running state of the
system, system errors, and errors from custom scripts
• Depending on where your script is running, there may be a different
console
• Clear up any known errors
Best Practice: Error Console
Tips:
• Know how long your script takes (Log start, end, and duration)
• Use loggers effectively to troubleshoot your code (debug vs. info vs.
warn vs. error)
Best Practice: Loops
• When to use loops:
- Dealing with multiple items
- Iterating over finite list
• When not to use loops:
- To make your code wait (use a timing mechanism
instead)
Best Practice: Loops
• Stay away from infinite loops (While True or long for loops)
• Use breaks effectively (Don’t do unnecessary work)
Example:
found = False
for row in result:
if row[“name”] == “MyName”:
found = True
break
Best Practice: Timers
• Timers run at a set interval 24x7
• Understanding fixed rate vs. fixed delay:
◦ Fixed delay timer script (default) waits for given delay between
each script invocation. The script's rate will be the delay plus the
time it takes to execute the script. This is the safest option.
◦ Fixed rate scripts attempt to run the script at a fixed rate relative
to the first execution. If script takes too long, or there is too much
background process, this may not be possible.
Best Practice: Timers
• Avoid scripts that run quickly that fill up queues
(such as tag writes)
• Provide ability to enable/disable through a setting
(such as a memory tag)
Best Practice: Tag Change
• Tag change scripts run when the value or quality of a tag
changes.
• Make sure to check the quality of the tag. It is possible the
value didn’t change but the quality did. Don’t run code at
the wrong times.
• You may want to check the value, and whether the value is
different from the previous value.
• Decide whether you want the script to run initially (when
the server reboots)
Best Practice: Avoid Race Conditions
• Race condition or race hazard: the behavior of a system
where the output is dependent on the sequence or timing
of other uncontrollable events
• Expect one script to be completed before running the other
• Becomes a bug when events do not happen in the order
the programmer intended
• Typically due to asynchronous problems (tags, properties)
Best Practice: Avoid Race Conditions
Examples:
• A propertyChange script that refers to two properties but is
only filtered on one. The second property may not have
updated. Instead try to put in a single property, if possible,
or run the code multiple times, looking at all props.
• Writing to a tag and reading the tag on the next line
Best Practice: Understand Threading
• A lot of languages, such as Java, are multi-threaded
• Two or more parts that can run concurrently, and each part
can handle a different task at the same time.
Best Practice: Understand Threading
• Are scripts running in a shared or dedicated thread?
• Scripts running in a shared thread will all execute in the
same thread. This is usually desirable, to prevent creating
unnecessary threads. However, scripts that take a long
time to run will block other scripts on the shared thread.
Best Practice: Understand Threading
• Rule of thumb: quick-running tasks should run in the
shared thread, and long-running tasks should get their own
thread.
• Understand what else could be affected if running in the
same thread
Best Practice: Understand Threading
UI thread vs separate thread (asynchronous)
• UI can hang
• Use progress bars instead (asynchronous)
• Callbacks to the UI thread invokeLater
Other Tips: Restoring Backups on Other Machines
• Scripts could be running in two places
• Make sure to restore disabled or have a code check if it is
a certain machine (by IP or hostname).
Other Tips: Scripting Timesavers
• Software package functions vs. libraries
• Language functions vs. custom code (example: the Python
CSV library)
Recap - Things to Remember When Scripting:
• Understand the basic purpose of scripting
• Know when to use scripting and when not to
• Understand where and when your script is running
• Use organization and standards
• Include comments in your code
Recap of Scripting Best Practices:
• Use variable naming conventions
• Define common functions
• Use exception handling
• Use the error console
• Avoid infinite loops
• Use appropriate threads with timers
• Plan tag change scripts
• Avoid race conditions
• Understand threading
One Last Tip …
Looking for some scripting help? Here are a few good resources:
• User forum at: www.inductiveautomation.com/forum
• Python language tutorial: www.python-course.eu/course.php
Design Like a Pro Series
Available at: inductiveautomation.com/resources
Questions & Comments
Jim Meisler x227
Vannessa Garcia x231
Vivian Mudge x253
Account Executives
Myron Hoertling x224
Shane Miller x218
Ramin Rofagha x251
Maria Chinappi x264
Dan Domerofski x273
Lester Ares x214
800-266-7798 x247
Melanie Moniz
Director of Sales:
Jeff Osterback x207
Design Like a Pro: Scripting Best Practices

More Related Content

What's hot

Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsInductive Automation
 
Design Like a Pro: Basics of Building Mobile-Responsive HMIs
Design Like a Pro: Basics of Building Mobile-Responsive HMIsDesign Like a Pro: Basics of Building Mobile-Responsive HMIs
Design Like a Pro: Basics of Building Mobile-Responsive HMIsInductive Automation
 
Fixing SCADA: How Ignition Saves Time
Fixing SCADA: How Ignition Saves TimeFixing SCADA: How Ignition Saves Time
Fixing SCADA: How Ignition Saves TimeInductive Automation
 
The New Ignition v7.9 - See, Maintain, and Manage Your Enterprise With Ease
The New Ignition v7.9 - See, Maintain, and Manage Your Enterprise With EaseThe New Ignition v7.9 - See, Maintain, and Manage Your Enterprise With Ease
The New Ignition v7.9 - See, Maintain, and Manage Your Enterprise With EaseInductive Automation
 
How to Quickly Create Effective Plant-Floor Screens
How to Quickly Create Effective Plant-Floor ScreensHow to Quickly Create Effective Plant-Floor Screens
How to Quickly Create Effective Plant-Floor ScreensInductive Automation
 
Fixing SCADA: How Ignition Saves Money
Fixing SCADA: How Ignition Saves MoneyFixing SCADA: How Ignition Saves Money
Fixing SCADA: How Ignition Saves MoneyInductive Automation
 
Top 10 Design & Security Tips to Elevate Your SCADA System
Top 10 Design & Security Tips to Elevate Your SCADA SystemTop 10 Design & Security Tips to Elevate Your SCADA System
Top 10 Design & Security Tips to Elevate Your SCADA SystemInductive Automation
 
Design Like a Pro: Building Better HMI Navigation Schemes
Design Like a Pro: Building Better HMI Navigation SchemesDesign Like a Pro: Building Better HMI Navigation Schemes
Design Like a Pro: Building Better HMI Navigation SchemesInductive Automation
 
Design Like a Pro - Best Practices For IIoT
Design Like a Pro - Best Practices For IIoTDesign Like a Pro - Best Practices For IIoT
Design Like a Pro - Best Practices For IIoTInductive Automation
 
Leveraging Operational Data in the Cloud
Leveraging Operational Data in the CloudLeveraging Operational Data in the Cloud
Leveraging Operational Data in the CloudInductive Automation
 
July webinar slides industry 4.0 view from the front lines
July webinar slides industry 4.0  view  from the front linesJuly webinar slides industry 4.0  view  from the front lines
July webinar slides industry 4.0 view from the front linesInductive Automation
 
Design Like a Pro: How to Pick the Right System Architecture
Design Like a Pro: How to Pick the Right System ArchitectureDesign Like a Pro: How to Pick the Right System Architecture
Design Like a Pro: How to Pick the Right System ArchitectureInductive Automation
 
10 Steps to Architecting a Sustainable SCADA System
10 Steps to Architecting a Sustainable SCADA System10 Steps to Architecting a Sustainable SCADA System
10 Steps to Architecting a Sustainable SCADA SystemInductive Automation
 
Common Project Mistakes: Visualization, Alarms, and Security
Common Project Mistakes: Visualization, Alarms, and SecurityCommon Project Mistakes: Visualization, Alarms, and Security
Common Project Mistakes: Visualization, Alarms, and SecurityInductive Automation
 
Real Tools for Digital Transformation
Real Tools for Digital TransformationReal Tools for Digital Transformation
Real Tools for Digital TransformationInductive Automation
 
Bringing Digital Transformation Into Focus
Bringing Digital Transformation Into FocusBringing Digital Transformation Into Focus
Bringing Digital Transformation Into FocusInductive Automation
 
Fixing SCADA: How Ignition Reduces Frustration
Fixing SCADA: How Ignition Reduces FrustrationFixing SCADA: How Ignition Reduces Frustration
Fixing SCADA: How Ignition Reduces FrustrationInductive Automation
 
6 Simple Steps to Enterprise Digital Transformation
6 Simple Steps to Enterprise Digital Transformation6 Simple Steps to Enterprise Digital Transformation
6 Simple Steps to Enterprise Digital TransformationInductive Automation
 

What's hot (20)

Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise Solutions
 
Design Like a Pro: Basics of Building Mobile-Responsive HMIs
Design Like a Pro: Basics of Building Mobile-Responsive HMIsDesign Like a Pro: Basics of Building Mobile-Responsive HMIs
Design Like a Pro: Basics of Building Mobile-Responsive HMIs
 
Fixing SCADA: How Ignition Saves Time
Fixing SCADA: How Ignition Saves TimeFixing SCADA: How Ignition Saves Time
Fixing SCADA: How Ignition Saves Time
 
The New Ignition v7.9 - See, Maintain, and Manage Your Enterprise With Ease
The New Ignition v7.9 - See, Maintain, and Manage Your Enterprise With EaseThe New Ignition v7.9 - See, Maintain, and Manage Your Enterprise With Ease
The New Ignition v7.9 - See, Maintain, and Manage Your Enterprise With Ease
 
How to Quickly Create Effective Plant-Floor Screens
How to Quickly Create Effective Plant-Floor ScreensHow to Quickly Create Effective Plant-Floor Screens
How to Quickly Create Effective Plant-Floor Screens
 
Fixing SCADA: How Ignition Saves Money
Fixing SCADA: How Ignition Saves MoneyFixing SCADA: How Ignition Saves Money
Fixing SCADA: How Ignition Saves Money
 
Top 10 Design & Security Tips to Elevate Your SCADA System
Top 10 Design & Security Tips to Elevate Your SCADA SystemTop 10 Design & Security Tips to Elevate Your SCADA System
Top 10 Design & Security Tips to Elevate Your SCADA System
 
Design Like a Pro: Building Better HMI Navigation Schemes
Design Like a Pro: Building Better HMI Navigation SchemesDesign Like a Pro: Building Better HMI Navigation Schemes
Design Like a Pro: Building Better HMI Navigation Schemes
 
Design Like a Pro - Best Practices For IIoT
Design Like a Pro - Best Practices For IIoTDesign Like a Pro - Best Practices For IIoT
Design Like a Pro - Best Practices For IIoT
 
Leveraging Operational Data in the Cloud
Leveraging Operational Data in the CloudLeveraging Operational Data in the Cloud
Leveraging Operational Data in the Cloud
 
July webinar slides industry 4.0 view from the front lines
July webinar slides industry 4.0  view  from the front linesJuly webinar slides industry 4.0  view  from the front lines
July webinar slides industry 4.0 view from the front lines
 
Design Like a Pro: How to Pick the Right System Architecture
Design Like a Pro: How to Pick the Right System ArchitectureDesign Like a Pro: How to Pick the Right System Architecture
Design Like a Pro: How to Pick the Right System Architecture
 
10 Steps to Architecting a Sustainable SCADA System
10 Steps to Architecting a Sustainable SCADA System10 Steps to Architecting a Sustainable SCADA System
10 Steps to Architecting a Sustainable SCADA System
 
Common Project Mistakes: Visualization, Alarms, and Security
Common Project Mistakes: Visualization, Alarms, and SecurityCommon Project Mistakes: Visualization, Alarms, and Security
Common Project Mistakes: Visualization, Alarms, and Security
 
Real Tools for Digital Transformation
Real Tools for Digital TransformationReal Tools for Digital Transformation
Real Tools for Digital Transformation
 
Bringing Digital Transformation Into Focus
Bringing Digital Transformation Into FocusBringing Digital Transformation Into Focus
Bringing Digital Transformation Into Focus
 
Fixing SCADA: How Ignition Reduces Frustration
Fixing SCADA: How Ignition Reduces FrustrationFixing SCADA: How Ignition Reduces Frustration
Fixing SCADA: How Ignition Reduces Frustration
 
Mobility Meets Manufacturing
Mobility Meets ManufacturingMobility Meets Manufacturing
Mobility Meets Manufacturing
 
6 Simple Steps to Enterprise Digital Transformation
6 Simple Steps to Enterprise Digital Transformation6 Simple Steps to Enterprise Digital Transformation
6 Simple Steps to Enterprise Digital Transformation
 
ENPAQ Brochure
ENPAQ BrochureENPAQ Brochure
ENPAQ Brochure
 

Similar to Design Like a Pro: Scripting Best Practices

Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to WorkSingleStore
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Getting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosGetting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosEmmett Ross
 
Desired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptxDesired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptx4132lenin6497ram
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET Dmytro Mindra
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelinesAnkur Goyal
 
Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Maven Logix
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)Yogesh Deshpande
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem slovingMani Kandan
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review ProcessDr. Syed Hassan Amin
 
Ni week 2018 LLAMA presentation
Ni week 2018 LLAMA presentationNi week 2018 LLAMA presentation
Ni week 2018 LLAMA presentationDMC, Inc.
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxAliyahAli19
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?GetInData
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programmingJuggernaut Liu
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium SuccessfullyDave Haeffner
 

Similar to Design Like a Pro: Scripting Best Practices (20)

Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to Work
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Coding
CodingCoding
Coding
 
Code Inspection
Code InspectionCode Inspection
Code Inspection
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
Getting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosGetting started with CATIA V5 Macros
Getting started with CATIA V5 Macros
 
Desired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptxDesired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptx
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
Ni week 2018 LLAMA presentation
Ni week 2018 LLAMA presentationNi week 2018 LLAMA presentation
Ni week 2018 LLAMA presentation
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 

More from Inductive Automation

De-Risk Your Digital Transformation — And Reduce Time, Cost & Complexity
De-Risk Your Digital Transformation — And Reduce Time, Cost & ComplexityDe-Risk Your Digital Transformation — And Reduce Time, Cost & Complexity
De-Risk Your Digital Transformation — And Reduce Time, Cost & ComplexityInductive Automation
 
Overcoming Digital Transformation Pain Points
Overcoming Digital Transformation Pain PointsOvercoming Digital Transformation Pain Points
Overcoming Digital Transformation Pain PointsInductive Automation
 
How Ignition Eases SCADA Pain Points
How Ignition Eases SCADA Pain PointsHow Ignition Eases SCADA Pain Points
How Ignition Eases SCADA Pain PointsInductive Automation
 
Solving Data Problems to Accelerate Digital Transformation.pptx
Solving Data Problems to Accelerate Digital Transformation.pptxSolving Data Problems to Accelerate Digital Transformation.pptx
Solving Data Problems to Accelerate Digital Transformation.pptxInductive Automation
 
Security Best Practices for Your Ignition System
Security Best Practices for Your Ignition SystemSecurity Best Practices for Your Ignition System
Security Best Practices for Your Ignition SystemInductive Automation
 
Turn Any Panel PC Into an Ignition HMI
Turn Any Panel PC Into an Ignition HMITurn Any Panel PC Into an Ignition HMI
Turn Any Panel PC Into an Ignition HMIInductive Automation
 
5 Mobile-Responsive Layout Strategies
5 Mobile-Responsive Layout Strategies5 Mobile-Responsive Layout Strategies
5 Mobile-Responsive Layout StrategiesInductive Automation
 
Integrators Explore the Road Ahead
Integrators Explore the Road AheadIntegrators Explore the Road Ahead
Integrators Explore the Road AheadInductive Automation
 
The Art of Displaying Industrial Data
The Art of Displaying Industrial DataThe Art of Displaying Industrial Data
The Art of Displaying Industrial DataInductive Automation
 
Common Project Mistakes (And How to Avoid Them)
Common Project Mistakes (And How to Avoid Them)Common Project Mistakes (And How to Avoid Them)
Common Project Mistakes (And How to Avoid Them)Inductive Automation
 
Choosing a SCADA System for the IIoT Era
Choosing a SCADA System for the IIoT Era Choosing a SCADA System for the IIoT Era
Choosing a SCADA System for the IIoT Era Inductive Automation
 
The Evolution of Industrial Visualization
The Evolution of Industrial VisualizationThe Evolution of Industrial Visualization
The Evolution of Industrial VisualizationInductive Automation
 
Historic Opportunities: Discover the Power of Ignition's Historian
Historic Opportunities: Discover the Power of Ignition's HistorianHistoric Opportunities: Discover the Power of Ignition's Historian
Historic Opportunities: Discover the Power of Ignition's HistorianInductive Automation
 
Unlocking Greater Efficiency: The Why and How of OEE Implementation
Unlocking Greater Efficiency: The Why and How of OEE ImplementationUnlocking Greater Efficiency: The Why and How of OEE Implementation
Unlocking Greater Efficiency: The Why and How of OEE ImplementationInductive Automation
 
Leveraging Ignition Quick Start to Rapidly Build Real Projects
Leveraging Ignition Quick Start to Rapidly Build Real ProjectsLeveraging Ignition Quick Start to Rapidly Build Real Projects
Leveraging Ignition Quick Start to Rapidly Build Real ProjectsInductive Automation
 
Design Like a Pro: Developing & Deploying Perspective Applications as HMIs
Design Like a Pro: Developing & Deploying Perspective Applications as HMIsDesign Like a Pro: Developing & Deploying Perspective Applications as HMIs
Design Like a Pro: Developing & Deploying Perspective Applications as HMIsInductive Automation
 
Integrator Discussion: Leading Through Innovation During COVID-19 and Beyond
Integrator Discussion: Leading Through Innovation During COVID-19 and BeyondIntegrator Discussion: Leading Through Innovation During COVID-19 and Beyond
Integrator Discussion: Leading Through Innovation During COVID-19 and BeyondInductive Automation
 
Ignition Community Live with Carl Gould & Colby Clegg
Ignition Community Live with Carl Gould & Colby CleggIgnition Community Live with Carl Gould & Colby Clegg
Ignition Community Live with Carl Gould & Colby CleggInductive Automation
 

More from Inductive Automation (20)

De-Risk Your Digital Transformation — And Reduce Time, Cost & Complexity
De-Risk Your Digital Transformation — And Reduce Time, Cost & ComplexityDe-Risk Your Digital Transformation — And Reduce Time, Cost & Complexity
De-Risk Your Digital Transformation — And Reduce Time, Cost & Complexity
 
Overcoming Digital Transformation Pain Points
Overcoming Digital Transformation Pain PointsOvercoming Digital Transformation Pain Points
Overcoming Digital Transformation Pain Points
 
How Ignition Eases SCADA Pain Points
How Ignition Eases SCADA Pain PointsHow Ignition Eases SCADA Pain Points
How Ignition Eases SCADA Pain Points
 
New Ignition Features In Action
New Ignition Features In ActionNew Ignition Features In Action
New Ignition Features In Action
 
Solving Data Problems to Accelerate Digital Transformation.pptx
Solving Data Problems to Accelerate Digital Transformation.pptxSolving Data Problems to Accelerate Digital Transformation.pptx
Solving Data Problems to Accelerate Digital Transformation.pptx
 
Security Best Practices for Your Ignition System
Security Best Practices for Your Ignition SystemSecurity Best Practices for Your Ignition System
Security Best Practices for Your Ignition System
 
Turn Any Panel PC Into an Ignition HMI
Turn Any Panel PC Into an Ignition HMITurn Any Panel PC Into an Ignition HMI
Turn Any Panel PC Into an Ignition HMI
 
5 Mobile-Responsive Layout Strategies
5 Mobile-Responsive Layout Strategies5 Mobile-Responsive Layout Strategies
5 Mobile-Responsive Layout Strategies
 
Integrators Explore the Road Ahead
Integrators Explore the Road AheadIntegrators Explore the Road Ahead
Integrators Explore the Road Ahead
 
The Art of Displaying Industrial Data
The Art of Displaying Industrial DataThe Art of Displaying Industrial Data
The Art of Displaying Industrial Data
 
Common Project Mistakes (And How to Avoid Them)
Common Project Mistakes (And How to Avoid Them)Common Project Mistakes (And How to Avoid Them)
Common Project Mistakes (And How to Avoid Them)
 
First Steps to DevOps
First Steps to DevOpsFirst Steps to DevOps
First Steps to DevOps
 
Choosing a SCADA System for the IIoT Era
Choosing a SCADA System for the IIoT Era Choosing a SCADA System for the IIoT Era
Choosing a SCADA System for the IIoT Era
 
The Evolution of Industrial Visualization
The Evolution of Industrial VisualizationThe Evolution of Industrial Visualization
The Evolution of Industrial Visualization
 
Historic Opportunities: Discover the Power of Ignition's Historian
Historic Opportunities: Discover the Power of Ignition's HistorianHistoric Opportunities: Discover the Power of Ignition's Historian
Historic Opportunities: Discover the Power of Ignition's Historian
 
Unlocking Greater Efficiency: The Why and How of OEE Implementation
Unlocking Greater Efficiency: The Why and How of OEE ImplementationUnlocking Greater Efficiency: The Why and How of OEE Implementation
Unlocking Greater Efficiency: The Why and How of OEE Implementation
 
Leveraging Ignition Quick Start to Rapidly Build Real Projects
Leveraging Ignition Quick Start to Rapidly Build Real ProjectsLeveraging Ignition Quick Start to Rapidly Build Real Projects
Leveraging Ignition Quick Start to Rapidly Build Real Projects
 
Design Like a Pro: Developing & Deploying Perspective Applications as HMIs
Design Like a Pro: Developing & Deploying Perspective Applications as HMIsDesign Like a Pro: Developing & Deploying Perspective Applications as HMIs
Design Like a Pro: Developing & Deploying Perspective Applications as HMIs
 
Integrator Discussion: Leading Through Innovation During COVID-19 and Beyond
Integrator Discussion: Leading Through Innovation During COVID-19 and BeyondIntegrator Discussion: Leading Through Innovation During COVID-19 and Beyond
Integrator Discussion: Leading Through Innovation During COVID-19 and Beyond
 
Ignition Community Live with Carl Gould & Colby Clegg
Ignition Community Live with Carl Gould & Colby CleggIgnition Community Live with Carl Gould & Colby Clegg
Ignition Community Live with Carl Gould & Colby Clegg
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

Design Like a Pro: Scripting Best Practices

  • 1.
  • 2. Moderator Don Pearson Chief Strategy Officer Inductive Automation
  • 3. Today’s Agenda • Introduction to Ignition • Things to Remember When Scripting • Scripting Best Practices • Q&A
  • 4. About Inductive Automation • Founded in 2003 • HMI, SCADA, MES, and IIoT software • Installed in 100+ countries • Over 1,500 integrators • Used by 44% of Fortune 100 companies Learn more at: inductiveautomation.com/about
  • 5. Used By Industries Worldwide
  • 6. Ignition: Industrial Application Platform One Universal Platform for SCADA, MES & IIoT: • Unlimited licensing model • Cross-platform compatibility • Based on IT-standard technologies • Scalable server-client architecture • Web-managed • Web-launched on desktop or mobile • Modular configurability • Rapid development and deployment
  • 7. Presenter Kevin McClusky Co-Director of Sales Engineering, Inductive Automation
  • 8. Why Scripting Exists • It’s possible to create complete, powerful projects with HMI/SCADA software without writing code • However, many designers find that to complete all project requirements, they need to use scripting. • Typically, 80-90% of required functionality can be accomplished through native features. Scripting exists to fill the other 10-20%.
  • 9. Why Use Scripting? • More flexibility • Extend the logic • Do more with the product than what’s built into it • But it has to be used in the right way
  • 10. When to Use Scripting and When Not To • Use scripting when you simply can’t accomplish a requirement with built-in tools. • Don’t just use scripting for scripting’s sake. • You may want to ask other users in forums or call tech support. • Scripting can make it more difficult for another engineer to understand, so make sure it is applicable and comment your code.
  • 11. When to Use Scripting: Examples • Exporting data through scripting that wasn’t built-in to binding or component • Custom calculations
  • 12. When Not to Use Scripting: Examples • Dynamic SQL query in binding vs. scripting • Logging data (contextually) from a tag change script when you can use transaction groups
  • 13. Which Scripting Language? Best programming languages to use: • Use the scripting language that comes with your HMI, SCADA, IIoT or MES platform. • Although scripting outside the platform may be possible, it’s best to use native scripting tools because it eases maintainability and has the fullest possible integration with the platform.
  • 14. Understanding Where and When Your Script is Running • Extremely important to know exactly where and when your code is running • Requires knowledge of the software platform you are using • Avoid unnecessary code from running and performing duplicate work
  • 15. Understanding Where and When Your Script is Running • Where scripts run in Ignition: • Gateway (server) • Client • When scripts run in Ignition: • Timer • Tag change • User in client (button press) • SFC • Alarm pipeline • Etc.
  • 16. Organization and Standards • Develop a code standard and be consistent • Organize well and make sure folders, functions & variables are named appropriately • Avoid language shortcuts • Indent style (tabs or spaces) • Programming style • Comment conventions • Naming conventions
  • 17. Organization and Standards • Develop a code standard and be consistent • Organize well and make sure folders, functions & variables are named appropriately • Avoid language shortcuts • Indent style (tabs or spaces) • Programming style • Comment conventions • Naming conventions
  • 18. Organization and Standards • Avoid language shortcuts (example) 1. Example with shortcut: numbers = [1,2,3,4,5,6] even = [number for number in numbers if number%2 == 0] 2. Example without: numbers = [1,2,3,4,5,6] even = [] for number in numbers: if number%2 == 0: even.append(number)
  • 19. Organization and Standards • Develop a code standard and be consistent • Organize well and make sure folders, functions & variables are named appropriately • Avoid language shortcuts • Indent style (tabs or spaces) • Programming style • Comment conventions • Naming conventions
  • 20. Commenting Code • A comment is a programmer-readable explanation or annotation in the source code. • Added to make the source code easier for humans to understand, generally ignored by compilers and interpreters. • You need to do it! • Helps the next developers and makes code easier to understand and troubleshoot
  • 21. Commenting Code (Examples) • Individual Lines: # this is a comment print 'Hello world' # this is also a valid comment • Blocks of Lines: ''' This is a lot of text that you want to show as multiple lines of comments Script written by Professor X. Jan 5, 1990 ''' print 'Hello world'
  • 22. Commenting Code (Examples) • Use the Ctrl-/ keyboard shortcut to comment several lines of code at once. Just highlight one or more lines of code and hold the Ctrl key and press /
  • 23. Organization and Standards • Develop a code standard and be consistent • Organize well and make sure folders, functions & variables are named appropriately • Avoid language shortcuts • Indent style (tabs or spaces) • Programming style • Comment conventions • Naming conventions
  • 24. Best Practice: Variables • Use naming conventions • Define variables at the top of the script Example: name = event.source.parent.getComponent('Name').text desc = event.source.parent.getComponent('Description').text building = event.source.parent.getComponent('Building').selectedValue id = system.db.runPrepUpdate("INSERT INTO machines (machine_name, description) VALUES (?, ?)", [name, desc])
  • 25. Best Practice: Define Scripting Functions • Functions are code that can be called repeatedly from other places • Can have parameters passed into them, and may return a resulting value • Types of functions: 1. Built-in to the language, like len() 2. Part of software package, like system.gui.getMessageBox() for Ignition 3. Provided by language standard library, like math.sqrt() 4. User-defined functions
  • 26. Best Practice: Define Scripting Functions Benefits: • Keeps code organized • Easier to find and troubleshoot • Keeps windows and tags cleaner • Ability to re-use
  • 27. Best Practice: Define Scripting Functions • Default values for arguments (keyword arguments) Argument specified by position: print checkBounds(150, 0, 250) Argument specified by keyword: print checkBounds(150, range=250)
  • 28. Best Practice: Define Scripting Functions • Variable arguments (*args and **kwargs) Example: def add(firstValue, *args): finalValue = firstValue for value in args: finalValue = finalValue + value return finalValue def checkBounds(value, offset=0, range=200): if value + offset > range: return true else: return false
  • 29. Best Practice: Exception Handling • Exceptions are errors detected during execution • Not unconditionally fatal • Most exceptions aren't handled by programs • You can write programs that handle exceptions Example: try: window = system.gui.getWindow('Overview') system.gui.closeWindow(window) except: system.gui.warningBox("The Overview window isn't open")
  • 30. Best Practice: Error Console • One of the most important troubleshooting tools of any package • Shows a wealth of information about the running state of the system, system errors, and errors from custom scripts • Depending on where your script is running, there may be a different console • Clear up any known errors
  • 31. Best Practice: Error Console Tips: • Know how long your script takes (Log start, end, and duration) • Use loggers effectively to troubleshoot your code (debug vs. info vs. warn vs. error)
  • 32. Best Practice: Loops • When to use loops: - Dealing with multiple items - Iterating over finite list • When not to use loops: - To make your code wait (use a timing mechanism instead)
  • 33. Best Practice: Loops • Stay away from infinite loops (While True or long for loops) • Use breaks effectively (Don’t do unnecessary work) Example: found = False for row in result: if row[“name”] == “MyName”: found = True break
  • 34. Best Practice: Timers • Timers run at a set interval 24x7 • Understanding fixed rate vs. fixed delay: ◦ Fixed delay timer script (default) waits for given delay between each script invocation. The script's rate will be the delay plus the time it takes to execute the script. This is the safest option. ◦ Fixed rate scripts attempt to run the script at a fixed rate relative to the first execution. If script takes too long, or there is too much background process, this may not be possible.
  • 35. Best Practice: Timers • Avoid scripts that run quickly that fill up queues (such as tag writes) • Provide ability to enable/disable through a setting (such as a memory tag)
  • 36. Best Practice: Tag Change • Tag change scripts run when the value or quality of a tag changes. • Make sure to check the quality of the tag. It is possible the value didn’t change but the quality did. Don’t run code at the wrong times. • You may want to check the value, and whether the value is different from the previous value. • Decide whether you want the script to run initially (when the server reboots)
  • 37. Best Practice: Avoid Race Conditions • Race condition or race hazard: the behavior of a system where the output is dependent on the sequence or timing of other uncontrollable events • Expect one script to be completed before running the other • Becomes a bug when events do not happen in the order the programmer intended • Typically due to asynchronous problems (tags, properties)
  • 38. Best Practice: Avoid Race Conditions Examples: • A propertyChange script that refers to two properties but is only filtered on one. The second property may not have updated. Instead try to put in a single property, if possible, or run the code multiple times, looking at all props. • Writing to a tag and reading the tag on the next line
  • 39. Best Practice: Understand Threading • A lot of languages, such as Java, are multi-threaded • Two or more parts that can run concurrently, and each part can handle a different task at the same time.
  • 40. Best Practice: Understand Threading • Are scripts running in a shared or dedicated thread? • Scripts running in a shared thread will all execute in the same thread. This is usually desirable, to prevent creating unnecessary threads. However, scripts that take a long time to run will block other scripts on the shared thread.
  • 41. Best Practice: Understand Threading • Rule of thumb: quick-running tasks should run in the shared thread, and long-running tasks should get their own thread. • Understand what else could be affected if running in the same thread
  • 42. Best Practice: Understand Threading UI thread vs separate thread (asynchronous) • UI can hang • Use progress bars instead (asynchronous) • Callbacks to the UI thread invokeLater
  • 43. Other Tips: Restoring Backups on Other Machines • Scripts could be running in two places • Make sure to restore disabled or have a code check if it is a certain machine (by IP or hostname).
  • 44. Other Tips: Scripting Timesavers • Software package functions vs. libraries • Language functions vs. custom code (example: the Python CSV library)
  • 45. Recap - Things to Remember When Scripting: • Understand the basic purpose of scripting • Know when to use scripting and when not to • Understand where and when your script is running • Use organization and standards • Include comments in your code
  • 46. Recap of Scripting Best Practices: • Use variable naming conventions • Define common functions • Use exception handling • Use the error console • Avoid infinite loops • Use appropriate threads with timers • Plan tag change scripts • Avoid race conditions • Understand threading
  • 47. One Last Tip … Looking for some scripting help? Here are a few good resources: • User forum at: www.inductiveautomation.com/forum • Python language tutorial: www.python-course.eu/course.php
  • 48.
  • 49. Design Like a Pro Series Available at: inductiveautomation.com/resources
  • 50.
  • 51. Questions & Comments Jim Meisler x227 Vannessa Garcia x231 Vivian Mudge x253 Account Executives Myron Hoertling x224 Shane Miller x218 Ramin Rofagha x251 Maria Chinappi x264 Dan Domerofski x273 Lester Ares x214 800-266-7798 x247 Melanie Moniz Director of Sales: Jeff Osterback x207