Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 3 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.4 SER built-in module .............................................................................................................................30
3.3.1Debug Python script on GPS modules using SSC bus.......................................................................................70
3.3.1.1Installation of the drivers ..........................................................................................................................70
3.3.1.2Debugging process ....................................................................................................................................73
3.3.2Debug Python script on GPS modules using CMUX ........................................................................................74
3.3.2.2Debugging process ....................................................................................................................................74
4Python standard functions ............................................................................................................. 79
4.2.2Truth Value Testing...........................................................................................................................................81
4.2.6Numeric Types: Long Integers ..........................................................................................................................82
5.2 Other Limits..........................................................................................................................................97
6 List of acronyms.............................................................................................................................. 98
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 6 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
DISCLAIMER
The information contained in this document is the proprietary information of Telit Communications
S.p.A. and its affiliates (“TELIT”). The contents are confidential and any disclosure to persons other
than the officers, employees, agents or subcontractors of the owner or licensee of this document,
without the prior written consent of Telit, is strictly prohibited.
Telit makes every effort to ensure the quality of the information it makes available. Notwithstanding the
foregoing, Telit does not make any warranty as to the information contained herein, and does not
accept any liability for any injury, loss or damage of any kind incurred by use of or reliance upon the
information.
Telit disclaims any and all responsibility for the application of the devices characterized in this
document, and notes that the application of the device must comply with the safety standards of the
applicable country, and where applicable, with the relevant wiring rules.
Telit reserves the right to make modifications, additions and deletions to this document due to
typographical errors, inaccurate information, or improvements to programs and/or equipment at any
time and without notice. Such changes will, nevertheless be incorporated into new editions of this
application note.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 7 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
1 Easy Script Extension - Python
interpreter
1.1 Overview
The Easy Script Extension is a feature that allows driving the modem "internally", writing the
controlling application directly in a nice high level language: Python.
The Easy Script Extension is aimed for the application usually done by a small microcontroller that
managed some I/O pins and the module through the AT command interface.
A schematic of such a configuration can be:
FFLLAASSHH RROOMM
GGSSMM--GGPPRRSS
PPrroottooccooll SSttaacckk
FFLLAASSHH
RROOMM
mmeemmoorryy
HHAARRDDWWAARREE RREESSOOUURRCCEESS
EEXXTTEERRNNAALL
CCOONNTTRROOLLLLEERR
PPHHYYSSIICCAALL AATT SSEERRIIAALL
PPOORRTT
AATT ccoommmmaannddss
GGPPRRSS MMOODDEEMM
EENNGGIINNE
RRAAMM
E
RRAAMM ffoorr
GGSSMM--GGPPRRSS
mmooddeemm
PPrroottooccooll SSttaacck
k
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 8 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
In order to eliminate this external controller, and further simplify the programming of the sequence of
operations, inside the Python version it is included:
• Python script interpreter engine v. 1.5.2+
• around 2MB of Non Volatile Memory space for the user scripts and data
• 1.2 MB RAM reserved for Python engine usage
A schematic of this approach is:
FFLLAASSHH RROOMM
AAvvaaiillaabbllee UUsseerr
NNVVMM FFLLAASSHH
MMeemmoorryy
((22MMbbyyttee)
GGSSMM--GGPPRRSS
PPrroottooccooll SSttaacckk
FFLLAASSHH
RROOMM
mmeemmoorryy
E
AAvvaaiillaabbllee RRAAMM
ffoorr PPyytthhoonn
IInntteerrpprreetteerr
((11..22MMbbyyttee)
RRAAMM ffoorr
GGSSMM--GGPPRRSS
mmooddeemm
PPrroottooccooll SSttaacck
PPYYTTHHOONN
IINNTTEERRPPRREETTEERR EENNGGIINNEE
MMDDMM mmoodduullee
)
VVIIRRTTUUAALL IINNTTEERRNNAALL AATT
SSEERRIIAALL PPOORRTT
AATT ccoommmmaannddss
GGPPRRSS MMOODDEEMM
EENNGGIINNE
RRAAMM
)
k
HHAARRDDWWAARREE RREESSOOUURRCCEESS
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 9 of 100
Permission to use, copy, modify, and distribute this software and its documentation for any purpose
and without fee is hereby granted, provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear in supporting documentation, and
that the names of Stichting Mathematisch Centrum or CWI or Corporation for National Research
Initiatives or CNRI not be used in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
While CWI is the initial source for this software, a modified version is made available by the
Corporation for National Research Initiatives (CNRI) at the Internet address ftp://ftp.python.org
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM OR CNRI BE
LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 10 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
1.3 Python installation
In order to have software that functions correctly the system requirement is PC running Windows 2000
or XP.
To get PythonWin package 1.5.2+ with the latest version please contacts Technical Support at the email:
ts-emea@telit.com;
ts-apac@telit.com;
ts-americas@telit.com.
Or by means the form in telit’s website Æ technical support Æcontact
Getting user name and password it is possible to download it from Telit’s websiteÆdownload zone:
http://www.telit.com/en/products/download-zone,
At the moment, the latest version available is TelitPy1.5.2+_V4.1.exe.
To install Telit Python package you need to execute the exe file TelitPy1.5.2+_V4.1.exe and let the
installer use the default settings. The installation contains the Python compiler package. The Telit
Python package is placed in the folder C:\Program Files\Python\ .The correct path in the Windows
Environmental variables will be set up automatically.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 11 of 100
r
V
r
r
rry
y
A
A
r
r
r
rry
y
r
r
rry
y
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
1.4 Python implementation description
Python scripts are text files stored in NVM inside the Telit module. There's a file system inside the
module that allows to write and read files with different names on one single level (no subdirectories
are supported).
Attention: it is possible to run only one Python script at the time.
The Python script is executed in a task inside the Telit module at the lowest priority, making sure this
does not interfere with GSM/GPRS normal operations. This allows serial ports, protocol stack etc. to
run independently from the Python script.
The Python script interacts with the Telit module functionality through four build-in interfaces.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 12 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
NOTE: Antenna GPS, GPS receiver and GPS Library are available exclusively for GPS modules
GM862-GPS and GE863-GPS. Moreover SER2 Library cannot be used by the GPS modules since
their TRACE port is not available.
•The MDM interface is the most important one. It allows Python script to send AT commands,
receive responses and unsolicited indications, send data to the network and receive data from
the network during connections. It is quite the same as the usual serial port interface in the
Telit module. The difference is that this interface is not a real serial port but just an internal
software bridge between Python and mobile internal AT command handling engine. All AT
commands working in the Telit module are working in this software interface as well. Some of
them have no meaning on this interface, such as those regarding serial port settings. The usual
concept of hardware flow control keeps its meaning over this interface, but it's managed
internally.
•The MDM2 interface is the second interface between Python and mobile internal AT
command handling. It is used to send AT commands from Python script to mobile and receive
AT responses from mobile to Python script when the classic MDM built-in module already in
use.
•The SER interface allows Python script to read from and write to the real physical serial port
ASC0, that is usually used to send the AT commands to the module, for example to read
information from external device. When Python is running this serial port is free to be used by
Python script because it is not used as AT command interface since the AT parser is mapped
into the internal virtual serial port. No flow control is available from Python on this port.
•The SER2 interface allows Python script to read from and write to the real physical serial port
ASC1, that is usually available for trace and debug.
•The GPIO interface allows Python script to handle general purpose input output faster than
through AT commands, skipping the command parser and going directly to control the pins.
• The MOD interface is a collection of useful functions.
• The IIC interface is an implementation on the Python core of the IIC bus Master. It allows
Python to create one or more IIC bus on the available GPIO pins.
• The SPI interface isan implementation on the Python core of the SPI bus Master. It allows
Python to create one or more SPI bus on the available GPIO pins.
•The GPS interface isthe interface between Python and mobile internal GPS controller. It is
used in order to handle GPS controller without dedicated AT commands through MDM built-in
module.
For the debug, the print command is directly forwarded on the EMMI TX pin (second serial port) at
baud rate115200bps 8N1.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 13 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
1.5 Introduction to Python
Python is a dynamic object oriented programming language that can be used for many kinds of
software development. It offers strong support for integration with different tools, comes with extensive
standard libraries, and can be learned in a few days time.
1.5.1 Data types
There are three groups of data types in Python:
• Scalars have the subtypes integer, long integer (with an arbitrary number of digits), and strings.
For example:
i = 1; li = 9999999999L; s = 'Hello'
• Sequences contain any number of arbitrary objects in a defined order.
L = [1, 5, 3, 9, 14];
• Associative lists (more commonly known as dictionaries) allow the access to values based on
keys. These keys can be arbitrary but immutable objects. For example:
D = {'b': 'Python', 'a': 5}; print D['a']
prints 5.
• Unlike Pascal, C, C++ or Java, Python is a dynamically typed language. Thus, the following
code is perfectly valid Python:
a = 7 # 7 (integer)
a = str(2*a) + ' bytes' # '7 bytes' (string)
In Python variables are not defined in the script, they appear only when used.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 14 of 100
1.5.2 Operators
Python has the following operators:
• Arithmetic and bitwise operators
+ - * / % ** ~ << >> & ^ |
• Relational and logical operators
is in < <= > >= == != not and or
• Assignments
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
= += -= *= /= %= **= <<= >>= &= ^= |=
• Other operators
() [ ] { } [:] `` . lambda
1.5.3 Compound statements
• Statements that belong to the same logical group are indented by the same amount of white
space:
if a > 0:
b = 1
c = 2
Usually, each statement starts on a new line.
• A statement is continued by putting a backslash \ at the end of a line. This isn't necessary if
there are still parentheses (or brackets or braces) open:
my_list = [1, # open bracket, statement continues
['abc', 2], # nested list
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 15 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
1.5.4 Conditional execution
• Python uses if, elif (not elsif or elseif), and else to denote conditional execution of statements.
For example:
if a > b:
print 'a is greater than b.'
elif a < b:
print 'a is lower than b.'
else:
print 'a equals b.'
• You can use "abbreviated" interval tests:
if 2 <= a <= 7:
print 'a is in the interval [2, 7].'
1.5.5 Loops
• Loops in Python are defined by the keywords for and while.
• The following example uses a while loop to collect all numbers from 0 to 99 in a list.
numbers = [ ]
i = 0
while i < 100:
numbers.append(i)
i = i + 1 # or i += 1 since Python 2.0
• A similar for loop looks like:
numbers = [ ]
for i in range(100):
numbers.append(i)
• Instead of the explicit loops above also an implicit loop is possible:
numbers = range(100)
range(100) generates a list of all integers from 0 to 99 (not 100).
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 16 of 100
1.5.6 Resources
Some useful manuals for Python can be found on the following links:
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
http://www.python.org/doc/current/tut/tut.html
http://www.hetland.org/python/instant-python.php
http://rgruet.free.fr/PQR2.2.html
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 17 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
1.6 Python core supported features
The Python core version is 1.5.2+ (string methods added to 1.5.2). You can use all Python statements
and almost all Python built-in types and functions.
Built-in types and functions not
supported
complex marshal
float imp
long _main_
docstring _builtin_
sys
md5
Available modules
(all others are not supported)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 18 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2 Python Build-in Custom Modules
Several build in custom modules have been included in the python core, specifically aimed at the
hardware environment of the module.
The build in modules included are:
MDM
MDM2
SER
SER2
GPIO
MOD
IIC
SPI
GPS
interface between Python and mobile internal AT command handling
second interface between Python and mobile internal AT command handling
interface between Python and mobile internal serial port ASC0 direct handling
interface between Python and mobile internal serial port ASC1 direct handling
interface between Python and mobile internal general purpose input output direct
handling
interface between Python and mobile miscellaneous functions
custom software Inter IC bus that can be mapped on creation over almost any
GPIO pin available
custom software Serial Protocol Interface bus that can be mapped on creation
over almost any GPIO pin available
interface between Python and mobile internal GPS controller
2.1 CMUX and Python1
To make the use of Python easier CMUX (Converter-Multiplexer) feature has been implemented in the
Telit modules. The Multiplexer mode creates four virtual channels on one serial interface and permits
to transmit data to four different applications. This makes it possible to run a Python script and at the
same time use CMUX on ASC0 with the following division of channels:
• first CMUX port is reserved for SER module;
• second CMUX port is available for AT command handling in case when MDM2 built-in module
is not been imported;
• third CMUX port is available for AT command handling;
• fourth CMUX port is in use for debug (print statements);
ASC1 is available for non-GPS products with import of the SER2 built-in module.
1
feature available for the modules with the following Order-Num. :, GM862GPS***-***, GM862PYT***-***,
GE863PYT***-***, GE863GPS***-***, GE864PYT***-***, GC864PYT***-***, GE864PYH***-***,and old
3990250657, 3990250660,
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 19 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.2 MDM built-in module
MDM built-in module is the interface between Python and the module AT command parser engine.
You need to use MDM built-in module if you want to send AT commands and data from Python script
to the network and receive responses and data from the network during connections.
For the default start configuration echo (ATE0) is disabled and long form (verbose) is return codes
(ATV1).
If you want to use MDM built-in module you need to import it first:
import MDM
then you can use MDM built-in module methods like in the following example:
a = MDM.send('AT', 0)
b = MDM.sendbyte(0x0d, 0)
c = MDM.receive(10)
which sends 'AT' and receives 'OK'.
More details about MDM built-in module methods can be found in the following paragraphs.
2.2.1 MDM.send(string, timeout)
This command sends a string to AT command interface. First input parameter string is a Python string
which is the string to send to AT command interface. Second input parameter timeout is a Python
integer, which is measured in 1/10s, and represents the time of waiting for the string to be sent to AT
command interface, with maximum value of timeout. Waiting time is caused by hardware flow control.
Return value is a Python integer which is -1 if timeout expired otherwise is 1.
Example:
a = MDM.send('AT', 5)
sends string 'AT' to AT command handling, possibly waiting for 0.5 s, assigning return value to a.
NOTE: The buffer available for MDM.send command is 4096 bytes
2
2.2.2 MDM.receive(timeout)
This command receives a string from AT command interface waiting for it until timeout is expired.
Return value will be the first string received no matter of how long the timeout is. Request to Send
2
For the products with the following old Order-Num. 3390250656, 3390250654 and 3990150466 the available
buffer is 2048 bytes
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 20 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
(RTS) is set to ON. Input parameter timeout is a Python integer, which is measured in 1/10s, and
represents the maximum time of waiting for the string from AT command interface.
Return value is a Python string which is an empty string if timeout has expired without any data
received otherwise the string contains data received.
Example:
a = MDM.receive(15)
receives a string from AT command handling, possibly waiting for it for 1.5 s, assigning return value to
a.
NOTE: The buffer available for MDM.receive command is 4096 bytes
3
2.2.3 MDM.read()
This command receives a string from AT command interface without waiting for it. Request to Send
(RTS) is set to ON. It has no input parameter.
Return value is a Python string which is an empty string if no data received otherwise is the string
containing data received in the moment when command is activated.
Example:
a = MDM.read()
receives a string from AT command handling, assigning return value to a.
NOTE: The buffer available for MDM.read command is 4096 bytes
4
2.2.4 MDM.sendbyte(byte, timeout)
This command sends a byte to AT command interface. First input parameter byte is any Python byte
that will be to send to AT command interface. It can also be zero. Second input parameter timeout is a
Python integer, which is measured in 1/10s, and represents the maximum time of waiting for the string
from AT command interface. Waiting time is caused by hardware flow control.
Return value is a Python integer which is -1 if timeout expired otherwise is 1.
Example:
b = MDM.sendbyte(0x0d, 0)
3
For the products with the following old Order-Num. 3390250656, 3390250654 and 3990150466 the available
buffer is 2048 bytes
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 21 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
sends byte 0x0d, that stands for <CR>, to AT command handling, without waiting, assigning return
value to b.
2.2.5 MDM.receivebyte(timeout)
This command receives a byte from AT command interface waiting for it until timeout is expired.
Request to Send (RTS) is set to ON. Input parameter timeout is a Python integer which is measured in
1/10s, and represents the maximum time of waiting for the string from AT command interface.
Return value is a Python integer which is -1 if timeout expired without any data received otherwise is
the byte value received. It can also be zero.
Example:
b = MDM2.receivebyte(20)
receives a byte from AT command handling, possibly waiting for it for 2.0 s, assigning return value to
b.
2.2.6 MDM.readbyte()
This command receives a byte from AT command interface without waiting for it. Request to Send
(RTS) is set to ON. It has no input parameter.
Return value is a Python integer which is -1 if no data received otherwise is the byte value received. It
can also be zero.
Example:
b = MDM.readbyte()
receives a byte from AT command handling, assigning return value to b.
2.2.7 MDM.getDCD()
This command gets Carrier Detect (DCD) from AT command interface. It has no input parameter.
Return value is a Python integer which is 0 if DCD is OFF or 1 if DCD is ON.
Example:
cd = MDM.getDCD()
gets DCD from AT command handling, assigning return value to cd.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 22 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.2.8 MDM.getCTS()
This command gets Clear to Send (CTS) from AT command interface. it has no input parameter.
Return value is a Python integer which is 0 if CTS is set to OFF or 1 if CTS is set to ON.
Example:
cts = MDM.getCTS()
gets CTS from AT command handling, assigning return value to cts.
2.2.9 MDM.getDSR()
This command gets Data Set Ready (DSR) from AT command interface. It has no input parameter.
Return value is a Python integer which is 0 if DSR is OFF or 1 if DSR is ON.
Example:
dsr = MDM.getDSR()
gets DSR from AT command handling, assigning return value to dsr.
2.2.10 MDM.getRI()
This command gets Ring Indicator (RI) from AT command interface. It has no input parameter.
Return value is a Python integer which is 0 if RI is set to OFF or 1 if RI is set to ON.
Example:
ri = MDM.getRI()
gets RI from AT command handling, assigning return value to ri.
2.2.11 MDM.setRTS(RTS_value)
This command sets Request to Send (RTS) in AT command interface. Input parameter RTS_value is
a Python integer which is 0 if setting RTS to OFF or 1 if setting RTS to ON.
No return value.
Example:
MDM.setRTS(1)
sets RTS to ON in AT command handling.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 23 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.2.12 MDM.setDTR(DTR_value)
This command sets Data Terminal Ready (DTR) in AT command interface. Input parameter
DTR_value is a Python integer which is 0 if setting DTR to OFF or 1 if setting DTR to ON.
No return value.
Example:
MDM.setDTR(0)
sets DTR to OFF in AT command handling.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 24 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.3 MDM2 built-in module4
MDM2 built-in module is the second interface between Python and mobile internal AT command
handling. It is used to send AT commands from Python script to mobile and receive AT responses
from mobile to Python script when the classic MDM built-in module already in use.
MDM2 built-in module is independent from activation of CMUX on ASC0. In case you have enabled
CMUX on ASC0 (AT#CMUXSCR=1) then the second CMUX port will be dedicated to MDM2 and no
AT command handling will be possible on that port. Remember that first CMUX port is reserved for
SER module and fourth CMUX port is in use for debug (print statements).
For the default start configuration echo (ATE0) is disabled and long form (verbose) is return codes
(ATV1).
If you want to use MDM2 built-in module you need to import it first:
import MDM2
than you can use MDM2 built-in module methods like in the following example:
a = MDM2.send('AT', 0)
b = MDM2.sendbyte(0x0d, 0)
c = MDM2.receive(10)
which sends 'AT' and receives 'OK'.
More details about MDM2 built-in module methods can be found in the following paragraphs.
2.3.1 MDM2.send(string, timeout)
This command sends a string to AT command interface. First input parameter string is a Python string
that will be send to AT command interface. Second input parameter timeout is a Python integer which
is measured in 1/10s, and represents the time of waiting for the string to be sent to AT command
interface, with maximum value of timeout. Waiting time is caused by hardware flow control.
Return value is a Python integer which is -1 if timeout expired otherwise is 1.
Example:
a = MDM2.send('AT', 5)
sends string 'AT' to AT command handling, possibly waiting for 0.5 s, assigning return value to a.
NOTE: The buffer available for MDM2.send command is 4096 bytes
4
feature available for the modules with the following Order-Num.: , GM862PYT***-***, GE863PYT***-***,
GE864PYT***-***, GC864PYT***-***, GE864PYH***-***, GM862GPS***-***, G3863GPS***-***, and the old
3990250660 and 3990250657
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 25 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.3.2 MDM2.receive(timeout)
This command receives a string from AT command interface waiting for it until timeout is expired.
Return value will be the first string received no matter of how long the timeout is. Request to Send
(RTS) is set to ON. Input parameter timeout is a Python integer, which is measured in 1/10s, and
represents the maximum time of waiting for the string from AT command interface.
Return value is a Python string which is an empty string if timeout has expired without any data
received otherwise the string contains data received.
Example:
a = MDM2.receive(15)
receives a string from AT command handling, possibly waiting for it for 1.5 s, assigning return value to
a.
NOTE: The buffer available for MDM2.receive command is 4096 bytes.
2.3.3 MDM2.read()
This command receives a string from AT command interface without waiting for it. Request to Send
(RTS) is set to ON. No input parameter.
Return value is a Python string which is an empty string if no data received otherwise the string
contains data received in the moment when command is activated.
Example:
a = MDM2.read()
receives a string from AT command handling, assigning return value to a.
NOTE: The buffer available for MDM2.read command is 4096 bytes
2.3.4 MDM2.sendbyte(byte, timeout)
This command sends a byte to AT command interface. First input parameter byte is any Python byte
that will be to send to AT command interface. It can also be zero.
Second input parameter timeout is a Python integer which is the value in 1/10 s to wait for the byte to
be sent to AT command interface before timeout expires. Waiting time is caused by hardware flow
control.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 26 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Return value is a Python integer which is -1 if timeout expired otherwise is 1.
Example:
b = MDM2.sendbyte(0x0d, 0)
sends byte 0x0d, that is <CR>, to AT command handling, without waiting, assigning return value to b.
2.3.5 MDM2.receivebyte(timeout)
This command receives a byte from AT command interface waiting for it until timeout is expired.
Request to Send (RTS) is set to ON. Input parameter timeout is a Python integer which is measured in
1/10s, and represents the maximum time of waiting for the string from AT command interface.
Return value is a Python integer which is -1 if timeout expired without any data received otherwise is
the byte value received. It can also be zero.
Example:
b = MDM2.receivebyte(20)
receives a byte from AT command handling, possibly waiting for it for 2.0 s, assigning return value to
b.
2.3.6 MDM2.readbyte()
This command receives a byte from AT command interface without waiting for it. Request to Send
(RTS) is set to ON. It has no input parameter.
Return value is a Python integer which is -1 if no data received otherwise is the byte value received. It
can also be zero.
Example:
b = MDM2.readbyte()
receives a byte from AT command handling, assigning return value to b.
2.3.7 MDM2.getDCD()
This command gets Carrier Detect (DCD) from AT command interface. It has no input parameter.
Return value is a Python integer which is 0 if DCD is set to OFF or 1 if DCD is set to ON.
Example:
cd = MDM2.getDCD()
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 27 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
gets DCD from AT command handling, assigning return value to cd.
2.3.8 MDM2.getCTS()
This command gets Clear to Send (CTS) from AT command interface. It has no input parameter.
Return value is a Python integer which is 0 if CTS is set to OFF or 1 if CTS is set to ON.
Example:
cts = MDM2.getCTS()
gets CTS from AT command handling, assigning return value to cts.
2.3.9 MDM2.getDSR()
This command gets Data Set Ready (DSR) from AT command interface. It has no input parameter.
Return value is a Python integer which is 0 if DSR is set to OFF or 1 if DSR is set to ON.
Example:
dsr = MDM2.getDSR()
gets DSR from AT command handling, assigning return value to dsr.
2.3.10 MDM2.getRI()
This command gets Ring Indicator (RI) from AT command interface. It has no input parameter.
Return value is a Python integer which is 0 if RI is set to OFF or 1 if RI is set to ON.
Example:
ri = MDM2.getRI()
gets RI from AT command handling, assigning return value to ri.
2.3.11 MDM2.setRTS(RTS_value)
This command sets Request to Send (RTS) in AT command interface. Input parameter RTS_value is
a Python integer which is 0 if setting RTS to set to OFF or 1 if setting RTS to set to ON.
It has no return value.
Example:
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 28 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
MDM2.setRTS(1)
sets RTS to ON in AT command handling.
2.3.12 MDM2.setDTR(DTR_value)
This command sets Data Terminal Ready (DTR) in AT command interface. Input parameter
DTR_value is a Python integer which is 0 if setting DTR to set to OFF or 1 if setting DTR to set to ON.
It has no return value.
Example:
MDM2.setDTR(0)
sets DTR to OFF in AT command handling.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 29 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.4 SER built-in module
SER built-in module is the interface between Python core and the device serial port over the RXD/TXD
pins direct handling. You need to use SER built-in module if you want to send data from Python script
to serial port and to receive data from serial port ASC0 to Python script. This serial port handling
module can be used for example to interface the module with an external device such as a GPS and
read/send its data (NMEA for example). SER built-in module has also been improved lately with the
possibility to control physical lines.
If you want to use SER built-in module you need to import it first:
import SER
then you can use SER built-in module methods like in the following example:
a = SER.set_speed('9600')
b = SER.send('test')
c = SER.sendbyte(0x0d)
d = SER.receive(10)
which sends 'test' followed by <CR> and receives data waiting for one second.
More details about SER built-in module methods can be found in the following paragraphs.
2.4.1 SER.send(string)
This command sends a string to the serial port TXD/RXD. Input parameter string is a Python string
that will be send to serial port ASC0.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
a = SER.send('test')
sends string 'test' to serial port ASC0 handling, assigning return value to a.
NOTE: the buffer available for SER.send(string) command is 4096 bytes
5
For the products with the following old Order-Num. 3390250656, 3390250654 and 3990150466 the available
buffer is 2048 bytes
5
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 30 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.4.2 SER.receive(timeout)
This command receives a string from serial port TXD/RXD waiting for it until timeout is expired. Return
value will be the first string received no matter of how long the timeout is. Input parameter timeout is a
Python integer, which is measured in 1/10s, and represents the maximum time of waiting for the string
from the serial port ASC0.
Return value is a Python string which is an empty string if timeout expired without any data received
otherwise is the string containing data received.
Example:
a = SER.receive(15)
receives a string from serial port ASC0 handling, waiting for it for 1.5 s, assigning return value to a.
2.4.3 SER.read()
This command receives a string from serial port TXD/RXD without waiting for it. It has no input
parameter. Return value is a Python string which is an empty string if no data received otherwise is
the string containing data received in the moment when command is activated.
Example:
a = SER.read()
receives a string from serial port ASC0 handling, assigning return value to a.
NOTE: the buffer available for the SER.receive(timeout) and SER.read() commands is 4096 bytes
6
.
2.4.4 SER.sendbyte(byte)
This command sends a byte to serial port TXD/RXD. Input parameter byte is any Python byte that will
be send to serial port. It can also be zero.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
b = SER.sendbyte(0x0d)
sends byte 0x0d, that is <CR>, to serial port ASC0 handling, assigning return value to b.
6
For the products with the following old Order-Num. 3390250656, 3390250654 and 3990150466 the available
buffer is 256 bytes
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 31 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.4.5 SER.receivebyte(timeout)
This command receives a byte from serial port TXD/RXD waiting for it until timeout is expired. Return
value will be the first byte received no matter of how long the timeout is. Input parameter timeout is a
Python integer, which is measured in 1/10s, and represents the maximum time of waiting for the string
from serial port ASC0.
Return value is a Python integer which is -1 if timeout expired without any data received otherwise is
the byte value received. It can also be zero.
Example:
b = SER.receivebyte(20)
receives a byte from serial port ASC0 handling, waiting for it for 2.0 s, assigning return value to b.
2.4.6 SER.readbyte()
This command receives a byte from serial port TXD/RXD without waiting for it. It has no input
parameter.
Return value is a Python integer which is -1 if no data received otherwise is the byte value received. It
can also be zero.
Example:
b = SER.readbyte()
receives a byte from serial port ASC0 handling, assigning return value to b.
2.4.7 SER.set_speed(speed, <char format>)
This command sets serial port TXD/RXD speed. Default serial port TXD/RXD speed is 9600. Input
parameter speed is a Python string which is the value of the serial port speed. It can be the same
speeds as the +IPR command.
NOTE: sending the +IPR command to the device is not affecting the physical serial, when using
Python engine you must use this function to set the speed of the port.
Optional Parameter <char format> is a Python string that represents the character format to be used:
first is the number of bits per char (7 or 8), then the parity setting (N - none, E- even, O- odd) and the
number of stop bits (1 or 2). Default value is "8N1".
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
b = SER.set_speed('115200')
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 32 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
sets serial port ASC0 speed to 115200, assigning return value to b.
NOTE: in the PythonWin version pervious to TelitPy1.5.2+_V2.1.exe and Python on module version
previous to Ver6.03.000 a different syntax is implemented depending of the development environment.
For PythonWin application: SER.SetSpeed(speed) without char format parameter.
For Python installed on module: SER.set_speed(speed, char format) with char format not an optional
parameter.
2.4.8 SER.setDCD(DCD_value)
This command sets Carrier Detect (DCD) in serial port ASC0. Input parameter DCD_value is a Python
integer which is 0 if DCD is set to OFF or 1 if DCD is set to ON. It has no return value.
Example:
SER.setDCD(1)
sets DCD to ON in ASC0.
2.4.9 SER.setCTS(CTS_value)
This command sets Clear to Send (CTS) in serial port ASC0. Input parameter CTS_value is a Python
integer which is 0 if CTS is set to OFF or 1 if CTS is set to ON.
It has no return value.
Example:
SER.setCTS(1)
sets CTS to ON in ASC0.
2.4.10 SER.setDSR(DSR_value)
This command sets Data Set Ready (DSR) in serial port ASC0. Input parameter DSR_value is a
Python integer which is 0 if DSR is set to OFF or 1 if DSR is set to ON. It has no return value.
Example:
SER.setDSR(1)
sets DSR to ON in ASC0.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 33 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.4.11 SER.setRI(RI_value)
This command sets Ring Indicator (RI) in serial port ASC0. Input parameter RI_value is a Python
integer which is 0 if RI is set to OFF or 1 if RI is set to ON. It has no return value.
Example:
SER.setRI(1)
sets RI to ON in ASC0.
2.4.12 SER.getRTS()
This command gets Request to Send (RTS) from serial port ASC0. It has no input parameter.
Return value is a Python integer which is 0 if RTS is set to OFF or 1 if RTS is set to ON.
Example:
rts = SER.getRTS()
gets RTS from ASC0, assigning return value to rts.
2.4.13 SER.getDTR()
This command gets Data Terminal Ready (DTR) from serial port ASC0. It has no input parameter.
Return value is a Python integer which is 0 if DTR is set to OFF or 1 if DTR is set to ON.
Example:
dtr = SER.getDTR()
gets DTR from ASC0, assigning return value to dtr.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 34 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.5 SER2 built-in module7
SER2 built-in module is the interface between Python and mobile internal serial port ASC1 direct
handling. It is used when you want to send data from Python script to serial port ASC1 and receive
data from serial port ASC1 to Python script.
SER2 built-in module is available only for non-GPS products. When SER2 bulit-in module is imported,
ASC1 will not be available for trace and debug, in order to have these functionalities you should
activate CMUX on ASC0.
If you are using CMUX on ASC0 (AT#CMUXSCR=1) then fourth CMUX port will be available for trace
and debug.
If you want to use SER2 built-in module you need to import it first:
import SER2
than you can use SER2 built-in module methods like in the following example:
a = SER2.send('test')
b = SER2.sendbyte(0x0d)
c = SER2.receive(10)
which sends 'test' followed by <CR> and receives data waiting for one second.
More details about SER2 built-in module methods can be found the following paragraphs.
2.5.1 SER2.send(string)
This command sends a string to the serial port ASC1. Input parameter string is a Python string that will
be send to serial port ASC1.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
a = SER2.send('test')
sends string 'test' to serial port ASC1 handling, assigning return value to a.
NOTE: The buffer available for SER2.send command is 4096 bytes.
7
feature available for the modules with the following Order-Num. : GM862PYT***-***, GE863PYT***-***,
GE864PYT***-***, , GC864PYT***-***, GE864PYH***-***,.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 35 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.5.2 SER2.receive(timeout)
This command receives a string from serial port ASC1 waiting for it until timeout is expired. Return
value will be the first string received no matter of how long the timeout is. Input parameter timeout is a
Python integer, which is measured in 1/10s, and represents the maximum time of waiting for the string
from the serial port ASC1.
Return value is a Python string which is an empty string if timeout expired without any data received
otherwise is the string containing data received.
Example:
a = SER2.receive(15)
receives a string from serial port ASC1 handling, waiting for it for 1.5 s, assigning return value to a.
2.5.3 SER2.read()
This command receives a string from serial port ASC1 without waiting for it. It has no input parameter.
Return value is a Python string which is an empty string if no data received otherwise is the string
containing data received in the moment when command is activated.
Example:
a = SER2.read()
receives a string from serial port ASC1 handling, assigning return value to a.
NOTE: the buffer available for the SER2.receive(timeout) and SER2.read() commands is 4096 bytes.
2.5.4 SER2.sendbyte(byte)
This command sends a byte to serial port ASC1. Input parameter byte is any Python byte that will be
send to serial port ASC1. It can also be zero.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
b = SER2.sendbyte(0x0d)
sends byte 0x0d, that is <CR>, to serial port ASC1 handling, assigning return value to b.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 36 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.5.5 SER2.receivebyte(timeout)
This command receives a byte from serial port ASC1 waiting for it until timeout is expired. Return
value will be the first byte received no matter of how long the timeout is. Input parameter timeout is a
Python integer which is measured in 1/10s, and represents the maximum time of waiting for the string
from serial port ASC1.
Return value is a Python integer which is -1 if timeout expired without any data received otherwise is
the byte value received. It can also be zero.
Example:
b = SER2.receivebyte(20)
receives a byte from serial port ASC1 handling, waiting for it for 2.0 s, assigning return value to b.
2.5.6 SER2.readbyte()
This command receives a byte from serial port ASC1 without waiting for it. No input parameter.
Return value is a Python integer which is -1 if no data received otherwise is the byte value received. It
can also be zero.
Example:
b = SER2.readbyte()
receives a byte from serial port ASC1 handling, assigning return value to b.
2.5.7 SER2.set_speed(speed, <format>)
This command sets serial port ASC1 speed. Default serial port ASC1 speed is 9600. First input
parameter speed is a Python string which is the value of the serial port speed. It can be in the range
from '300' to '115200'. Second input parameter format is optional and is a Python string which is the
serial port format. It can be ‘8N1’, ‘8N2’, ‘8E1’, ‘8O1’, ‘7N1’, ‘7N2’, ‘7E1’, ‘7O1’, or ‘8E2’.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
b = SER2.set_speed('115200')
sets serial port ASC1 speed to 115200, assigning return value to b.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 37 of 100
2.6 GPIO built-in module
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
GPIO built-in module
output direct handling. You need to use GPIO built-in module if you want to set GPIO values from
Python script and to read GPIO values from Python script.
You can control GPIO pins also by sending internal 'AT#GPIO' commands using the MDM module, but
using the GPIO module is faster because no command parsing is involved, therefore its use is
recommended.
NOTE: Python core does not verify if the pins are already used for other purposes (IIC module or SPI
module) by other functions, it's the customer responsibility to ensure that no conflict over pins occurs.
If you want to use GPIO built-in module you need to import it first:
import GPIO
then you can use GPIO built-in module methods like in the following example:
a = GPIO.getIOvalue(5)
b = GPIO.setIOvalue(4, 1)
this reads GPIO 5 value and sets GPIO 4 to output with value 1.
More details about GPIO built-in module methods are in the following paragraphs.
8
is the interface between Python core and module internal general purpose input
2.6.1 GPIO.setIOvalue(GPIOnumber, value)
Sets output value of a GPIO pin. First input parameter GPIOnumber is a Python integer which is the
number of the GPIO. Second input parameter value is a Python integer which is the output value. It
can be 0 or 1.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
b = GPIO.setIOvalue(4, 1)
sets GPIO 4 to output with value 1, assigning return value to b.
2.6.2 GPIO.getIOvalue(GPIOnumber)
Gets input or output value of a GPIO. Input parameter GPIOnumber is a Python integer which is the
number of the GPIO.
8
Note: In case of data call, simulation in PythonWin of GPIO module will not be complete. (a dummy command
replaces GPIO module commands)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 38 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Return value is a Python integer which is -1 if an error occurred otherwise is input or output value. It is
0 or 1.
Example:
a = GPIO.getIOvalue(5)
gets GPIO 5 input or output value, assigning return value to b.
2.6.3 GPIO.setIOdir(GPIOnumber, value, direction)
Sets direction of a GPIO. First input parameter GPIOnumber is a Python integer which is the number
of the GPIO. Second input parameter value is a Python integer which is the output value. It can be 0
or 1. It is only used if direction value is 1.
NOTE: when the direction value is 1, although the parameter value has no meaning, it is necessary to
assign it one of the two possible values: 0 or 1
Third input parameter direction is a Python integer which is the direction value. It can be 0 for input or
1 for output.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
c = GPIO.setIOdir(4, 0, 0)
sets GPIO 4 to input with value having no meaning, assigning return value to c.
2.6.4 GPIO.getIOdir(GPIOnumber)
Gets direction of a GPIO. Input parameter GPIOnumber is a Python integer which is the number of the
GPIO.
Return value is a Python integer which is -1 if an error occurred otherwise is direction value. It is 0 for
input or 1 for output.
Example:
d = GPIO.getIOdir(7)
gets GPIO 7 direction, assigning return value to d.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 39 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.6.5 GPIO.getADC(adcNumber)9
Gets ADC value in the same way as AT#ADC command. Input parameter adcNumber is a Python
integer which represents the ADC number that will be read and converted in voltage.
Return value is a Python integer which is -1 if an error occurred otherwise the converted voltage is
returned in mV.
Example:
mV = GPIO.getADC(2)
gets ADC number 2 input voltage, assigning return value in mV.
2.6.6 GPIO.setDAC(enable, value)8
Sets DAC value in the same way as AT#DAC command. First input parameter enable is a Python
integer and can assume values 0 or 1. If it is set to 1 enables DAC output otherwise if it is set to 0
disabled DAC output. Second input parameter value is a Python integer and represents the scale
factor of output voltage and can assume values in the range 0-1023.
Return value is a Python integer that has value -1 if an error occurred otherwise it has value 1.
Example:
res = GPIO.setDAC(1, 512)
sets DAC output voltage at half the range, assigning return value to res.
2.6.7 GPIO.setVAUX(vauxNumber, enable)8
Enables or disables VAUX in the same way as AT#VAUX command. First input parameter
vauxNumber is a Python integer that represents VUAX number that will be enabled or disabled.
Second input parameter enable is a Python integer that can assume value 1 in order to enable VAUX
output or 0 if VAUX output should be disabled.
Return value is a Python integer that has value -1 if an error occurred otherwise it has value 1.
Example:
res = GPIO.setVAUX(1, 1)
enables VAUX number 1 output, assigning return value to res.
9
Available only for modules with following Order-Num.: GM862PYT***-***, , GE863PYT***-***, , GM862GPS******, GE863GPS***-***, GC864PYT***-*** , GC864PC2***-***, and the old 3990250657 and 3990250660
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 40 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.6.8 GPIO.getAXE()9
Gets hands free status value in the same way as AT#AXE command. There is no input parameter.
Return value is a Python integer that is 0 if a hand free is not connected or 1 if a hand free is
connected.
Sets status led configuration values in the same way as AT#SLED does. First input parameter status
is a Python integer that represents the configuration of status led and can assume the following
values:
0 - ALWAYS OFF
1 - ALWAYS ON
2 - AUTO
3 - BLINKING
Second input parameter onDuration is a Python integer which is the period of ON configuration of
status led in 1/10 s. Third input parameter offDuration is a Python integer which is the period of OFF
configuration of status led in 1/10 s.
Return value is a Python integer which is -1 if an error occurred otherwise it is 1.
Example:
res = GPIO.setSLED(3, 10, 90)
sets status led configuration to blinking with 1s in ON period and 9s in OFF period, assigning return
value to res.
10
2.6.10 GPIO.getCBC()9
Gets charger status and battery voltage values in the same way as AT#CBC command. There are no
input parameter.
Return value is a Python tuple formatted in the following way:
(chargerStatus, batteryVoltage).
First element of tuple is a Python integer which is charger status:
10
Available only for modules with following Order-Num.: GM862PYT***-***, , GE863PYT***-***, , GM862GPS******, GE863GPS***-***, GC864PYT***-***, GC864PC2***-***, GE864PYH***-***, and the old 3990250657 and
3990250660
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 41 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
0 - charger not connected
1 - charger connected and charging
2 - charger connected and charging process completed
Second element of tuple is a Python integer which is battery voltage in mV.
Example:
cbc = GPIO.getCBC()
gets charger status and battery voltage values, assigning return value to cbc tuple.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 42 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.7 MOD built-in module
MOD built-in module is the interface between Python and module miscellaneous functions. You need
to use MOD built-in module if you want to generate timers in Python script.
If you want to use MOD built-in module you need to import it first:
import MOD
then you can use MOD built-in module methods like in the following example:
MOD.sleep(15)
this blocks Python script execution for 1.5s.
More details about MOD built-in module methods are in the following paragraphs.
2.7.1 MOD.secCounter()
Returns seconds elapsed since 1 January 2000. This method is useful for timers generation in Python
script. No input parameter.
Return value is a Python long integer which is the value of seconds elapsed since 1 January 2000.
AT+CCLK command allows to read and set current date and time.
Here are some useful constants:
• 1 day = 86400 seconds
• 1 year = 31536000 or 31622400 seconds
• 30 years from 1 January 1970 to 1 January 2000 = 946684800 seconds
(simply add this constant if you need seconds elapsed since 1 January 1970)
Example:
a = MOD.secCounter()
returns seconds elapsed since 1 January 2000.
2.7.2 MOD.sleep(sleeptime)
Blocks Python script execution for a given time returning the resources to the system. Input parameter
sleeptime is a Python integer which is measured in 1/10s and used to block script execution for given
value. No return value.
Example:
MOD.sleep(15)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 43 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
blocks Python script for 1.5 s.
NOTE: the parameter sleeptime can assume integer values is in the following range [0,32767]
2.7.3 MOD.watchdogEnable(timeout)
Protects system against script blocking by performing automatic reboot of the module when the
watchdog reaches determined value. Input parameter timeout is an integer, which is measured in
seconds and represents time to waiting before executing software restart. No return value.
Example:
MOD.watchdogEnable(50)
after 50sec from execution of this command module will be rebooted.
11
2.7.4 MOD.watchdogReset()11
Restarts watchdog counter that has been previously activated with the command
MOD.watchdogEnable(timeout) preventing in this way reboot of the module. It should be added in
every part of the script that can cause a script blocking (loops, etc) and is used only when Python
watchdog is enabled. No input value. No return value.
Example:
MOD.watchdogReset()
Restarts Python watchdog counter.
2.7.5 MOD.watchdogDisable()11
Disables Python watchdog that has been previously activated with the command
MOD.watchdogEnable(timeout). Python watchdog should be disabled before scripts critical lines such
as import, since it takes a long time and then enabled again after. No input value. No return value.
Example:
MOD.watchdogDisable()
11
feature available for the modules with the following Order-Num. : GM862PYT***-***, , GE863PYT***-***, ,
GM862GPS***-***, GE863GPS***-***, GC864PYT***-*** GC864PC2***-***, GE864PYH***-***,and the old
3990250657 and 3990250660
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 44 of 100
Disables Python watchdog.
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.7.6 MOD.powerSaving(timeout)
This new feature allows Python to put the system in power saving mode12 for a certain period or until
an external event
13
occurs in the same way as AT command AT+CFUN=0 does. Input parameter
11
timeout is an integer, which is measured in seconds and represents time for which the Python script
remains blocked. Python script will exit power saving mode when the determined value of timeout is
reached or after unsolicited signal. If the timeout has negative value Python script will exit from power
saving mode only when an external event occurs.
No return value.
Example:
MOD.powerSaving(100)
Python script will exit power saving mode after 100sec or when an external event occurs.
2.7.7 MOD.powerSavingExitCause()11
This command can be executed after MOD.powerSaving(timeout) and gives the cause of unblocking
the Python script. No input parameter.
Return value is a Python integer which is 0 if Python script has exit power saving mode after an
external event otherwise it is 1 if Python script has exit power saving mode after the timeout is
reached.
Example:
MOD.powerSavingExitCause()
gets the cause of exiting of Python script from the power saving mode
12
ATTENTION: when the script debugging is activated the module does not enter in power saving mode
13
an external event in this case can be: URC unsolicited message (ex. RING of incoming calls) or putting RTS
high (when it goes back low the power saving mode remains disabled)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 45 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.8 IIC built-in module
IIC built-in module14 is an implementation on the Python core of the IIC bus15 Master (No Multi-Master)
using the "bit-banging" technique.
You need to use IIC built-in module if you want to create one or more IIC bus on the available GPIO
pins. This IIC bus handling module is mapped on creation on two GPIO pins that will become the
Serial Data and Serial Clock pins of the bus. It can be created more than one IIC bus over different
pins and the pins used must not be used for other purposes.
NOTE: Python core does not verify if the pins are already used for other purposes (SPI module or
GPIO module) by other functions, it's the customer responsibility to ensure that no conflict over pins
occurs.
If you want to use IIC built-in module you need to import it first:
import IIC
then you can create the new bus over the GPIO pins (for example over the pins GPIO3, GPIO4) and
then use IIC built-in module methods like in the following example:
IICbus = IIC.new(3, 4, 0x50)
IICbus.init()
res = IICbus.readwrite('test', 10)
which sends 'test' and receives a string of 10 bytes from IIC bus device at address 0x50, assigning it
to res.
NOTE: you must provide external pull-up on SDA line since the line is working as open collector, on
the other hand SCLK is driven with a complete push pull.
More details about IIC built-in module object methods are in the following paragraphs.
2.8.1 IIC.new(SDA_pin, SCL_pin, <ADDR>)
This command creates a new IIC bus object on the GPIO pins number. Input parameter SDA_pin, SCL_pin are Python bytes, which are the GPIO pin number where the SDA (Serial Data) and SCL
(Serial Clock) lines are mapped. Optional parameter ADDR is the address of IIC bus device.
Return value is the Python custom IIC bus object pointer, which then shall be used to interface with
the IIC bus created.
Example:
myIIC1 = IIC.new(3,4,0x50)
14
Note: IIC module cannot be simulated in Python Win
15
With the following clock frequency: 0KHz min, 20KHz typical (idle mode)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 46 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
This creates one IIC bus over the lines SDA=GPIO3 and SCL=GPIO4 with default address 0x50. If no
address defined, the address anyway can be feed with the readwrite() function as first part of the
string.
NOTE: available pins for the IIC bus are GPIO1 - GPIO13. The only exception is the module family
GM862 where available pins are GPIO2 - GPIO13 where GPIO2 must be used only for output.
2.8.2 IIC object method: init()
This command does the first pin initialisation on the IIC bus previously created. It has no input
parameter. Return value is a Python integer that is -1 if an error occurred otherwise is 1.
Example:
This command can send a string or receive a string of read_len bytes from from IIC bus device at
address addr. First input parameter string is Python character while the second parameter read_len is
a Python integer used in process of reading data from the IIC bus and can assume values in the range
from 0 to 254.
Return value is a Python string which contains received data.
Example of use:
#start of I2C example for a particular I2C device
import IIC
import MOD
I2C_SCL = 12 # GPIO used for SCL pin
I2C_SDA = 4 # GPIO used for SDA pin
I2C_ADDR = 0x50 # myIIC1 address
NUM_REGS = 8 # max # of registers
myIIC1 = IIC.new(I2C_SDA, I2C_SCL, I2C_ADDR)
status = myIIC1.init()
#MOD.sleep(5)
print ' Writing from ADDR = 0x08, DATA = "Telit" '
if myIIC1.readwrite('\x08'+'Telit',0) == -1:
print 'Error acknowledged'
#MOD.sleep(5)
16
NOTE: it is not possible to perform at the same time reading and writing of the string
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 47 of 100
ret = myIIC1.readwrite('\x08', 14) # Random read
print ' RANDOM READ FROM ADDR = 0x08, 14 bytes: %s' % ret
#MOD.sleep(5)
print ' SETTING CURRENT ADDRESS = 0x00'
if myIIC1.readwrite('\x00',0) == -1:
print 'Error acknowledged'
#MOD.sleep(5)
ret = myIIC1.readwrite('', 22) # Current address read
print ' CURRENT ADDR READ = 0x00, 22 bytes: %s' % ret
MOD.sleep(5)
ret = myIIC1.readwrite('\x00', 254) # Current address read
print ' read 254 bytes with readwrite: %s' % ret
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.8.4 IIC object method: sendbyte(byte)
Sends a byte to the IIC bus previously created. Input parameter byte is a Python byte which is the byte
to be sent to the IIC bus. The start and stop condition on the bus are added by the function.
Return value is a Python integer which is -1 if an error occurred otherwise is 1 the byte has been
acknowledged by the slave.
Example:
Supposing to set:
bus1 = IIC.new(3,4)
bus2 = IIC.new(5,6)
a = bus1.init()
then:
a = bus1.sendbyte(123)
sends byte 123 to the IIC bus , assigning return result value to a.
2.8.5 IIC object method: send(string)
Sends a string to the IIC bus previously created. Input parameter string is a Python string which is the
string to send to the IIC bus.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 48 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Return value is a Python integer which is -1 if an error occurred otherwise is 1 if all bytes of the string
have been acknowledged by the slave.
Example:
a = bus1.send('test')
sends string 'test' to the IIC bus , assigning return result value to a.
2.8.6 IIC object method: dev_read(addr, len)
Receives a string of len bytes from IIC bus device at address addr.
Return value is a Python string which is containing data received.
Example:
a = bus1.dev_read(114,10)
receives a string of 10 bytes from IIC bus device at address 114, assigning it to a.
2.8.7 IIC object method: dev_write(addr, string)
Sends a string to the IIC bus device at address addr.
Return value is a Python string which is 1 if data is acknowledged correctly, -1 otherwise.
Example:
a = bus1.dev_write(114,'123456789')
sends the string '123456789' to the IIC bus device at address 114, assigning the result to a.
Receives a string of len bytes from IIC bus device whose address is addr, starting from address start.
Return value is a Python string which is containing data received.
Example:
a = bus1.dev_gen_read(114,122, 10)
receives a string of 10 bytes from IIC bus device at address 114, starting from address 122 assigning
it to a.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 49 of 100
Sends a string to the IIC bus device whose address is addr, starting from address start.
Return value is a Python string which is 1 if data is acknowledged correctly, -1 otherwise.
Example:
a = bus1.dev_gen_write(114, 112, '123456789')
sends the string '123456789' to the IIC bus device at address 114, starting from address 112,
assigning the result to a.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 50 of 100
2.9 SPI built-in module
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
SPI built-in module
banging" technique. You need to use SPI built-in module if you want to create one or more SPI bus on
the available GPIO pins.
This SPI bus handling module is mapped on creation on three or more GPIO pins that will become the
Serial Data In/Out and Serial Clock pins of the bus, plus a number of optional chip select pins up to 8.
It can be created more than one SPI bus over different pins and these pins must not be used for other
purposes.
NOTE: Python core does not verify if the pins are already used for other purposes (IIC module or
GPIO module) by other functions, it's the customer responsibility to ensure that no conflict over pins
occurs.
If you want to use SPI built-in module you need to import it first:
import SPI
the functions to use are: create your SPI object (new), initialize (init) and transfer data (readwrite) like
in the example:
This command creates a new SPI bus object on the corresponding GPIO pins. Input parameter
SCLK_pin, MOSI_pin and MISO_pin are Python bytes that represent the GPIO pin number where the
SCLK (Serial CLocK), MOSI (Master Output Slave Input), MISO (Master Input Slave Output) lines are
mapped.
Input parameter SSi_line is a mandatory Python byte if the SPI device needs to be selected by Slave
Select line: it is the GPIO pin number where the SSi (i
Select lines can be defined.
17
Note: SPI module cannot be simulated in Python Win
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 51 of 100
th
Slave Select) line is mapped. Up to 8 Slave
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
The SS_pin is optional because not all SPI devices have a Slave Select line, otherwise named Chip
Select (CS) line.
Return value is the Python custom SPI object pointer that will be used further to interface with this
specific SPI object created.
Example:
mySPIobject = SPI.new(6, 7, 8, 9, 10)
Creates an SPI object “mySPIobject” where SCLK=GPIO6, MOSI=GPIO7, MISO=GPIO8 and
SS0=GPIO9, SS1=GPIO10
NOTE: available pins for the SPI bus are GPIO1 - GPIO13. The only exception is the module family
GM862 where available pins are GPIO3 - GPIO13.
This command performs the initialization on the SPI bus previously created, and can be reused as
many time as necessary if some of its parameters need changes during work.
First input parameter CPOL represents clock polarity and is controlled in the following way:
• CPOL = 0 - clock polarity low
• CPOL = 1 - clock polarity high
Second input parameter CPHA represents clock phase transmission and is controlled in the following
way:
• CPHA = 0 - data bit is clocked/latched on the first edge of the SCLK.
• CPHA = 1 - data bit is clocked/latched on the second edge of the SCLK.
The combinations of polarity and phases are often referred to as SPI modes.
Third parameter SSPOL is optional and represents the Slave Select Polarity and can assume the
following values:
• SSPOL = 0 - polarity low (default)
• SSPOL = 1 - polarity high
Fourth parameter SS is optional and represents the Default Slave Select line number to use among
the already defined slave select (SS) lines for this SPI object and then it can assume values from 0 to
7.
•SS = unused - means that if not SS settled in readwrite() parameter’s function, no SS will be
moved.
•SS = 0…7 – Defined the default SS line to move if not SS settled in readwrite() parameter’s
function.
Return value is a Python integer, which is -1 if an error occurred, otherwise is 1.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 52 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Example:
status = mySPIobject.init(0, 0, 0)
In this initialization no SS line is defined as default, and no SS line will be moved if not set in readwrite
function.
status = mySPIobject.init(0, 0, 0, 1)
In this initialization the SS=1 refers to the use of SS1, already defined in SPI.new(6, 7, 8, 9, 10) as
GPIO10.
status = mySPIobject.init(0, 0, 0, 0)
In this initialization the SS=0 refers to the use of SS0, already defined in SPI.new(6, 7, 8, 9, 10) as
GPIO9.
This command sends string and receives read_len bytes at the same time from SPI bus device at
Slave Select line number SS.
First input parameter string is a Python string while the second optional
18
parameter read_len is a
Python integer used only for reading data and can assume values in the range from 0 to 254.
The third optional input parameter SS, if defined, selects which of SS line number defined in SPI.new
will be used and, if not defined, the default Slave Select line number in SPI.init, if any, will be used.
Return value is a Python string that contains (read_len bytes) of sent and/or received data, in case an
error occurs return value will be –1 or NULL if is memory error.
Example:
myString = mySPIobject.readwrite(‘hello’, 10)
send the string "hello" and receives a string of 10 bytes from the SPI device, assigning it to myString
Example of writing and reading of a memory in a particular SPI device (addressable by a Slave Select
pin)
#start of SPI example
import SPI
import MOD
import MDM
import GPIO
CMD_WRITE = '\x02' #this value is not the value for any SPI device, but for tested one only!
CMD_READ = '\x03' #this value is not the value for any SPI device, but for tested one only!
18
In case of read operation this parameter is obligatory
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 53 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
CMD_RESET = '\xC0'
REG_ADDR_X = '\x0E' #this value is not the value for any SPI device, but for tested one only!
REG_ADDR_Y = '\x0F' #this value is not the value for any SPI device, but for tested one only!
TWO_READ_ACCESS = '\x00\x00' # string of the length equal to the number of bytes to receive
myString = MySPI1.readwrite (CMD_READ + REG_ADDR_X, 4)
print "DATA VALUE AT ADDR_X and _Y =",hex(ord(myString[2]))+' and '+ hex(ord(myString[3]))
# values of myString [0] and myString [1] correspond to the status output while writing
myString = MySPI1.readwrite(CMD_READ + REG_ADDR_X + TWO_READ_ACCESS,4)
# does the same as previous: this is to maintain the backward compatibility with the past version of the
readwrite method
ret = MySPI1.readwrite (CMD_READ, 129) # read first byte (cmd) plus 128 bytes starting from the last
position
i = 0
print "STATUS =",hex(ord(ret[i]))
while (i < 128):
print "REGISTER[",hex(i),"]:",hex(ord(ret[i + 1]))
i = i + 1
NOTE: We advice to use the new readwrite (2.9.3) method to send bytes or strings.
Sends a byte to the SPI bus previously created
Slave Select signal is activated. Input parameter byte is a Python byte which is the byte to be sent to
the SPI bus. Optional parameter SS_number is a Python byte representing the Slave number to be
activated; if not present no slave line is activated.
Return value is a Python integer which is -1 if an error occurred otherwise is 1 the byte has been sent.
Example:
a = bus3.sendbyte(123)
sends byte 123 to the SPI bus , assigning return result value to a.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 54 of 100
addressed for the Slave number SS_number whose
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
b=bus4.sendbyte(111,1)
sends byte 111 to the SPI bus activating the Slave Select line of the SS1 device (in our example
GPIO10)
2.9.5 SPI object method: readbyte(<SS_number>)
NOTE: We advice to use the new readwrite (2.9.3) method to send bytes or strings.
Receives a byte from the SPI bus device at Slave Select number SS_number. Input optional
parameter SS_number is a Python byte representing the Slave number to be activated; if not present
no slave line is activated.
Return value is a byte (integer) received from the SPI bus device if no data is received the return value
will be zero.
Example:
a = bus3.readbyte()
receives a byte from the SPI bus , assigning return result value to a.
b=bus4.readbyte(1)
receives a byte from the SPI bus device on SS1 line, assigning return result value to b.
NOTE: We advice to use the new readwrite (2.9.3) method to send bytes or strings.
Sends a string to the SPI bus previously created. Input parameter string is a Python string which is the
string to send to the SPI bus. Optional parameter SS_number is a Python byte representing the Slave
number to be activated; if not present no slave line is activated.
Return value is a Python integer which is -1 if an error occurred otherwise is 1 if all bytes of the string
have been sent.
Example:
a = bus3.send('test')
sends string 'test' to the SPI bus , assigning return result value to a.
2.9.7 SPI object method: read(len, <SS_number>)
NOTE: We advice to use the new readwrite (2.9.3) method to send bytes or strings.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 55 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Receives a string of len bytes from SPI bus device at Slave Select number SS_number. Input optional
parameter SS_number is a Python byte representing the Slave number to be activated; if not present
no slave line is activated.
Return value is a Python string that contains received data.
Example:
a = bus4.read(10,0)
receives a string of 10 bytes from SPI bus device on SS0 line, assigning it to a.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 56 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.10 GPS19 built-in module
GPS built-in module is the interface between Python and mobile internal GPS controller. It is used in
order to handle GPS controller without dedicated AT commands through MDM built-in module.
If you want to use GPS built-in module you need to import it first:
import GPS
After this you can start using GPS built-in module methods like in the following example:
position = GPS.getActualPosition()
gets a string with position information formatted in the same way as AT$GPSACP response.
More details about GPS built-in module methods can be found in the following paragraphs.
2.10.1 GPS. powerOnOff(newStatus)
This module powers ON/OFF GPS controller in the same way as AT command: AT$GPSP.
Input parameter newStatus is a Python integer and can have the following values:
• 0 to power OFF GPS controller
• 1 to power ON GPS controller.
There is no return value.
Example:
GPS.powerOnOff(0)
GPS controller is powered OFF.
2.10.2 GPS.getPowerOnOff()
This module gets GPS controller current power ON/OFF status. It has no input parameter.
Return value is a Python integer which is 0 if GPS controller is powered off or 1 if GPS controller is
powered on.
Example:
status = GPS.getPowerOnOff()
gets GPS controller current power ON/OFF status, assigning return value to status.
19
Available only for modules with following Order-Num.: GM862GPS***-***, GE863GPS***-*** and the old
3990250657 and 3990250660,
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 57 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.10.3 GPS.resetMode(mode)
This module resets GPS controller in the same way as AT command: AT$GPSR. Input parameter
mode is a Python integer and can have the following values:
• 0 for Hardware reset
• 1 for Coldstart (No Almanac, No Ephemeris);
• 2 for Warmstart (No Ephemeris);
• 3 for Hotstart (with stored Almanac and Ephemeris).
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
res = GPS.resetMode(1)
executes a cold restart of GPS controller, assigning return value to res.
2.10.4 GPS.getAntennaVoltage()
This module gets GPS antenna supply voltage in the same way as AT command: AT$GPSAV.
It has no input parameter.
Return value is a Python integer which represents antenna supply voltage in mV.
Example:
mV = GPS.getAntennaVoltage()
gets GPS antenna supply voltage, assigning return value to mV.
2.10.5 GPS.getAntennaCurrent()
This module gets GPS antenna current consumption in the same way as AT command: AT$GPSAI.
It has no input parameter.
Return value is a Python integer which represents antenna current consumption in mA.
Example:
mA = GPS.getAntennaCurrent()
gets GPS antenna current consumption, assigning return value to mA.
2.10.6 GPS.getActualPosition()
This module gets GPS last position information stored in the same way as with AT command:
AT$GPSACP. It has no input parameter.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 58 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Return value is a Python string which is the last position information formatted in the same way as for
AT$GPSACP command response.
Example:
lastPosition = GPS.getActualPosition()
gets GPS last position information, assigning return value to lastPosition.
2.10.7 GPS.powerSavingMode(mode, pushToFixPeriod)
This module sets GPS controller power saving mode in the same way as AT command AT$GPSPS.
First input parameter mode is a Python integer and can have the following values:
• 0 for Power Saving disabled – Continuous Power (default);
• 1 for Trickle Power activated;
• 2 for Push To Fix Mode enabled.
Second input parameter pushToFixPeriod is a Python integer which is the value of push to fix period in
seconds used when mode=2. If mode= 0 or mode= 1 this parameter has no meaning and can be set
to any value.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
res = GPS.powerSavingMode(2, 15)
sets GPS controller in power saving mode 2 with push to fix period of 15 seconds, assigning return
value to res.
2.10.8 GPS.powerSavingWakeUp()
This command wakes up GPS controller while in power saving mode in the same way as AT
command AT$GPSWK.
It has no input parameter.
Return value is a Python integer which is -1 if an error occurred otherwise is 1.
Example:
res = GPS.powerSavingWakeUp()
wakes up GPS controller while in power saving, assigning return value to res.
2.10.9 GPS.getLastGGA()
This command gets GPS last GGA NMEA sentence stored. It has no input parameter.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 59 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Return value is a Python string which is the last GGA NMEA sentence formatted according to NMEA
specification.
Example:
gga = GPS.getLastGGA()
gets last GGA NMEA sentence, assigning return value to gga.
2.10.10 GPS.getLastGLL()
This command gets GPS last GLL NMEA sentence stored. It has no input parameter.
Return value is a Python string which is the last GLL NMEA sentence formatted according to NMEA
specification.
Example:
gll = GPS.getLastGLL()
gets last GLL NMEA sentence, assigning return value to gll.
2.10.11 GPS.getLastGSA()
This command gets GPS last GSA NMEA sentence stored. It has no input parameter.
Return value is a Python string which is the last GSA NMEA sentence formatted according to NMEA
specification.
Example:
gsa = GPS.getLastGSA()
gets last GSA NMEA sentence, assigning return value to gsa.
2.10.12 GPS.getLastGSV()
This command gets GPS last GSV NMEA sentence stored. It has no input parameter.
Return value is a Python string which is the concatenation of the last GSV NMEA sentences formatted
according to NMEA specification.
Example:
gsv = GPS.getLastGSV()
gets last GSV NMEA sentence, assigning return value to gsv.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 60 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.10.13 GPS.getLastRMC()
This command gets GPS last RMC NMEA sentence stored. It has no input parameter.
Return value is a Python string which is the last RMC NMEA sentence formatted according to NMEA
specification.
Example:
rms = GPS.getLastRMC()
gets last RMC NMEA sentence, assigning return value to rmc.
2.10.14 GPS.getLastVTG()
This command gets GPS last VTG NMEA sentence stored. It has no input parameter.
Return value is a Python string which is the last VTG NMEA sentence formatted according to NMEA
specification.
Example:
vtg = GPS.getLastVTG()
gets last VTG NMEA sentence, assigning return value to vtg.
2.10.15 GPS.getPosition()
This command gets GPS last position stored in numeric format. It has no input parameter.
Return value is a Python tuple formatted in the following way <latitude, latNorS, longitude, lonEorW>
where:
• First element of tuple is a Python integer which is latitude in (degrees * 10000000), that is in
degrees with 10000000 scale factor.
• Second element of tuple in a Python string which is ‘N’ for north or ‘S’ for south.
• Third element of tuple is a Python integer which is longitude in (degrees * 10000000), that is
in degrees with 10000000 scale factor.
• Fourth element of tuple in a Python string which is ‘E’ for east or ‘W’ for west.
If GPS controller has no position information the following tuple is returned:
(0, ‘’, 0, ‘’).
Example:
pos = GPS.getPosition()
gets last position stored, assigning return value to pos.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 61 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
3 Python Script Operations
3.1 Executing a Python script
The steps required to have a script running by the python engine of the module are:
• write the python script;
• download the python script into the module NVM;
• enable the python script;
• execute the python script.
3.1.1 Write Python script
A Python script is a simple text file, it can be written with any text editor but for your convenience a
complete Integrated Development Environment (IDE) is included in a software package that Telit
provides called Telit Python Package.
Remembering the supported features described in 1.6, it is simple to write the script and test it directly
from the IDE.
The followin
command parser, waits for response and then ends.
import MDM
print 'Hello World!'
result = MDM.send('AT\r', 0)
print result
c = MDM.receive(10)
print c
g is the "Hello Word" short Python script that sends the simplest AT command to the AT
• < know-how >: know how protection, 1 = on, 0 = off (default)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 62 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
The script can be downloaded on the module using the #WSCRIPT command. In order to guarantee
your company know-how, you have the option to hide the script text so that the #RSCRIPT command
does not return the text of the script and keeps it "confidential", you can see only the name of the
script with the #LSCRIPT command.
Remember that if you chose to hide the script text it is your responsibility to keep the information about
what is executed on the module; for example by naming the script depending from the application and
version of the script.
In order to download the script, first you have to choose a name for your script in the module taking
care that:
• it must have extension .py
20
;
• the maximum allowed length is 16 characters;
• script name is case sensitive (“Script.py” and “script.py” are two different scripts).
Then you have to find out the exact size in bytes of the script (for example right clicking on the file and
selecting “size” in “properties”, attention: not “size on the disc”)
The script download in Hyper Terminal is done regardless the previous serial settings at: 115200 baud
8-N-1 with hardware flow control active.
20
Only the file that will be executed afterwards must have the extension .py. In download phase the files can
also have .pyo extension (altreday compiled files) or any other binary format.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 63 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
For example:
AT#WSCRIPT=”a.py”,110
wait for the prompt
>>>
and use “Send Text file” with ASCII Setup: “Send line ends with line feeds” and “Append line feeds to
incoming line ends” in HyperTerminal “Properties” enabled.
Wait for download result: OK or ERROR.
TIP: If download result gives ERROR check if the script name (remember that it is case sensitive) or
the file size are correct.
Another way to perform download is: disconnecting in Hyper Terminal, when the prompt appears, then
right clicking on the file and selecting “download”, when the download ends reconnecting in Hyper Terminal.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 64 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
If instead of Hyper Terminal you use Procomm Plus application the script text should be sent using
“Send File”, selecting “Raw ASCII” or “ASCII” as Transfer Protocol. If you use “ASCII” transfer
protocol, be sure the options “Expand tabs” and “Expand black lines” are not selected.
3.1.3 Enable Python script
Command: AT#ESCRIPT=“< script_name >“
AT#ESCRIPT?
• < script_name >: file name
Select the Python script which will be executed (the enabled script) from the next start-up and in every
future start-up using the AT#ESCRIPT command. In case the Python script consists of more than one
file only the main file should be executed.
First choose the script you want to enable between the ones you’ve downloaded:
AT#LSCRIPT? can help you checking the names of the scripts;
AT#ESCRIPT? can help you check the name of the script that is enabled at the moment
NOTE: There is no error return value for non existing script name in the module memory typed in
command AT#ESCRIPT. For this reason it’s recommended to double check the name of the script
that you want to execute. On the other hand this characteristic permits additional possibilities: like
enabling the Python script before downloading it on the module or non having to enable the same
script name every time the script has been changed, deleted and replaced with another script but with
the same name. Note also that the file extension must be .py.
For example:
AT#ESCRIPT=”a.py”
Wait for enable result: OK.
3.1.4 Execute Python script
The Python script you have downloaded to module and enabled is executed at every module power
on if the DTR line is sensed LOW (2.8V at the module DTR pin - RS232 signals are inverted -) at startup, (in this case no AT command interface is connected to the modem port) and if the script name you
enabled matches with one of the script names of the scripts you downloaded.
21
Note: Python script will be executed when the module is powered ON and if the serial cable has previously
been disconnected.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 65 of 100
21
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
In order to gain again the AT command interface on the modem physical port (for example to update
locally a new script) the module shall be powered on with the DTR line HIGH (0V at the module DTR
pin) so that the script is not executed and the Python engine is stopped. The real execution of the
Python script is delayed from the power on due to the time needed by Python to parse the script. The
longer is the script, the longer is this delay.
NOTE: that only the running script is compiled at run time, all the others that this script may include
are compiled once and the compiled result is saved in the NVM as a file with extension .pyo. This
delay can be greatly reduced with a simple stratagem:
• type your script normally, and include the main loop in a function, for example "main()", save it
to the NVM of the module with a known name, for example appl.py
• write a new script that includes the previous file object, for example "import appl", and this file
should call only the main function of the appl.py script, for example main().
In this way the first time the script is executed the imported files will be compiled and the result saved
as compiled .pyo files (don't delete them during normal operations, but remember to delete them if you
change the corresponding .py script otherwise your changes will not take effect). From the next startup and in every future start-up the imported files will not be anymore compiled and script execution
delay is greatly reduced.
This trick is useful also for long complex scripts, which may run out of memory during compilation;
splitting the script into several smaller scripts containing part of the functions/objects definitions will
separate the compilation and allow for much bigger script usage.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 66 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
3.1.5 Reading Python script
Command: AT#RSCRIPT=“< script_name >“
• < script_name >: file name
With the following command AT#RSCRIPT you can read a saved script text. The script text read can
be saved using “Capture Text” in HyperTerminal or “Capture File” in Procomm Plus application. Port
settings should be baud rate 115200bps and hardware flow control.
If know-how protection is activated than AT#RSCRIPT will return only OK: no Python script source
code will be returned. In this way nobody will be able to read your Python script from the module.
The Python script will be still in the Python script list and it will be still possible to delete it and to
overwrite it.
Example:
AT#RSCRIPT=”a.py”
returns Python script source code a.py
3.1.6 List saved Python scripts
Command: AT#LSCRIPT?
This is a read command that shows the list of the script names currently saved and number of free
bytes in memory. No input parameter.
3.1.7 Deleting Python script
Command: AT#DSCRIPT=“< script_name >“
• < script_name >: file name
The Python script can be deleted from the module memory using the #DSCRIPT command.
For example:
AT#DSCRIPT=”a.py”
Wait for result: OK.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 67 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
NOTE: Commands used to write, read and delete script like AT#WSCRIPT, AT#LSCRIPT,
AT#RSCRIPT and AT#DSCRIPT can be applied on any type of file, not necessary an executable
Python script. (example: received data files)
3.1.8 Restart Python script
Command: AT#REBOOT
This is an execution command that causes the restart of the module and execution of the active script
on the start-up.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 68 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
3.2 Run AT Interface and Python at the same time
With new start mode for Python it is possible to use standard AT command interface on ASC0 and run
a Python script at the same time. This behavior can be obtained with the following AT command:
AT#STARTMODESCR=2
When this command is set, note that the following differences with the standard use of AT interface
will appear:
• AT command interface is available on ASC0 and is connected to third AT instance parser.
Note that parameters saved in profiles can be different between different AT instance parsers,
so in this case only setting from the third AT instance parser will be applied.
• AT command interface is available on ASC0 and is connected to third AT instance parser even
while the script is not enabled (AT#ESCRIPT) and is not running.
• AT command interface is available on ASC0 and continues to be connected to third AT
instance parser also in case Python script exits, for an error or ends normally.
• AT command interface will not be available on ASC0 if the Python script imports module SER.
• For backward compatibility MDM interface must stay connected to first AT instance parser and
MDM2 interface must stay connected to second AT instance parser.
• If there is an enabled Python script and the module is powered-on the Python script will start
running, the only way to interrupt its execution is to disable it by sending AT#ESCRIPT and
reboot the Telit module. Another possibility is to change script startmode with
AT#STARTMODESCR
23
command by setting parameter values to 0 or 1 while the Python
script is running and rebooting the Telit module afterwards.
• This mode is not compatible with setting AT#CMUXSCR=1.
22
22
Normally, AT command interface on ASC0 is connected to first AT instance parser (in case we’re use the
serial port with or without CMUX and there is no Python script running) while in case of
AT#STARTMODESCR=2 CMUX is activated and third CMUX port will be used for AT command interface (which
means that settings from the third AT instance parser will be applied).
23
For further information on this AT command and parameter settings please consult AT Commands Reference
Guide
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 69 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
3.3 Debug Python script
The debug of the active Python script can be done both on the emulated environment of the Telit
Python Package (refer to its documentation) or directly on the target with the second serial port pin
EMMI TX (actually a not translated RS232 serial port as the RXD pin).
Connect to the module serial port EMMI TX at 115200 8-N-1 with hardware flow control active.
Now you can see all Python outputs to stdout and stderr:
• Python information messages (for example the version);
• Python error information;
• Results of all Python “print” statements.
The Telit GM862-GPS and GE863-GPS have the second serial port pin EMMI TX used for continuous
direct output of GPS NMEA sentences that’s why there is another procedure to follow for debugging of
the Telit GPS modules. There are two ways to perform direct debugging: activate SSC port or use
CMUX.
3.3.1 Debug Python script on GPS modules using SSC bus
SSC (Serial Synchronous Controller) port can be configured to be compatible to the SPI Interface,
available via 4 GPIO pins. In this case the Python debug data will be read from the USB port placed
on the EVK2.
NOTE: for the direct debug of GPS modules a software version starting from 7.02.001 is needed
3.3.1.1 Installation of the drivers
Before starting the process of debug the drivers should be installed in the following way:
• Download the FTDI drivers and the installation guide in order to use the USB port placed
on the EVK2 (http://www.ftdichip.com/Drivers/D2XX.htm
• Save the drivers (unzipped) on the PC
• After connecting USB cable with PC and USB port placed on the EVK2 (that has been
powered on): the installation procedure should start, according to the installation guide
instructions
• When the installation is concluded you will have four new COM ports (see Control Panel –
System – Hardware – Device Manager) and one not visible SSC port
)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 70 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
• close any application controlling the serial ports and install the Python Debug application
(please contact our technical support to get Python Debug application)
NOTE: if an error messages appears during the installation, it will be necessary to close any
application controlling the serial ports
• the following box should appear when you run the Pythondebug.exe for the first time:
• Select the Setup option.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 71 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
• Then select a Virtual COM, different from the other COM ports preferably (“COM8” in the
figure), and associate to it the first SSC device that appearing in the list (“Data Module
EVK2A” in the figure),
• the following figure should appear:
NOTE: If the PC uses the EVK2 RS232 upper port (ASC0) to send AT commands, remember
to put all jumpers to set RS232 mode. This will not affect reading of Python debug data from
the USB port
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 72 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
3.3.1.2 Debugging process
After the successful installation of the drivers process of direct debugging of the Telit GPS modules
can start. The steps are the following:
• Switch on the module and activate the SSC output with the following AT command:
AT#SSCTRACE=1
• Download and enable your Python script, then power OFF the module.
• to be sure that DTR input to the module is HIGH disconnect the RS232 cable from the
module side (i.e. RS232 DTR on the modem serial port is LOW);
• check if you have the USB cable connected between the USB port of the PC and the USB
port placed on the EVK2
• every time before you power ON the module you have to click on the Reset button in the
Python Debug application (necessary to reactivate the association between the virtual Com
port and the SSC device)
• Run a terminal emulator application (e.g. Hyper Terminal) to trace the activity of the Python
script, with the following setting:
connected
COM
Bit rate
Data bits
Parity
Stop bit
Flow control
• Power ON the module and you should see the script starting and the debug info appearing
on the terminal emulator window.
• If the debug strings do not appear on the screen: power OFF the module, check again if
USB cable is correctly connected, reset the Python Debug application, than power ON the
module and run the terminal emulator application with the same settings as before.
virtual Port set in Python
Debug (COM8 in the
example)
115 200
8
No parity
1
Hardware
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 73 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
3.3.2 Debug Python script on GPS modules using CMUX
CMUX (Converter-Multiplexer) is a multiplexing protocol implemented in the Telit module that can be
used to send data, SMS, fax, TCP data. The Multiplexer mode enables one serial interface to transmit
data to four different customer applications form which one is dedicated to Python debug. This is
achieved by providing four virtual channels using a Multiplexer (Mux).
With activating of the CMUX feature debugging data can be received on the serial ASC0 port mounted
on EVK2.
NOTE: for the direct debug of GPS modules a software version starting from 7.02.X01 is needed.
3.3.2.1 Installation
• Install the Telit Serial Port Mux ver 1.08-B001
will appear at the end of installation:
24
application on your PC. A box similar to this
• Select the baud rate and then click on the Apply button
3.3.2.2 Debugging process
NOTE: If the PC uses the EVK2 RS232 upper port (ASC0) to send AT commands, remember
to put all jumpers to set RS232 mode.
24 please contact our technical assistance to get the latest application version
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 74 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
• Switch ON the module and with a terminal emulator (e.g. Hyper Terminal) and send the
following commands to the module:
AT#SSCTRACE=0 disabled SSC output
AT#CMUXSCR=1,<bitrate> activated the CMUX feature on the module; put the desired
bit rate (e.g. 115200)
AT#STARTMODESCR=1,10 module waits for minimum 10 seconds (recommended
value; can be changed) and if there is no AT commands sent in this period (except
AT<Enter>) start the enabled Python script, regardless of the DTR status (low or high).
• Download and enable
25
your Python script, then power OFF the module.
• Close any application controlling the serial ports (e.g. Hyper Terminal)
• Run the Telit Serial Port Mux ; a figure similar to the one below will appear:
25
follow the procedure of download and enable of the Python script reported in the paragraph 3.2 and 3.3
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 75 of 100
Control if the Setup options are the following:
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Set the Module Main Port as the real COM port you have available (e.g. COM1 in the figure), check
the Python box and then select the Apply button.
• After this step, you will have 4 new Telit Serial Port Mux ports (see Control Panel – System –
Hardware – Device Manager) as in the figure below:
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 76 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
• Run a terminal emulator application (e.g. Hyper Terminal) to trace the activity of the Python
script, with the following setting:
connected
COM
Bit rate
Data bits
Parity
Stop bit
Flow control
virtual port #4 set in Telit
CMUX window (COM10 in
the figure)
115 200
8
No parity
1
Hardware
In the Telit Serial Port Mux window, “Status:” of the Virtual Port#4, after establishing
connection in Hyper Terminal, will change from Idle to Opened
• Power on the module and wait for at least 10 seconds without sending any AT command
(except AT<Enter>);
In the Telit Serial Port Mux window, “Status:” of the Modem Port: will change in the
following way (before 10 seconds expired):
Idle Æ cycle between Connecting and Error Æ Connected
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 77 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
After 10 seconds you should see the script starting and the debug info appearing on the
terminal emulator window.
• If an ERROR messages appears in the Virtual Port #1,2,3,4 boxes, close any application
controlling the serial ports and then restart the Telit CMUX application. If this procedure is not
sufficient to avoid ERROR message, reset the PC, run again Telit Serial Port Mux with the
same settings and repeat the procedure as described above.
• If you need to debug the same Python application again, then:
• Disconnect the terminal emulator application (eg. Hyper Terminal) from the Virtual
Port#4 (in this case COM10)
•“Status:” of the Virtual Port#4 in the Telit Serial Port Mux window, should change
from Opened to Idle
• Switch off the module
• Connect the terminal emulator application to Virtual Port#4 (in this case COM10)
26
•“Status:” of the Virtual Port#4 in the Telit Serial Port Mux window
, should change
from Idle to Opened
•Switch on the module and wait for the “Status:” of the Modem Port in the Telit Serial
Port Mux window to go connected
26
If the Telit Serial Port Mux application seems to be freezed, please consider that it becomes active after the
module is switched on.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 78 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4 Python standard functions
In this paragraph you can find detailed description of Python language supported features in Data
Terminal Modules. Note that all the functions listed below are available in the Python version is 1.5.2+.
4.1 Technical characteristics
4.1.1 General
All Python statements and almost all Python built-in types and functions are supported. See in the
table below the features not supported:
Available built-in modules are:
All others are not supported.
complex
float
docstring
marshal
imp
__main__
__builtin__
sys
md5
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 79 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2 Python supported features
Refer to the documents available online such as: Python 1.5.2 Tutorial, Python 1.5.2 Reference
Manual or Python 1.5.2 Library Reference for further details for all the features listed in the paragraphs
below.
4.2.1 Operators, statements, functions
List of supported operators, statements, functions:
• comments #
• line joining \
• operators +, -, *, /, **, %
• operators <<, >>, &, |, ^, ~
• parentheses
• assignment
• comparison operators <, >, ==, <=, >=, !=, <>
• print statement
• if, elif, else statement
• indentation
• and, or, not keywords
• for in statement
• while statement
• range() function
• break and continue statements
• pass statement
• functions (without docstrings) (def)
• return statement
• objects
• object methods
• del statement
• modules
• import statement
• from statement
• exceptions
• try except finally statements
• raise statement
• classes (class)
• class instances
• global statement
• is, is not tests
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 80 of 100
• exec statement
4.2.2 Truth Value Testing
Truth value testing is supported.
4.2.3 Boolean Operations
The following Boolean operations are supported:
x or y
x and y
not x
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.4 Comparisons
The following comparisons are supported:
<
<=
>
>=
==
<>
!=
is
is not
4.2.5 Numeric Types: Integers
The following operations are supported with the integer type:
x + y
x - y
x * y
x / y
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 81 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
x % y
-x
+x
abs(x)
int(x)
long(x)
divmod(x, y)
pow(x, y)
x ** y
x | y
x ^ y
x & y
x << n
x >> n
~x
4.2.6 Numeric Types: Long Integers
The following operations are supported with long integers:
x + y
x - y
x * y
x / y
x % y
-x
+x
abs(x)
int(x)
long(x)
divmod(x, y)
pow(x, y)
x ** y
x | y
x ^ y
x & y
x << n
x >> n
~x
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 82 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.7 Numeric Types: Float
Floating point numbers are not supported.
4.2.8 Numeric Types: Complex
Complex numbers are not supported.
4.2.9 Sequence Types: Strings
The following operations are supported with the string type:
The only difference between Python version 1.5.2+ and 1.5.2 is that strings are objects that support
the following methods:
The following operations are supported with the tuples:
x in s
x not in s
s + t
s * n, n * s
s[i]
s[i:j]
len(s)
min(s)
max(s)
4.2.11 Sequence Types: Lists
The following operations are supported with the lists:
x in s
x not in s
s + t
s * n, n * s
s[i]
s[i:j]
len(s)
min(s)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 84 of 100
The following attribute is supported:
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
max(s)
s[i] = x
s[i:j] = t
del s[i:j]
s.append(x)
s.extend(x)
s.count(x)
s.index(x)
s.insert(i, x)
s.pop([i])
s.remove(x)
s.reverse()
s.sort([cmpfunc])
__methods__
4.2.12 Mapping Types: Dictionaries
The following operations are supported with the dictionaries:
The following attribute is supported:
len(a)
a[k]
a[k] = x
del a[k]
a.clear()
a.copy()
a.has_key(k)
a.items()
a.keys()
a.update(b)
a.values()
a.get(k[, x])
__methods__
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 85 of 100
4.2.13 Other Built-in Types: File Objects
The following methods are supported with the file objects:
The following method is not supported:
The following attributes are supported:
f.readlines([sizehint])
f.close()
f.flush()
f.isatty()
f.fileno()
f.read([size])
f.readline([size])
f.seek(offset[,
whence])
f.tell()
f.write(str)
f.writelines(list)
f.truncate([size])
__methods__
softspace
mode
name
closed
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.14 Other Built-in Types: Modules
Modules objects and modules attribute access are supported.
The following attributes are supported:
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 86 of 100
__dict__
__name__
4.2.15 Other Built-in Types: Classes
Classes objects, class attribute access and class instances are supported.
The following attributes are supported:
The following attributes are supported by class methods:
The following special methods are supported:
__init__(self [, args...])
__getattr__(self, name)
__setattr__(self, name, value)
__delattr__(self, name)
__dict__
__name__
__bases__
__module__
im_func
im_self
im_class
__del__(self)
__repr__(self)
__str__(self)
__cmp__(self, other)
__hash__(self)
__nonzero__(self)
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.16 Other Built-in Types: Functions
Functions objects and function call are supported with the following attributes:
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 87 of 100
func_code
func_globals
func_name
func_defaults
__name__
4.2.17 Other Built-in Types: Methods
Methods objects are supported with the following attributes:
__name__
__self__
4.2.18 Other Built-in Types: Type Objects
Type objects are supported.
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.19 Other Built-in Types: Null Object
Null object is supported.
4.2.20 Other Built-in Types: Ellipsis Object
Ellipsis object is supported.
4.2.21 Other Built-in Types: Buffer Objects
Buffer objects are supported.
4.2.22 Other Built-in Types: Range Objects
Range objects are supported.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 88 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.23 Other Built-in Internal Types: Code Objects
Code objects and code object execution is supported with the following attributes:
co_argcount
co_nlocals
co_stacksize
co_flags
co_code
co_consts
co_names
co_varnames
co_filename
co_name
co_firstlineno
co_lnotab
4.2.24 Other Built-in Internal Types: Frame Objects
Frame objects are supported with the following attributes:
f_back
f_code
f_builtins
f_globals
f_locals
f_lasti
f_lineno
f_restricted
f_trace
f_exc_type
f_exc_value
f_exc_traceback
4.2.25 Other Built-in Internal Types: Traceback Objects
Traceback objects are supported with the following attributes:
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 89 of 100
tb_next
tb_frame
tb_lasti
tb_lineno
4.2.26 Other Built-in Internal Types: Slice Objects
Slice objects are supported with the following attributes:
start
stop
step
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.27 Built-in Exceptions
The following built-in exceptions are supported:
Exception
StandardError
ArithmeticError
LookupError
AssertionError
AttributeError
EOFError
FloatingPointError
EnvironmentError
IOError
OSError
ImportError
IndexError
KeyError
KeyboardInterrupt
MemoryError
RemovedFeatureError
NameError
OverflowError
RuntimeError
NotImplementedError
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 90 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
RemovedFeatureError is an exception added in Python version 1.5.2+. RemovedFeatureError is
raised when trying to use floats or complex that are not supported.
Exceptions are strings objects. If file exceptions.py is downloaded to Data Terminal Module Python
than module exceptions is automatically imported at the scripts start and exceptions are class objects.
SyntaxError
SystemError
SystemExit
UnboundLocalError
TypeError
ValueError
ZeroDivisionError
4.2.28 Built-in Functions
The following built-in functions are supported:
round(x [, n]) (returns error)
compile(string, filename, kind)
__import__(name[, globals[, locals[, fromlist]]])
complex(real [, imag]) (returns error)
eval(expression[, globals[, locals]])
execfile(file[, globals[, locals]])
open(filename[, mode[, bufsize]])
callable(object)
vars([object])
coerce(x, y)
delattr(object, name)
divmod(a, b)
filter(function, list)
float(x) (returns error)
input([prompt])
intern(string)
issubclass(class1, class2)
raw_input([prompt])
reload(module)
abs(x)
cmp(x, y)
ord(c)
globals()
int(x)
locals()
long(x)
oct(x)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 91 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
apply(function, args[, keywords])
buffer(object[, offset[, size]])
chr(i)
dir([object])
getattr(object, name[, default])
hasattr(object, name)
hash(object)
hex(x)
id(object)
isinstance(object, class)
len(s)
list(sequence)
map(function, list, ...)
max(s[, args...])
min(s[, args...])
pow(x, y[, z])
range([start,] stop[, step])
reduce(function, sequence[, initializer])
repr(object)
setattr(object, name, value)
slice([start,] stop[, step])
str(object)
tuple(sequence)
type(object)
xrange([start,] stop[, step])
4.2.29 Built-in Modules: marshal
Built-in marshal module is supported with the following methods:
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 92 of 100
dump(value,file)
load(file)
dumps(value)
loads(string)
4.2.30 Built-in Modules: imp
Built-in imp module is supported with the following methods:
The following constants are supported:
load_module(name, file, filename, description)
find_module(name[, path])
get_magic()
get_suffixes()
new_module(name)
PY_SOURCE
PY_COMPILED
C_BUILTIN
PY_FROZEN
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.31 Built-in Modules: __main__
Built-in __main__ module is supported.
4.2.32 Built-in Modules: __builtin__
Built-in __builtin__ module is supported.
4.2.33 Built-in Modules: sys
Built-in sys module is supported with the following methods are supported:
exc_info()
exit([arg])
getrefcount(object)
setcheckinterval(interval)
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 93 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
The following variables are supported:
stdin
stdout
stderr
__stdin__
__stdout__
__stderr__
version
hexversion
copyright
platform
executable
prefix
exec_prefix
maxint
builtin_module_names
removed_features
argv
exc_type
exc_value
exc_traceback
exitfunc
last_type
last_value
last_traceback
modules
path
tracebacklimit
The variables hexversion and removed_features are variables added in Python version 1.5.2+.
“Hexversion” is the version number encoded as a single integer.
This is called ‘hexversion’ since it
only really looks meaningful when viewed as the result of passing it to the built-in hex() function.
“Removed_features” is a tuple of the strings “ComplexType” "FloatType" and "DocStrings".
4.2.34 Built-in Modules: md5
Built-in md5 module is supported with the following functions:
new([arg])
md5([arg])
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 94 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
The following methods are supported:
update(arg)
digest()
copy()
4.2.35 Library Modules
Most of Python Library Modules are not supported because they depend on Operative System.
Basically if a library module imports OS that module is not supported. Some library modules do not
depend on Operative System and are supported. An example is string.py.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 95 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
5 Python notes
5.1 Memory Limits
In order to prevent memory error, in phase of compilation or execution of the script, we advise you to
consider the following limits:
• allocated memory for each variable
• number of the variables that can cause RAM overflow.
The memory available on Telit Python modules includes:
• around 2MB of Non Volatile Memory for the user scripts and data
• 1.2 MB RAM reserved for Python engine usage
• 16KB of memory for each variable
In order to give rough idea of the impact of these constrains consult the table below that contains limits
for different types of variables. Please note that these limits are estimated values and should be used
only to give general information in Python script development.
NOTE: each element of list, tuple, range, or dictionary has up to 16KB of memory available.
At each startup the Python task loads a list of:
• variable names
• module names
• methods names
• strings delimited by “ “ or by ‘ ‘ if not terminated with \r
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 96 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
All these names are included in the main script and in all the files .py called directly or indirectly by the
main. The number of names that can be loaded at each startup from the Python task is around 500.
We advise you to use the same variable names in different .py files of the same project, in case this is
possible.
The recommended dimension of the compiled file .pyo should be <16KByte
NOTE: It is highly recommended not to use the module as a data logger since all flash memories have
limited number of writing and deleting cycles.
Some limits of the available NVM that affect file saving procedures and need to be considered have
been fixed below:
max number of
files saved in NVM
500
max number of
files open
16
contemporary
max length of file
name
16 characters
Other useful info for NVM usage in application development:
• writing in NVM over 2Mbyte could cause a slight decrees of writing speed
• AT#LSCRIPT and AT#FREEMEM commands might not always show a exact number of bytes
that can be used for NVM due to dynamic memory reorganisation process
5.2 Other Limits
Some other Python limits that should be considered while developing your Python script in other to
find an appropriate solution are listed below:
•Python script should not interfere with GSM/GPRS standard operations
reason there is a pause of 50 ms each second during the Python task activity.
• GPIO polling frequency <100Hz;
• I2C and SPI speed: from 10Kb/s to 20Kb/s
28
This means that operations such as serial port, protocol stack etc, can run independently from the Python
script.
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 97 of 100
28
, for this
6 List of acronyms
AAbbbbrreevviiaattiioonn DDeessccrriippttiioonn
ACM Accumulated Call Meter
ASCII American Standard Code for Information Interchange
AT Attention Commands
CB Cell Broadcast
CBS Cell Broadcasting Service
CCM Call Control Meter
CLIP Calling Line Identification Presentation
CLIR Calling Line Identification Restriction
CMOS Complementary Metal-Oxide Semiconductor
CR Carriage Return
CSD Circuit Switched Data
CTS Clear To Send
DAI Digital Audio Interface
DCD Data Carrier Detected
DCE Data Communications Equipment
DRX Data Receive
DSR Data Set Ready
DTA Data Terminal Adaptor
DTE Data Terminal Equipment
DTMF Dual Tone Multi Frequency
DTR Data Terminal Ready
EMC Electromagnetic Compatibility
ETSI European Telecommunications Equipment Institute
FTA Full Type Approval (ETSI)
GPRS General Radio Packet Service
GPIO General Purpose Input Output
GSM Global System for Mobile communication
HF Hands Free
IIC Inter Integrated Circuit
IMEI International Mobile Equipment Identity
IMSI International Mobile Subscriber Identity
IRA International Reference Alphabet
ITU International Telecommunications Union
IWF Inter-Working Function
LCD Liquid Crystal Display
LED Light Emitting Diode
LF Linefeed
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 98 of 100
AAbbbbrreevviiaattiioonn DDeessccrriippttiioonn
ME Mobile Equipment
MISO Master Input Slave Output
MMI Man Machine Interface
MO Mobile Originated
MOSI Master Output Slave Input
MS Mobile Station
MT Mobile Terminated
NVM Non Volatile Memory
NMEA National Marine Electronics Association
OEM Other Equipment Manufacturer
PB Phone Book
PDU Protocol Data Unit
PH Packet Handler
PIN Personal Identity Number
PLMN Public Land Mobile Network
PUCT Price per Unit Currency Table
PUK PIN Unblocking Code
RACH Random Access Channel
RLP Radio Link Protocol
RMS Root Mean Square
RTS Ready To Send
RI Ring Indicator
SCA Service Centre Address
SCL Serial CLock
SDA Serial DAta
SIM Subscriber Identity Module
SMD Surface Mounted Device
SMS Short Message Service
SMSC Short Message Service Centre
SPI Serial Protocol Interface
SS Supplementary Service
SSC Synchronous Serial Controllers
TIA Telecommunications Industry Association
UDUB User Determined User Busy
USSD Unstructured Supplementary Service Data
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 99 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
7 Document Change Log
RReevviissiioonn DDaattee
ISSUE#0 21/03/06 Release First ISSUE#1
ISSUE#1 13/09/06 1.4 Python Implementation Description: added SPI and IIC libraries that
ISSUE#2 16/03/07 Added new modules such as:
ISSUE#3 24/05/07 New disclaimer
ISSUE#4 07/09/07 Added products into applicability table
ISSUE#5 25/10/07 Added list of standard built-in functions
ISSUE#6 07/12/07 Updated memory limits chapter
ISSUE#7 19/12/07 Added new commands under GPIO module
ISSUE#8 01/10/08 Updated new limits in NVM availability for customer’s application from
CChhaannggeess
were missing on the graphic
2.4 MOD built-in module: added Python watchdog and power saving
mode
2.5 IIC built-in module: added note for the IIC bus clock frequency
3.9 Debug Python Script: new paragraph for GPS modules
- clarified meaning of parameter timeout for the following commands:
MDM.receive(timeout), SER.receive(timeout) and
SER.receivebyte(timeout)
2.3 MDM2 built-in module
2.5 SER2 built-in module
2.10 GPS built-in module
Added new function under IIC and SPI
Added introduction for the new modules in paragraph 1.4 and 2
Introduced new chapter with Python notes
Added notes for GPIO, IIC and SPI modules
Added new paragraph: 3.2Run AT Interface and Python at the same
time
Added buffer size for MDM and MDM2 send, read, receive commands
SW rel 7.03.x00
Updated version of Python package
Updated P/N list
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 100 of 100
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.