-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCameraSrv.py
executable file
·99 lines (85 loc) · 2.78 KB
/
CameraSrv.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
#!/usr/bin/env python
import sys, traceback, Ice, os
Ice.loadSlice("/home/utsumi/bin/HinOTORI.ice")
import HinOTORI
sys.path.append("/home/utsumi/bin")
import MultiExposure
import time
import config
import git
import pyfits
camnum=len(config.camera)
class CameraServer(Ice.Application):
def run(self,args):
self.shutdownOnInterrupt() # make sure clean up
adapter = self.communicator().createObjectAdapterWithEndpoints(
os.path.basename(__file__),
"default -h %s -p %d" % ( config.nodesetting['camera']['ip'], \
config.nodesetting['camera']['port']))
try:
cams=MultiExposure.GetCamConnections()
except:
cams=[None]*camnum
print traceback.format_exc()
for i in range(camnum):
try:
print int(cams[i].GetSerialNumber())
cfg=filter(lambda x: x['serial']==int(cams[i].GetSerialNumber()), config.camera)[0]
except AttributeError:
print traceback.format_exc()
cfg=config.camera[i]
except:
print traceback.format_exc()
raise HinOTORI.Error("Camera may not have appropriate serial number or it is not included in configration file")
camera = Camera(cfg['uid'],cams[i])
adapter.add(camera, \
self.communicator().stringToIdentity("ApogeeCam%d" % cfg['uid']))
adapter.activate()
self.communicator().waitForShutdown()
return 0
class Camera(HinOTORI.Camera):
def __init__(self,idnum,cam):
self.idnum = idnum
self.cam = cam
repo = git.Repo(os.path.abspath(os.path.dirname(__file__)))
headcommit = repo.head.commit
self.hexsha=headcommit.hexsha
self.author=headcommit.author.name
HinOTORI.Camera.__init__(self)
def __del__(self):
if self.cam is not None:
self.cam.CloseConnection()
def Take(self,expt,filename,shutter,fitsheader,current=None):
fitsheader=pyfits.Header.fromstring(fitsheader)
fitsheader.extend([
("GITHASH",self.hexsha,"A Git hash key"),
("GITAUTHO",self.author,"Last commiter name"),
])
print repr(fitsheader)
print "Take %lf" % expt
if self.cam is not None:
MultiExposure.camprocess(self.cam,filename,expt,fitsheader,shutter)
else:
time.sleep(expt)
print "finish"
return
def Take_async(self,_cb,expt,filename,shutter,fitsheader,current=None):
try:
self.Take(expt,filename,shutter,fitsheader,current)
_cb.ice_response()
except:
_cb.ice_exception(HinOTORI.Error(traceback.format_exc()))
def GetTemperature(self,current=None):
print "GetTemperature[%d]: %lf" % (self.idnum, self.cam.GetTempCcd())
return self.cam.GetTempCcd()
def SetTemperature(self,setp,current=None):
print "Trying to set temperature[%d] to %lf" % (self.idnum, setp)
self.cam.SetCoolerSetPoint( setp )
if __name__ == "__main__":
app = CameraServer()
args = sys.argv
args.extend( [
"--Ice.ThreadPool.Server.Size=%d" % camnum
])
status = app.main(sys.argv)
sys.exit(status)