-
Notifications
You must be signed in to change notification settings - Fork 0
/
img.py
126 lines (109 loc) · 3.7 KB
/
img.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import time, threading, io, sys
import PyIndi
device_name = "Canon DSLR EOS 6D"
exposure_time = 1.0
hostname = "stellarmate.local"
filename = "captured_image.raw" # Provide your desired filename and extension
class CamClient(PyIndi.BaseClient):
def __init__(self, hostname=hostname, port=7624):
super(CamClient, self).__init__()
self.setServer(hostname,int(port))
# self.blobEvent=threading.Event()
self.debug = False
if (not(self.connectServer())):
raise Exception(f"No indiserver running on {hostname}:{port} - Run server in Ekos first.")
self.device=self.getDevice(device_name)
while not(self.device):
time.sleep(0.5)
self.log(f"Waiting for {device_name}")
self.device=self.getDevice(device_name)
self.setBLOBMode(1, device_name, None)
@property
def debug(self):
return self._debug
@debug.setter
def debug(self, val):
self._debug = val
def getProp(self, device, propType, propName):
func = None
if propType.lower() == "switch":
func = self.device.getSwitch
elif propType.lower() == "number":
func = self.device.getNumber
elif propType.lower() == "text":
func = self.device.getText
result = None
if func != None:
result = func(propName)
while not(result):
time.sleep(0.5)
result = func(propName)
return result
def send_num(self, name, val):
prop = self.device.getNumber("CCD_EXPOSURE")
prop[0].value = val
self.sendNewNumber(prop)
def get_num(self, name):
prop = self.device.getNumber("CCD_EXPOSURE")
return prop[0].value
def toggle(self, switch_name, toggle):
print(f"name: {switch_name} -> {toggle}")
switch = self.getProp(device_name, "switch", switch_name)
print(f"name: {switch}")
for i in range(0,len(switch)):
print(f"name: {switch[i].name}")
state = PyIndi.ISS_ON if switch[i].name == toggle else PyIndi.ISS_OFF
switch[i].setState(state)
self.sendNewSwitch(switch) # send this new value to the device
def log(self,msg,end="\n"):
if self.debug:
print(msg,end=end)
def newDevice(self, d):
pass
def newProperty(self, p):
pass
def removeProperty(self, p):
pass
def newSwitch(self, svp):
pass
def newNumber(self, nvp):
pass
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
def newBLOB(self, bp):
print(f"Image received")
blob = bp["blobs"][0]
blobName = bp["name"]
with open(filename, "wb") as file:
file.write(blob)
print(f"Image {blobName} downloaded and saved as {filename}")
self.disconnectServer()
def serverConnected(self):
pass
def serverDisconnected(self, code):
pass
# Create an INDI client
indiclient = CamClient()
# Set the exposure time (in seconds)
indiclient.send_num("CCD_EXPOSURE", exposure_time)
# Start capturing
# indiclient.toggle("CCD_CAPTURE", "ON")
# Wait for the exposure to complete
while indiclient.get_num("CCD_EXPOSURE") > 0:
print(f"{indiclient.get_num('CCD_EXPOSURE')}")
time.sleep(0.5)
print(f"Done {indiclient.get_num('CCD_EXPOSURE')}")
# Stop capturing
# indiclient.sendNewSwitch(device, "CCD_CAPTURE", "OFF")
# Disconnect from the camera
#indiclient.disconnectDevice(device_name)
# Disconnect from the INDI server
#indiclient.disconnectServer()