Rainbow Electronics GM862-GPS User Manual

Easy Script in Python

80000ST10020a Rev.8 - 01/10/08
This document is relating to the following products:
APPLICABILITY TABLE
PRODUCT PART NUMBER APPLICABILITY
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
GT863-PY
GT864-QUAD
GT864-PY
GM862-QUAD
GM862-QUAD-PY
GM862-GPS
GC864-QUAD
GC864-PY
GC864-QUAD w/ SIM holder
GC864-PY w/ SIM holder
GC864-QUAD-C2
GC864-PY-C2
GE863-QUAD
GE863-PY
GE863-GPS
GE863-SIM
GE864-QUAD
3990150471
4990150069 4990150070
GM862QUD***-***
GM862PYT***-***
GM8632GPS***-***
GC864QUD***-***
GC864PYT***-***
GC864QUH***-***
GC864PYH***-***
GC864QC2***-*** GC864PC2***-***
GE863QUD***-***
GE863PYT***-***
GE863GPS***-***
NMO dependant
GE864QUD***-***
GE864-PY
GE864PYT***-***
The suffix “***-***” depends on the module HW/SW configuration. Please contact your Telit representative for details.
From SW Version:
7.03.x00
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 2 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08

Contents

1 Easy Script Extension - Python interpreter ..................................................................................... 8
1.1 Overview..................................................................................................................................................8
1.2 Python 1.5.2+ Copyright Notice ..........................................................................................................10
1.3 Python installation................................................................................................................................11
1.4 Python implementation description ....................................................................................................12
1.5 Introduction to Python.........................................................................................................................14
1.5.1 Data types ..........................................................................................................................................................14
1.5.2 Operators............................................................................................................................................................15
1.5.3 Compound statements........................................................................................................................................15
1.5.4 Conditional execution........................................................................................................................................16
1.5.5 Loops .................................................................................................................................................................16
1.5.6 Resources...........................................................................................................................................................17
1.6 Python core supported features...........................................................................................................18
2 Python Build-in Custom Modules.................................................................................................. 19
2.1 CMUX and Python ...............................................................................................................................19
2.2 MDM built-in module ..........................................................................................................................20
2.2.1 MDM.send(string, timeout) ...............................................................................................................................20
2.2.2 MDM.receive(timeout)......................................................................................................................................20
2.2.3 MDM.read().......................................................................................................................................................21
2.2.4 MDM.sendbyte(byte, timeout)...........................................................................................................................21
2.2.5 MDM.receivebyte(timeout) ...............................................................................................................................22
2.2.6 MDM.readbyte()................................................................................................................................................22
2.2.7 MDM.getDCD() ................................................................................................................................................22
2.2.8 MDM.getCTS()..................................................................................................................................................23
2.2.9 MDM.getDSR() .................................................................................................................................................23
2.2.10 MDM.getRI() ................................................................................................................................................23
2.2.11 MDM.setRTS(RTS_value)............................................................................................................................23
2.2.12 MDM.setDTR(DTR_value) ..........................................................................................................................24
2.3 MDM2 built-in module ........................................................................................................................25
2.3.1 MDM2.send(string, timeout) .............................................................................................................................25
2.3.2 MDM2.receive(timeout)....................................................................................................................................26
2.3.3 MDM2.read().....................................................................................................................................................26
2.3.4 MDM2.sendbyte(byte, timeout).........................................................................................................................26
2.3.5 MDM2.receivebyte(timeout) .............................................................................................................................27
2.3.6 MDM2.readbyte()..............................................................................................................................................27
2.3.7 MDM2.getDCD() ..............................................................................................................................................27
2.3.8 MDM2.getCTS()................................................................................................................................................28
2.3.9 MDM2.getDSR() ...............................................................................................................................................28
2.3.10 MDM2.getRI() ..............................................................................................................................................28
2.3.11 MDM2.setRTS(RTS_value)..........................................................................................................................28
2.3.12 MDM2.setDTR(DTR_value) ........................................................................................................................29
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
2.4.1 SER.send(string)................................................................................................................................................30
2.4.2 SER.receive(timeout).........................................................................................................................................31
2.4.3 SER.read() .........................................................................................................................................................31
2.4.4 SER.sendbyte(byte) ...........................................................................................................................................31
2.4.5 SER.receivebyte(timeout)..................................................................................................................................32
2.4.6 SER.readbyte()...................................................................................................................................................32
2.4.7 SER.set_speed(speed, <char format>)...............................................................................................................32
2.4.8 SER.setDCD(DCD_value).................................................................................................................................33
2.4.9 SER.setCTS(CTS_value)...................................................................................................................................33
2.4.10 SER.setDSR(DSR_value) .............................................................................................................................33
2.4.11 SER.setRI(RI_value).....................................................................................................................................34
2.4.12 SER.getRTS()................................................................................................................................................34
2.4.13 SER.getDTR()...............................................................................................................................................34
2.5 SER2 built-in module ...........................................................................................................................35
2.5.1 SER2.send(string)..............................................................................................................................................35
2.5.2 SER2.receive(timeout).......................................................................................................................................36
2.5.3 SER2.read() .......................................................................................................................................................36
2.5.4 SER2.sendbyte(byte) .........................................................................................................................................36
2.5.5 SER2.receivebyte(timeout)................................................................................................................................37
2.5.6 SER2.readbyte().................................................................................................................................................37
2.5.7 SER2.set_speed(speed, <format>).....................................................................................................................37
2.6 GPIO built-in module...........................................................................................................................38
2.6.1 GPIO.setIOvalue(GPIOnumber, value).............................................................................................................38
2.6.2 GPIO.getIOvalue(GPIOnumber) .......................................................................................................................38
2.6.3 GPIO.setIOdir(GPIOnumber, value, direction).................................................................................................39
2.6.4 GPIO.getIOdir(GPIOnumber) ...........................................................................................................................39
2.6.5 GPIO.getADC(adcNumber)...............................................................................................................................40
2.6.6 GPIO.setDAC(enable, value)8...........................................................................................................................40
2.6.7 GPIO.setVAUX(vauxNumber, enable)8............................................................................................................40
2.6.8 GPIO.getAXE()9................................................................................................................................................41
2.6.9 GPIO.setSLED(status, onDuration, offDuration) ..............................................................................................41
2.6.10 GPIO.getCBC()9............................................................................................................................................41
2.7 MOD built-in module ...........................................................................................................................43
2.7.1 MOD.secCounter() ............................................................................................................................................43
2.7.2 MOD.sleep(sleeptime).......................................................................................................................................43
2.7.3 MOD.watchdogEnable(timeout)........................................................................................................................44
2.7.4 MOD.watchdogReset() ......................................................................................................................................44
2.7.5 MOD.watchdogDisable()...................................................................................................................................44
2.7.6 MOD.powerSaving(timeout) .............................................................................................................................45
2.7.7 MOD.powerSavingExitCause().........................................................................................................................45
2.8 IIC built-in module...............................................................................................................................46
2.8.1 IIC.new(SDA_pin, SCL_pin, <ADDR>)...........................................................................................................46
2.8.2 IIC object method: init() ....................................................................................................................................47
2.8.3 IIC object method: readwrite(string, read_len)..................................................................................................47
2.8.4 IIC object method: sendbyte(byte).....................................................................................................................48
2.8.5 IIC object method: send(string) .........................................................................................................................48
2.8.6 IIC object method: dev_read(addr, len) .............................................................................................................49
2.8.7 IIC object method: dev_write(addr, string)........................................................................................................49
2.8.8 IIC object method: dev_gen_read(addr, start, len).............................................................................................49
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 4 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
2.8.9 IIC object method: dev_gen_write(addr, start, string).......................................................................................50
2.9 SPI built-in module...............................................................................................................................51
2.9.1 SPI.new(SCLK_pin, MOSI_pin, MISO_pin, <SS0>, <SS1>,…<SS7>)...........................................................51
2.9.2 SPI object method: init (CPOL, CPHA, <SSPOL>, <SS>)...............................................................................52
2.9.3 SPI object method: readwrite(string, <read_len>, <SS>)..................................................................................53
2.9.4 SPI object method: sendbyte(byte, <SS_number>) ...........................................................................................54
2.9.5 SPI object method: readbyte(<SS_number>) ....................................................................................................55
2.9.6 SPI object method: send(string, <SS_number>)................................................................................................55
2.9.7 SPI object method: read(len, <SS_number>) ....................................................................................................55
2.10 GPS built-in module .............................................................................................................................57
2.10.1 GPS. powerOnOff(newStatus) ......................................................................................................................57
2.10.2 GPS.getPowerOnOff()...................................................................................................................................57
2.10.3 GPS.resetMode(mode) ..................................................................................................................................58
2.10.4 GPS.getAntennaVoltage() .............................................................................................................................58
2.10.5 GPS.getAntennaCurrent()..............................................................................................................................58
2.10.6 GPS.getActualPosition() ...............................................................................................................................58
2.10.7 GPS.powerSavingMode(mode, pushToFixPeriod) .......................................................................................59
2.10.8 GPS.powerSavingWakeUp().........................................................................................................................59
2.10.9 GPS.getLastGGA()........................................................................................................................................59
2.10.10 GPS.getLastGLL().........................................................................................................................................60
2.10.11 GPS.getLastGSA() ........................................................................................................................................60
2.10.12 GPS.getLastGSV() ........................................................................................................................................60
2.10.13 GPS.getLastRMC() .......................................................................................................................................61
2.10.14 GPS.getLastVTG() ........................................................................................................................................61
2.10.15 GPS.getPosition() ..........................................................................................................................................61
3 Python Script Operations ............................................................................................................... 62
3.1 Executing a Python script ....................................................................................................................62
3.1.1 Write Python script ............................................................................................................................................62
3.1.2 Download Python script.....................................................................................................................................62
3.1.3 Enable Python script ..........................................................................................................................................65
3.1.4 Execute Python script ........................................................................................................................................65
3.1.5 Reading Python script........................................................................................................................................67
3.1.6 List saved Python scripts ...................................................................................................................................67
3.1.7 Deleting Python script .......................................................................................................................................67
3.1.8 Restart Python script..........................................................................................................................................68
3.2 Run AT Interface and Python at the same time ................................................................................69
3.3 Debug Python script .............................................................................................................................70
3.3.1 Debug Python script on GPS modules using SSC bus.......................................................................................70
3.3.1.1 Installation of the drivers ..........................................................................................................................70
3.3.1.2 Debugging process ....................................................................................................................................73
3.3.2 Debug Python script on GPS modules using CMUX ........................................................................................74
3.3.2.1 Installation.................................................................................................................................................74
3.3.2.2 Debugging process ....................................................................................................................................74
4 Python standard functions ............................................................................................................. 79
4.1 Technical characteristics......................................................................................................................79
4.1.1 General...............................................................................................................................................................79
4.2 Python supported features...................................................................................................................80
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved page 5 of 100
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08
4.2.1 Operators, statements, functions........................................................................................................................80
4.2.2 Truth Value Testing...........................................................................................................................................81
4.2.3 Boolean Operations............................................................................................................................................81
4.2.4 Comparisons ......................................................................................................................................................81
4.2.5 Numeric Types: Integers....................................................................................................................................81
4.2.6 Numeric Types: Long Integers ..........................................................................................................................82
4.2.7 Numeric Types: Float ........................................................................................................................................83
4.2.8 Numeric Types: Complex..................................................................................................................................83
4.2.9 Sequence Types: Strings....................................................................................................................................83
4.2.10 Sequence Types: Tuples................................................................................................................................84
4.2.11 Sequence Types: Lists...................................................................................................................................84
4.2.12 Mapping Types: Dictionaries ........................................................................................................................85
4.2.13 Other Built-in Types: File Objects ................................................................................................................86
4.2.14 Other Built-in Types: Modules......................................................................................................................86
4.2.15 Other Built-in Types: Classes........................................................................................................................87
4.2.16 Other Built-in Types: Functions....................................................................................................................87
4.2.17 Other Built-in Types: Methods......................................................................................................................88
4.2.18 Other Built-in Types: Type Objects ..............................................................................................................88
4.2.19 Other Built-in Types: Null Object.................................................................................................................88
4.2.20 Other Built-in Types: Ellipsis Object............................................................................................................88
4.2.21 Other Built-in Types: Buffer Objects............................................................................................................88
4.2.22 Other Built-in Types: Range Objects ............................................................................................................88
4.2.23 Other Built-in Internal Types: Code Objects.................................................................................................89
4.2.24 Other Built-in Internal Types: Frame Objects ...............................................................................................89
4.2.25 Other Built-in Internal Types: Traceback Objects.........................................................................................89
4.2.26 Other Built-in Internal Types: Slice Objects .................................................................................................90
4.2.27 Built-in Exceptions........................................................................................................................................90
4.2.28 Built-in Functions..........................................................................................................................................91
4.2.29 Built-in Modules: marshal.............................................................................................................................92
4.2.30 Built-in Modules: imp ...................................................................................................................................93
4.2.31 Built-in Modules: __main__..........................................................................................................................93
4.2.32 Built-in Modules: __builtin__ .......................................................................................................................93
4.2.33 Built-in Modules: sys ....................................................................................................................................93
4.2.34 Built-in Modules: md5 ..................................................................................................................................94
4.2.35 Library Modules............................................................................................................................................95
5 Python notes.................................................................................................................................... 96
5.1 Memory Limits .....................................................................................................................................96
5.2 Other Limits..........................................................................................................................................97
6 List of acronyms.............................................................................................................................. 98
7 Document Change Log................................................................................................................. 100
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.
All rights reserved.
© 2006-2007 Telit Communications S.p.A.
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
Easy Script in Python
80000ST10020a Rev.8 - 01/10/08

1.2 Python 1.5.2+ Copyright Notice

The Python code implemented into the module is copyrighted by Stichting Mathematisch Centrum, this is the license: Copyright © 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands.
All Rights Reserved Copyright © 1995-2001 Corporation for National Research Initiatives; All Rights Reserved. Copyright (c) 2001-2007 Python Software Foundation; All Rights Reserved. All Rights Reserved are retained in Python.
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 e­mail:
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.
AAnntteennnnaa
GGPPSS
MMOODD LLiibbrraarryy
PPrriinntt
CCoommmmaanndd
SSeerriiaall ppoorrtt 11 ((AASSCC11)) eexx
GPS receiver
R
TTR
Viirrttuuaall IInntteerrnnaall AATT SSeerriiaall PPoorrtt
MMDDMM LLiibbrraarryy
MMDDMM22LLiib
SSEERR22 LLiibbrraarryy
CCEE
a
rddwwaarree RReessoouurrcceess
HHa
GGPPRRSS MMooddeemm EEnnggiinnee
b
a
a
GGPPSSLLiib
PPyytthhoonn EEnnggiinnee wwiitthh
G
PPRROOG
SSEERR LLiibbrraarryy
UUPPGGRRAADDAABBLLEE
ssooffttwwaarree ssccrriipptt
SSeerriiaall ppoorrtt 00 ((AASSCC00)) eexx
b
SSPPII LLiib
a
a
b
raarryy
IIIICCLLiib
GGPPIIOO LLiibbrraarryy
AAnntteennnnaa
GGSSMM
b
a
a
GGPPIIOO
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 is an 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 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.
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
-3+6j] # closed outermost bracket, statement ends print my_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
Loading...
+ 70 hidden pages