Cheatography
https://cheatography.com
This cheat sheet provides a overview of the aspects of the Python coding langauge useful to users of the Spike prototyping software
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Data Types
String |
'Hello', "2345", 'This is a string' |
Integer (Int) |
2, 5, -7 |
Double (float) |
2.1, 5.0, -7.778 |
Boolean |
True, False |
Assignment operator
x = y |
The value of y is assigned to the variable x |
Comparsion operator
x == y |
x is equal to y |
x != y |
x is not equal to y |
x < y |
x is less than y |
x > y |
x is greater than y |
x <= y |
x is less than or equal |
x >= y |
x is greater than or equal |
Identity operators
x is y |
x references the same data as y |
x is not y |
x does not reference the same data as y |
Logical operators
x == y And x > 0 |
If both the expressions are True then the ‘and’ operator returns True |
x== y Or x > 0 |
If either of the expressions are True then the ‘or’ operator returns True |
See lesson 5 of Basics of Python for Spike users in the helpfiles
Variable Scope/allowable context
command |
global interpreter |
(work)unit cfb/em(eu) command |
procedural step/transition |
unit |
NO |
YES |
YES - S88 |
em |
NO |
YES |
NO |
workUnit |
NO |
YES |
YES - S95 |
EU |
NO |
YES |
NO |
See the 'Variable Scope' section of the help files.
Arithmetic Operators
x + y |
add |
x - y |
subtract |
x * y |
multiply |
x / y |
divide |
x ** y |
x ^ y |
x % y |
modulus |
abs(x) |
absolute |
Potential pitfalls
object comparsion* |
while* The while loop statement repeatedly executes a target statement as long as a given condition is true. However if while loops are used inappropriately they will trash CPU performance. In most cases the 'if' statement, waitFor function and timers would be more appriopate.
|
rounding errors* Double values can only be appropriate
|
'True' v 'true' In Spike, 'True' refers to a boolean value while 'true' is the name of an object
|
*See the potential programming pitfalls section of the help files for more detail
|
|
Useful Spike functions
opc('NameOfObject') |
Access an object in the opc model |
opc('NameOfObject'). |
The '.' operator provides access to all commands and properties of the object |
unit. |
Provides access to the commands and properties of the current unit |
unit.SupportModule |
Provides access to unit parameters, timer and counters |
unit.MessageModule |
Provides access to create messages, prompts and call work instructions |
em. |
Provides access to the commands and properties of the current equipment module |
info() |
Prints a string variable to the console tab |
str() |
Converts an object into a string |
waitFor(condition met) |
Wait for the value of given property on given module to equal given condition |
sleep(duration) |
Put current script to sleep for duration seconds |
resetModules() |
Reset parent associated modules |
firstScan |
do something when running a script the first time |
Useful code snippets
$createtimer |
Recommended method of creating a timer |
$createcounter |
Recommended method of creating a counter |
$ calls various pre-created code snippets which can be viewed in the snippets folder of the Type Explorer
Statements
If Statement
if condition met:
do Something
elif other condition met:
do Something Else
else:
do Something Else
While Loop
while condition is met:
do Something
For Loop
For variable in collection:
do Something with variable |
|