Module indiclient
An INDI Client Library
It implements the INDI Protocol for Python (see http://indi.sourceforge.net/)
There are two major applications:
-
writing telescope control scripts
-
writing user interfaces for remote telescope control
Supported platforms are:
-
Linux
-
Windows
-
any other platform supporting Python
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 INDI object classes:
-
Two important
indiclient
methods:
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()
>>> time.sleep(0.01)
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
Function Summary |
StringType
|
_normalize_whitespace (text)
Remove redundant whitespace from a string |
StringType
|
_sexagesimal (format,
r)
Return a sexagesimal representation of the float given on input |
_normalize_whitespace(text)
Remove redundant whitespace from a string
-
- Parameters:
text -
a string containing any unnecessary whitespaces
(type=str)
- Returns:
-
the input string with exactly one whitespace between each word
and no tailing ones.
(type=StringType)
|
_sexagesimal(format,
r)
-
- Parameters:
format -
a format string for sexagesimal numbers as defined in the in
INDI standard
(type=StringType)
r -
A floating point number
(type=FloatType)
- Returns:
-
A sexagesimal representation of the float given on input
(type=StringType)
|