-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatchTelescopeProps.py
79 lines (71 loc) · 2.34 KB
/
watchTelescopeProps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import PyIndi
import time
class IndiClient(PyIndi.BaseClient):
def __init__(self):
super(IndiClient, self).__init__()
def newDevice(self, d):
global dmonitor
# We catch the monitored device
dmonitor=d
print("New device ", d.getDeviceName())
def newProperty(self, p):
global monitored
global cmonitor
# we catch the "CONNECTION" property of the monitored device
if (p.getDeviceName()==monitored and p.getName() == "CONNECTION"):
cmonitor=p.getSwitch()
print("New property ", p.getName(), " for device ", p.getDeviceName())
def removeProperty(self, p):
pass
def newBLOB(self, bp):
pass
def newSwitch(self, svp):
pass
def newNumber(self, nvp):
global newval
global prop
# We only monitor Number properties of the monitored device
prop=nvp
newval=True
def newText(self, tvp):
pass
def newLight(self, lvp):
pass
def newMessage(self, d, m):
pass
def serverConnected(self):
pass
def serverDisconnected(self, code):
pass
monitored="Telescope Simulator"
dmonitor=None
cmonitor=None
indiclient=IndiClient()
indiclient.setServer("localhost",7624)
# we are only interested in the telescope device properties
indiclient.watchDevice(monitored)
indiclient.connectServer()
# wait CONNECTION property be defined
while not(cmonitor):
time.sleep(0.5)
# if the monitored device is not connected, we do connect it
if not(dmonitor.isConnected()):
# Property vectors are mapped to iterable Python objects
# Hence we can access each element of the vector using Python indexing
# each element of the "CONNECTION" vector is a ISwitch
cmonitor[0].s=PyIndi.ISS_ON # the "CONNECT" switch
cmonitor[1].s=PyIndi.ISS_OFF # the "DISCONNECT" switch
indiclient.sendNewSwitch(cmonitor) # send this new value to the device
newval=False
prop=None
nrecv=0
while (nrecv<10):
# we poll the newval global variable
if (newval):
print("newval for property", prop.name, " of device ",prop.device)
# prop is a property vector, mapped to an iterable Python object
for n in prop:
# n is a INumber as we only monitor number vectors
print(n.name, " = ", n.value)
nrecv+=1
newval=False