The VisAO Camera
visaodevices.py
Go to the documentation of this file.
1 ##@file visaodevices.py
2 #
3 # The visaodevices python module provides interfaces to all of the scriptable VisAO processes.
4 #
5 # Each process has a class dervied from VisAOFifoDev
6 #
7 
8 
9 """@module visaodevices
10 
11  The visaodevices python module provides interfaces to all of the scriptable VisAO processes.
12 
13  Each process has a class dervied from VisAOFifoDev
14 """
15 
16 
17 from visaofifos import *
18 
19 
21  """
22  Class to control the Focus stage.
23  """
24  def __init__(self):
25  self.base_name = 'focusmotor'
26  self.setup_fifo_names()
27  self.connected = 0
28  self.control = 0
29 
30  def get_pos(self):
31  """
32  Get the current position of the stage.
33  """
34  if self.connected != 1:
35  self.connect()
36  ans = self.write_fifoch('pos?')
37  return float(ans.rstrip('\n\x00'))
38 
39  def abort(self):
40  """
41  Abort a move in progress.
42  """
43  if self.connected != 1:
44  self.connect()
45  resp = int(self.write_fifoch('abort').rstrip('\n\x00'))
46  return resp
47 
48  def pos(self, newpos):
49  """
50  Move to a new position, specified in microns.
51  """
52  if self.control != 1:
53  print 'Must take control of ' + self.base_name + ' first.'
54  return -1
55 
56  argstr = 'pos ' + str(newpos)
57  resp = self.write_fifoch(argstr).rstrip('\n\x00')
58 
59  if resp != '1':
60  print 'Error from ' + self.base_name
61 
62  return int(resp)
63 
64  def preset(self):
65  """
66  Move to a preset focus position based on the filter selection.
67  """
68  if self.control != 1:
69  print 'Must take control of ' + self.base_name + ' first.'
70  return -1
71 
72 
73  resp = self.write_fifoch("preset").rstrip('\n\x00')
74 
75  if resp != '0':
76  print 'Error from ' + self.base_name
77 
78  return int(resp)
79 
80  def wait_move(self):
81  """
82  Wait for a move to complete.
83  """
84  if self.connected != 1:
85  self.connect()
86 
87  time.sleep(0.1)
88  stat = int(self.write_fifoch('ismoving?').rstrip('\n\x00'))
89 
90  while stat != 0:
91  time.sleep(0.1)
92  stat = int(self.write_fifoch('ismoving?').rstrip('\n\x00'))
93 
94  return 1
95 
97  """
98  Class to control the ccd47.
99  """
100  def __init__(self):
101  self.base_name = 'ccd47ctrl'
102  self.setup_fifo_names()
103  self.connected = 0
104  self.control = 0
105 
106  def get_state(self):
107  """
108  Get the current state of the ccd47 controller.
109  """
110  if self.connected != 1:
111  self.connect()
112  stat = self.write_fifoch('state?').rstrip('\n\x00')
113 
114  return stat
115 
116  def stop(self):
117  if self.connected != 1:
118  self.connect()
119  stat = self.write_fifoch('stop').rstrip('\n\x00')
120 
121  return stat
122 
123  def start(self):
124  if self.connected != 1:
125  self.connect()
126  stat = self.write_fifoch('start').rstrip('\n\x00')
127 
128  return stat
129 
130  def save(self, n, im_type=0):
131  """
132  Save data.
133  n = -1 save continuously
134  n = 0 stop saving
135  n = >0 save n images
136  """
137  if self.control != 1:
138  print 'Must take control of ' + self.base_name + ' first.'
139  return 'error'
140 
141  self.imtype(im_type)
142  visao_wait(.1)
143 
144  argstr = 'save ' + str(n)
145 
146  stat = int(self.write_fifoch(argstr).rstrip('\n\x00'))
147 
148  return stat
149 
150  def savescience(self, n):
151  """
152  Save science data.
153  n = -1 save continuously
154  n = 0 stop saving
155  n = >0 save n images
156  """
157 
158  return self.save(n, 0)
159 
160  def savedark(self, n):
161  """
162  Save data.
163  n = -1 save continuously
164  n = 0 stop saving
165  n = >0 save n images
166  """
167  if self.control != 1:
168  print 'Must take control of ' + self.base_name + ' first.'
169  return 'error'
170 
171  self.imtype(2)
172  visao_wait(.1)
173 
174  argstr = 'savedark ' + str(n)
175 
176  stat = int(self.write_fifoch(argstr).rstrip('\n\x00'))
177 
178  return stat
179 
180  def wait_save(self):
181  """
182  Wait for a save sequence to complete.
183  """
184  if self.connected != 1:
185  self.connect()
186 
187  time.sleep(0.3)
188  stat = int(self.write_fifoch('save?').rstrip('\n\x00'))
189 
190  while stat != 0:
191  time.sleep(0.3)
192  stat = int(self.write_fifoch('save?').rstrip('\n\x00'))
193 
194  return 1
195 
196  def subdir(self, sd):
197  """
198  Change to a new sub-directory for saving.
199  """
200  if self.control != 1:
201  print 'Must take control of ' + self.base_name + ' first.'
202  return 'error'
203  com = "subdir %s" % sd
204  res = self.write_fifoch(com)
205 
206  return res
207 
208  def imtype(self, it):
209  """
210  Change image type
211  """
212  if self.control != 1:
213  print 'Must take control of ' + self.base_name + ' first.'
214  return 'error'
215  com = "imtype %s" % it
216  res = int(self.write_fifoch(com).rstrip('\n\x00'))
217 
218  return res
219 
220  def reps(self, rp):
221  """
222  Set ccd 47 accumulator reps
223  """
224  argstr = 'reps ' + str(rp)
225  resp = self.write_fifoch(argstr).rstrip('\n\x00')
226  #pause for program load
227  visao_wait(.2)
228 
229  def exptime(self, et):
230  """
231  Set ccd 47 exposure time
232  """
233  argstr = 'exptime ' + str(et)
234  resp = self.write_fifoch(argstr).rstrip('\n\x00')
235  #pause for program load
236  visao_wait(.2)
237 
238  def get_framerate(self):
239  """
240  Get current framerate
241  """
242  if self.connected != 1:
243  self.connect()
244  fr = self.write_fifoch('framerate?').rstrip('\n\x00')
245  return float(fr)
246 
247  def get_reps(self):
248  """
249  Get current repititions
250  """
251  if self.connected != 1:
252  self.connect()
253  fr = self.write_fifoch('rep?').rstrip('\n\x00')
254  return float(fr)
255 
256  def get_subdir(self):
257  """
258  Get current subdirectory
259  """
260  if self.connected != 1:
261  self.connect()
262  fr = self.write_fifoch('subdir?').rstrip('\n\x00')
263  return fr
264 
265  def set_program(self, pixrate, window, gain, etime):
266  """
267  Set the CCD47 program.
268 
269  pixrate = integer, the pixel rate. Must be one of 2500, 250, or 80.
270  window = integer, the window size, depending on pixel rate can be 1024, 512, 256, 64,32
271  gain = string the gain. Choices are 'H', 'MH', 'ML', or 'L'
272  etime = exposure time, in seconds. 0 is the minimum exposure time for the other settings
273  """
274 
275  pset = -1
276  pno = -1
277  pgain = -1
278  preps = 0
279 
280  if pixrate == 2500:
281  if window == 1024:
282  pset = 0
283  pno = 0
284  if window == 64:
285  pset = 0
286  pno = 1
287  if window == 512:
288  pset = 1
289  pno = 0
290  if window == 32:
291  pset = 1
292  pno = 1
293  if pixrate == 250:
294  if window == 1024:
295  pset = 0
296  pno = 2
297  if window == 512:
298  pset = 1
299  pno = 2
300 
301  if gain == 'H':
302  pgain = 0
303  if gain == 'MH':
304  pgain = 1
305  if gain == 'ML':
306  pgain = 2
307  if gain == 'L':
308  pgain = 3
309 
310 
311  if pset == -1 or pno == -1 or pgain == -1:
312  raise "CCD47Ctrl: unknown or unsupported program"
313 
314 
315  pstr = 'set %d %d %d 0' % (pset, pno, pgain)
316 
317  if self.connected != 1:
318  self.connect()
319 
320  st = self.get_state()
321  if st[0] != 'S':
322  raise "CCD47Ctrl: you do no have SCRIPT control of CCD47"
323 
324  self.write_fifoch(pstr)
325  time.sleep(0.25)
326 
327  st = self.get_state()
328 
329  print 'CCD47Ctrl: reprogramming little joe'
330 
331  while(st[2] == '3'):
332  time.sleep(1)
333  st = self.get_state()
334 
335  print 'CCD47Ctrl: little joe reprogrammed'
336 
337  self.exptime(etime)
338 
339  time.sleep(0.25)
340 
341  return 0
342 
344  """"
345  Class to control the a filter wheel. You should use the FilterWheel2 or FilterWheel3 for a specific device.
346  """
347  def get_filter(self):
348  """
349  Get the current filter.
350  """
351  if self.connected != 1:
352  self.connect()
353  filt = self.write_fifoch('filter?').rstrip('\n\x00')
354 
355  return filt
356 
357  def set_filter(self, filt):
358  """
359  Set filter to filt, moves the wheel.
360 
361  filt should exactly match the names of filter used in its conf file (e.g. "SDSS z'")
362  """
363  if self.connected != 1:
364  self.connect()
365  if self.control != 1:
366  print 'Must take control of ' + self.base_name + ' first.'
367  return 'error'
368 
369  com = "filter %s" % filt
370  resp = self.write_fifoch(com).rstrip('\n\x00')
371 
372  return resp
373 
374  def home(self):
375  """
376  Home the wheel.
377  """
378  if self.connected != 1:
379  self.connect()
380 
381  if self.control != 1:
382  print 'Must take control of ' + self.base_name + ' first.'
383  return 'error'
384 
385  resp = self.write_fifoch("home").rstrip('\n\x00')
386 
387  return resp
388 
389  def wait_move(self):
390  """
391  Wait for a filter wheel move to complete.
392  """
393  if self.connected != 1:
394  self.connect()
395 
396  time.sleep(1.)
397  stat = int(self.write_fifoch('moving?').rstrip('\n\x00'))
398  #print "Moving: %i" % stat
399 
400  while stat == 1:
401  time.sleep(0.1)
402  stat = int(self.write_fifoch('moving?').rstrip('\n\x00'))
403  #print "Moving: %i" % stat
404  return stat
405 
406  def wait_home(self):
407  """
408  Wait for a filter wheel home to complete.
409  """
410  if self.connected != 1:
411  self.connect()
412 
413  time.sleep(0.5)
414  stat1 = int(self.write_fifoch('homing?').rstrip('\n\x00'))
415  while stat1 == 1:
416  time.sleep(0.1)
417  stat1 = int(self.write_fifoch('homing?').rstrip('\n\x00'))
418 
419 
420  time.sleep(0.5)
421  stat2 = int(self.write_fifoch('moving?').rstrip('\n\x00'))
422  while stat2 == 1:
423  time.sleep(0.1)
424  stat2 = int(self.write_fifoch('moving?').rstrip('\n\x00'))
425 
426  if stat1 != 0:
427  return stat1
428 
429  if stat2 != 0:
430  return stat2
431 
432  return 0
433 
435  """
436  Class to control the FilterWheel2.
437  """
438  def __init__(self):
439  self.base_name = 'filterwheel2Local'
440  self.setup_fifo_names()
441  self.connected = 0
442  self.control = 0
443 
445  """
446  Class to control the FilterWheel2.
447  """
448  def __init__(self):
449  self.base_name = 'filterwheel3Local'
450  self.setup_fifo_names()
451  self.connected = 0
452  self.control = 0
453 
455  """
456  Class to control the Shutter.
457  """
458  def __init__(self):
459  self.base_name = 'shuttercontrol'
460  self.setup_fifo_names()
461  self.connected = 0
462  self.control = 0
463 
464  def get_state(self):
465  """
466  Get the current state of the shutter.
467  """
468  if self.connected != 1:
469  self.connect()
470  shutstate = self.write_fifoch('state?').rstrip('\n\x00')
471  return int(shutstate[2]+shutstate[3]) #it is either 1 or -1
472 
473 
474  def open(self):
475  """
476  Open the shutter.
477  """
478  if self.connected != 1:
479  self.connect()
480  self.write_fifoch('open')
481 
482  def shut(self):
483  """
484  Close the shutter.
485  """
486  if self.connected != 1:
487  self.connect()
488  self.write_fifoch('close')
489 
491  def __init__(self):
492  self.base_name = 'gimbal'
493  self.setup_fifo_names()
494  self.connected = 0
495  self.control = 0
496 
497  def get_xpos(self):
498  if self.connected != 1:
499  self.connect()
500  xpos = self.write_fifoch('xpos?').rstrip('\n\x00')
501  return float(xpos) #it is either 1 or -1
502 
503  def get_ypos(self):
504  if self.connected != 1:
505  self.connect()
506  ypos = self.write_fifoch('ypos?').rstrip('\n\x00')
507  return float(ypos)
508 
509  def move_xabs(self, newx):
510  if self.connected != 1:
511  self.connect()
512 
513  argstr = 'xabs ' + str(newx)
514  resp = self.write_fifoch(argstr).rstrip('\n\x00')
515 
516  if resp == 'N' or resp == 'L' or resp == 'A':
517  print 'Do not have SCRIPT control of ' + self.base_name
518  return -1
519 
520  if resp != '0':
521  print 'Error from ' + self.base_name
522  print 'Response: ' + resp
523  return -1
524 
525  return 0
526 
527  def move_yabs(self, newy):
528  if self.connected != 1:
529  self.connect()
530 
531  argstr = 'yabs ' + str(newy)
532  resp = self.write_fifoch(argstr).rstrip('\n\x00')
533 
534  if resp == 'N' or resp == 'L' or resp == 'A':
535  print 'Do not have SCRIPT control of ' + self.base_name
536  return -1
537 
538  if resp != '0':
539  print 'Error from ' + self.base_name
540  print 'Response: ' + resp
541  return -1
542 
543  return 0
544 
545  def move_xrel(self, dx):
546  if self.connected != 1:
547  self.connect()
548 
549  argstr = 'xrel ' + str(dx)
550  resp = self.write_fifoch(argstr).rstrip('\n\x00')
551 
552  if resp == 'N' or resp == 'L' or resp == 'A':
553  print 'Do not have SCRIPT control of ' + self.base_name
554  return -1
555 
556  if resp != '0':
557  print 'Error from ' + self.base_name
558  print 'Response: ' + resp
559  return -1
560 
561  return 0
562 
563  def move_yrel(self, dy):
564  if self.connected != 1:
565  self.connect()
566 
567  argstr = 'yrel ' + str(dy)
568  resp = self.write_fifoch(argstr).rstrip('\n\x00')
569 
570  if resp == 'N' or resp == 'L' or resp == 'A':
571  print 'Do not have SCRIPT control of ' + self.base_name
572  return -1
573 
574  if resp != '0':
575  print 'Error from ' + self.base_name
576  print 'Response: ' + resp
577  return -1
578 
579  return 0
580 
581  def dark(self):
582  if self.connected != 1:
583  self.connect()
584 
585  resp = self.write_fifoch('dark').rstrip('\n\x00')
586 
587  if resp == 'N' or resp == 'L' or resp == 'A':
588  print 'Do not have SCRIPT control of ' + self.base_name
589  return -1
590 
591  #if resp != '0':
592  #print 'Error from ' + self.base_name
593  #print 'Response: ' + resp
594  #return -1
595 
596  return 0
597 
598  def center(self):
599  if self.connected != 1:
600  self.connect()
601 
602  resp = self.write_fifoch('center').rstrip('\n\x00')
603 
604  if resp == 'N' or resp == 'L' or resp == 'A':
605  print 'Do not have SCRIPT control of ' + self.base_name
606  return -1
607 
608  #if resp != '0':
609  #print 'Error from ' + self.base_name
610  #print 'Response: ' + resp
611  #return -1
612 
613  return 0
614 
615  def wait_move(self):
616  """
617  Wait for a gimbal move to complete.
618  """
619  if self.connected != 1:
620  self.connect()
621 
622  time.sleep(2.)
623  statx = int(self.write_fifoch('xmoving?').rstrip('\n\x00'))
624  #print statx
625  staty = int(self.write_fifoch('ymoving?').rstrip('\n\x00'))
626  #print staty
627  while statx > 0 or staty > 0:
628  time.sleep(0.1)
629  statx = int(self.write_fifoch('xmoving?').rstrip('\n\x00'))
630  staty = int(self.write_fifoch('ymoving?').rstrip('\n\x00'))
631 
632  return statx + staty
633 
634 
636  def __init__(self):
637  self.base_name = 'framegrabber39'
638  self.setup_fifo_names()
639  self.connected = 0
640  self.control = 0
641 
642  def save(self, n):
643  """
644  Save data.
645  n = -1 save continuously
646  n = 0 stop saving
647  n = >0 save n images
648  """
649  if self.control != 1:
650  print 'Must take control of ' + self.base_name + ' first.'
651  return 'error'
652 
653  argstr = 'save ' + str(n)
654 
655  stat = int(self.write_fifoch(argstr).rstrip('\n\x00'))
656 
657  return stat
658 
659  def wait_save(self):
660  """
661  Wait for a save sequence to complete.
662  """
663  if self.connected != 1:
664  self.connect()
665 
666  time.sleep(0.3)
667  stat = int(self.write_fifoch('save?').rstrip('\n\x00'))
668 
669  while stat != 0:
670  time.sleep(0.3)
671  stat = int(self.write_fifoch('save?').rstrip('\n\x00'))
672 
673  return 1
674 
675  def subdir(self, sd):
676  """
677  Change to a new sub-directory for saving.
678  """
679  if self.control != 1:
680  print 'Must take control of ' + self.base_name + ' first.'
681  return 'error'
682  com = "subdir %s" % sd
683  res = self.write_fifoch(com)
684 
685  return res
686 
688  def __init__(self):
689  self.base_name = 'framewriter39'
690  self.setup_fifo_names()
691  self.connected = 0
692  self.control = 0
693 
694 
695  def subdir(self, sd):
696  """
697  Change to a new sub-directory for saving.
698  """
699  if self.control != 1:
700  print 'Must take control of ' + self.base_name + ' first.'
701  return 'error'
702  com = "subdir %s" % sd
703  res = self.write_fifoch(com)
704 
705  return res
def pos(self, newpos)
Definition: visaodevices.py:48
def savescience(self, n)
def set_program(self, pixrate, window, gain, etime)
def imtype(self, it)
def exptime(self, et)
def set_filter(self, filt)
def setup_fifo_names(self)
Definition: visaofifos.py:28
def write_fifoch(self, com)
Definition: visaofifos.py:59
def subdir(self, sd)