Module indiclient
[show private | hide private]
[frames | no frames]

Module indiclient

An INDI Client Library

It implements the INDI Protocol for Python (see http://indi.sourceforge.net/)

There are two major applications: Supported platforms are:

The simple way

The most easy way to write a script is demonstrated in the example below (same as file test.py)

Important: make sure you got an indiserver running tutorial_two from the indi distribution and that the Connection is set to On.
>>> from indiclient import *
>>> indi=indiclient("localhost",7624)
>>> time.sleep(1)
>>> indi.tell()
Telescope Simulator CONNECTION Connection SwitchVector OneOfMany
        CONNECT On Switch On
        DISCONNECT Off Switch Off
Telescope Simulator EQUATORIAL_COORD Equatorial J2000 NumberVector rw
        RA RA H:M:S Number 3.5
        DEC Dec D:M:S Number 0

>>> print time.time()
1126108172.88

>>> indi.set_and_send_float("Telescope Simulator","EQUATORIAL_COORD","RA",2.0).wait_for_ok_timeout(60.0)
>>> print time.time()
1126108211.44

>>> print indi.get_float("Telescope Simulator","EQUATORIAL_COORD","RA")
2.0

>>> print indi.get_text("Telescope Simulator","EQUATORIAL_COORD","RA")
2:0:0.00

>>> indi.set_and_send_text("Telescope Simulator","EQUATORIAL_COORD","RA","3:30:00").wait_for_ok_timeout(60.0)
>>> print indi.get_float("Telescope Simulator","EQUATORIAL_COORD","RA")
3.5

>>> indi.quit()
(if you omit the .wait_for_ok_timeout(60.0) the command will still be send, but the function will not wait until the telescope moved to the new position.) If this suits you needs you may take a look at:

The object oriented way

Otherwise can use a more object oriented approach (same as file testobj.py):
>>> from indiclient import *
>>> indi=indiclient("localhost",7624)
>>> vector=indi.get_vector("Telescope Simulator","CONNECTION")
>>> vector.set_by_elementname("CONNECT")
>>> indi.send_vector(vector)
>>> vector.wait_for_ok()
>>> vector.tell()
Telescope Simulator CONNECTION Connection SwitchVector OneOfMany
        CONNECT On Switch On
        DISCONNECT Off Switch Off

>>> vector.set_by_elementname("DISCONNECT")
>>> vector.wait_for_ok()
>>> vector.tell()
Telescope Simulator CONNECTION Connection SwitchVector OneOfMany
        CONNECT On Switch Off
        DISCONNECT Off Switch On

>>> element=vector.get_element("CONNECT")
>>> print element.get_active()
False

>>> indi.quit()
In order to do things like that you should first of all read the documentation of classes in question (you will need roughly 30 minutes to do so) :

The event driven way

Sometimes you want to act in a special way if a special element or a special vector has just been received. You can write custom handlers inheriting from the classes: And add them with the functions: A custom hander function for an element is demonstrated in the example below (same as file testevent.py):
>>> from indiclient import *
>>> class demohandler(indi_custom_element_handler):
>>>     def on_indiobject_changed(self,vector,element):
>>>             print "RA= "+element.get_text()
>>>             print " has just been received on port "+str(self.indi.port)
>>> indi=indiclient("localhost",7624)
>>> print "Installing and calling hander"
Installing and calling hander

>>> indi.add_custom_element_handler(demohandler("Telescope Simulator","EQUATORIAL_COORD","RA"))
RA= 1:0:0.00
has just been received on port 7624

>>> print "Done"
Done

>>> indi.set_and_send_float("Telescope Simulator","EQUATORIAL_COORD","RA",2.0)
>>> time.sleep(0.0001)
>>> indi.set_and_send_float("Telescope Simulator","EQUATORIAL_COORD","RA",1.0)
>>> print "Staring hander"
Staring hander

>>> indi.process_events()
RA= 1:0:0.00
has just been received on port 7624
RA= 1:0:0.00
has just been received on port 7624

>>> print "Done"
Done

>>> indi.quit()
You have to call the indiclient.process_events method during you main loop. As your handler will only be called during the indiclient.process_events method. Your handler will be called once for each time the element was received. A main loop could for example look like this:
>>> while True:
>>>     do_my_stuff()
>>>     indi.process_events() # here your custom handler is called
>>>     time.sleep(0.01) # give some time to the operating system.
RA= 1:0:0.00
has just been received on port 7624
RA= 1:0:0.00
has just been received on port 7624
There is a threaded process that continuesly listens for data from the server and adds it to the list of available indivectors. We still use the indiclient.process_events sheme as GTK does not support threading well and gtkindiclient is based on this library.

Events needed by dynamic clients

If you want to build a dynamic client, you will want to install some more handlers using the methods: This is demonstrated in the example below (same as file testhandler.py).
>>> def def_vector(vector,indiclientobject):
>>>     print "new vector defined by host: "+indiclientobject.host+" : "
>>>     vector.tell()
>>> def msg(message,indiclientobject):
>>>     print "got message by host :"+indiclientobject.host+" : "
>>>     message.tell()
>>> indi=indiclient("localhost",7624)
>>> indi.set_def_handlers(def_vector,def_vector,def_vector,def_vector,def_vector)
>>> indi.set_message_handler(msg)
>>> time.sleep(1)
>>> indi.process_events()
new vector defined by host: localhost :
Telescope Simulator CONNECTION Connection SwitchVector OneOfMany
        CONNECT On Switch Off
        DISCONNECT Off Switch On
new vector defined by host: localhost :
Telescope Simulator EQUATORIAL_COORD Equatorial J2000 NumberVector rw
        RA RA H:M:S Number 0.180309
        DEC Dec D:M:S Number 0
got message by host :localhost :
        INDImessage Telescope Simulator Telescope is disconnected

>>> indi.quit()

Version: 0.13

Author: Dirk Huenniger

Contact: dhun (at) astro (dot) uni-bonn (dot) de

Organization: "Hoher List" observatory Daun (Germany)

License: GNU General Public License as published by the Free Software Foundation, version 2

Classes
bigindiclient  
gui_indi_object_handler This class provides two abstract handler functions.
indi_custom_element_handler A base class for a custom handler that will be called each time a specified INDI element is received.
indi_custom_vector_handler A base class for a custom handler that will be called each time a specified INDI vector is received.
indi_element_identifier  
indi_vector_identifier  
indiblob  
indiblobvector A vector of BLOBs
indiclient providing a simplified interface to bigindiclient
indielement The Base Class of any element of an INDI Vector
indilight a status light
indilightvector A vector of lights
indimessage a text message.
indinamedobject An indiobject that has got a name as well as a label
indinumber A floating point number with a defined format
indinumbervector A vector of numbers
indiobject The Base Class for INDI objects (so anything that INDI can send or receive )
indipermissions The indi read/write permissions.
indiswitch a switch that can be either On or Off
indiswitchvector a vector of switches
inditext a (nearly) arbitrary text
inditextvector A vector of texts
inditransfertype This is object is used to denote whether the an object was sent from the client to the server or vice versa and whether the object is just being defined or if it was defined earlier.
inditransfertypes A Class containing the different transfer types
indivector The base class of all INDI vectors
indixmltag Classifys a received INDI object by its tag.
mini_element_handler A class for custom handlers that consists only of a single function, instead of a whole class.

Generated by Epydoc 2.1 on Sat Sep 10 10:26:05 2005 http://epydoc.sf.net