My favorites | Sign in
Logo
                
Search
for
Updated Jul 12, 2009 by r...@ooz.ie
Labels: Featured
GettingStarted  
Getting started.

Installation

The installation of the package takes place in four steps: downloading the source, extracting it and system-wide installation on the elevated priviledges. The following should work for most Unix derivatives.

$ wget http://pyhumod.googlecode.com/files/pyhumod-0.01.tar.gz
$ tar xzf pyhumod-*.tar.gz
$ cd pyhumod-*
$ sudo python setup.py install

Please note that humod requires pySerial and humod.detect uses dbus-python to talk to HAL. pySerial is a required dependency for PyHumod, dbus-python can be installed if you want to take advantage of the humod.detect module.

Using PyHumod

Once installed, you can write your own scripts or use PyHumod from an interpreter. In both cases Python requires you to import PyHumod first.

Writing your own scripts

An example script could look as follows:

#!/usr/bin/env python
# An example PyHumod script.

import humod
m = humod.Modem()
model = m.show_model()
print 'You are using %s 3G modem.' % model

Using a Python interpreter

You can use Python interpreter to run PyHumod. At home I use ipython, however, most of the interpreter examples on this website are run from the standard /usr/bin/python.

$ ipython
Python 2.5.4 (r254:67916, May 21 2009, 22:07:14)
Type "copyright", "credits" or "license" for more information.

IPython 0.9.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import humod

In [2]: mod = humod.Modem('/dev/ttyUSB0', '/dev/ttyUSB1')

In [3]: mod.show_model()
Out[3]:'E270'

Instantiating a Modem()

The key task that must be accomplished every time you want to talk to the modem is to instantiate a Modem() class. In order for instatiation to suceed you must know where the required data and control ports are. For most Linux users the data port will be located in /dev/ttyUSB0 and the control port in /dev/ttyUSB1 and these are the values that the Modem() class defaults to. Custom values for data and control ports can be passed to the Modem() class as the first and the second argument respectively. In other words, the statement

m = humod.Modem()

is equal to

m = humod.Modem('/dev/ttyUSB0', '/dev/ttyUSB1')

but some MacOS X users may want to execute the following:

m = humod.Modem('/dev/cu.HUAWEIMobile-Modem', '/dev/cu.HUAWEIMobile-Pcui')

Next: You can now try to connect to or disconnect from the 3G network.


Thanks to justinf for his useful suggestions.


Sign in to add a comment
Hosted by Google Code