Commit 657b2214 authored by Sergio Poppi's avatar Sergio Poppi
Browse files

Added PyLocalOscillator to noto-tag01

parent b20eb36b
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
"@(#) $Id$"
+199 −0
Original line number Original line Diff line number Diff line
import socket
import time


QUERYERROR="SYST:ERR? \n"

FREQCMD="FREQ "
QUERYFREQ="FREQ?;"+QUERYERROR
QUERYPOWER="POW?\n"
RFONCMD="OUTP:STAT ON"
RFOFFCMD="OUTP:STAT OFF"
QUERYRF="OUTP:STAT?"
FREQUNIT=" MHZ\n"
POWERUNIT=" dBM\n"

class CommandLineError(Exception):
   def __init__(self, value):

      self.value = value
   def __str__(self):
      return repr(self.value)


class CommandLine:
   
    
   def __init__(self):
     
       try: 
          self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       except socket.error , msg:
          print msg
          self.sock=None

   def __del__(self):
       pass
   
   def configure(self,ip,port):
      '''
      Connect to the HW
      Clear query error
      
      '''
        
   
      try:
         self.sock.connect((ip,port))
         msg ='OK' 
         self.sendCmd('*CLS\n')
         return msg
      except socket.error , msg:
         print msg
         print "connect error: " ,msg
         return msg
   
   def init(self,reply):
     
     pass
   
   def setPower(self,power):
       POWERCMD="POWER "
       cmd= POWERCMD + str(power) + POWERUNIT
 
       try:

           err=self.sendCmd(cmd)
             
           msg=self.query(QUERYERROR)
            
           return msg,err
           
       except socket.error , msg:
          print "connect error: " ,msg
          return msg,False
          self.sock=None
   
   def getPower(self):
       QUERYPOWER="POWER?;SYST:ERR?\n"
       cmd=QUERYPOWER
       try:

          msg=self.query(cmd)
          commands=msg.split(';')
          val=int(commands[0])# unit is MHZ,
          err_msg=commands[1]
          print "query err",msg
          if err_msg != '0,\"No error\"\n': 
                print "exception",err_msg
                raise CommandLineError(err_msg)   
          return err_msg,val
   
       except socket.error , msg:
          print "connect error: " ,msg
          return msg,-1
          self.sock=None
       except CommandLineError,msg:
          raise
       except ValueError,msg:
          raise CommandLineError(msg)   
   
     
   def setFrequency(self,freq):

       cmd= FREQCMD + str(freq) + FREQUNIT
 
       try:

           err=self.sendCmd(cmd)
             
           msg=self.query(QUERYERROR)
            
           return msg,err
           
       except socket.error , msg:
          print "connect error: " ,msg
          return msg,False
          self.sock=None
   
   def getFrequency(self):
         
        cmd= QUERYFREQ
        try:
           
          msg=self.query(cmd)
          commands=msg.split(';')
          val=int(commands[0])/1e6 # unit is MHZ,
          err_msg=commands[1]
          print "query err",msg
          if err_msg != '0,\"No error\"\n': 
                print "exception",err_msg
                raise CommandLineError(err_msg)   
          return err_msg,val
   
        except socket.error , msg:
          print "connect error: " ,msg
          return msg,-1
          self.sock=None
        except CommandLineError,msg:
          raise
        except ValueError,msg:
          raise CommandLineError(msg)   
   
   def readStatus(self):
       ''' 
       Query the error code of the synt.      
       '''       
       try:
           
          msg=self.query(QUERYERROR)
          print "query err",msg
          if msg != '0,\"No error\"\n': 
                print "exception",msg
                raise CommandLineError(msg)   
          return msg
       except socket.error , msg:
          print "connect error: " ,msg
          return msg
          
   def rfOn(self):
     
       pass
   
   def rfOff(self):
      
      
      pass
   
   def sendCmd(self,msg):
     
       try:
           self.sock.sendall(msg)
           return True
       
       except socket.error , msg:
          print "connect error: " ,msg
          raise msg
          self.sock=None
          return False
   
   def close(self):
     
       self.sock.close()

   def query(self,cmd):
       try:
           self.sock.sendall(cmd) 
           msg = self.sock.recv(1024) 
           print 'query:received:',msg
           return msg
       
       except socket.error , msg:
          print "connect error: " ,msg
          raise
          return msg
   
       
       
      
     
 No newline at end of file
+151 −0
Original line number Original line Diff line number Diff line
#! /usr/bin/env python
#*******************************************************************************
# ALMA - Atacama Large Millimiter Array
# (c) UNSPECIFIED - FILL IN, 2015 
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#
# "@(#) $Id$"
#
# who       when      what
# --------  --------  ----------------------------------------------
# spoppi  2015-10-14  created
#

#************************************************************************
#   NAME
# 
#   SYNOPSIS
# 
#   DESCRIPTION
#
#   FILES
#
#   ENVIRONMENT
#
#   RETURN VALUES
#
#   CAUTIONS
#
#   EXAMPLES
#
#   SEE ALSO
#
#   BUGS     
#
#------------------------------------------------------------------------
#

import time
from math import radians
import Receivers__POA
from Acspy.Servants.CharacteristicComponent import CharacteristicComponent
from Acspy.Servants.ContainerServices import ContainerServices 
from Acspy.Servants.ComponentLifecycle import ComponentLifecycle 
from Acspy.Util.BaciHelper import addProperty
from Acspy.Clients.SimpleClient import PySimpleClient
from Acspy.Nc.Supplier import Supplier
from Acspy.Common.TimeHelper import getTimeStamp
from maciErrType import CannotGetComponentEx
from ACSErrTypeCommonImpl import CORBAProblemExImpl
from LocalOscillatorImpl.devios import amplitudeDevIO,frequencyDevIO,isLockedDevIO
import Acspy.Util.ACSCorba

import Receivers
import ComponentErrorsImpl
import ComponentErrors
 
from LocalOscillatorImpl import CommandLine
from IRAPy import logger

#IP, PORT = "192.168.201.149", 5025 #real hw

 
class LocalOscillator(Receivers__POA.LocalOscillator, CharacteristicComponent, ContainerServices, ComponentLifecycle):

   def __init__(self):
      CharacteristicComponent.__init__(self)
      ContainerServices.__init__(self)
      self.cl=CommandLine.CommandLine() 
      self.freq=0.  
      self.power=0.
      
# ___oOo___
   def cleanUp(self):
      
      self.cl.close()
   
   
   def initialize(self):
       name= self.getName()
       dal = Acspy.Util.ACSCorba.cdb()
       dao=dal.get_DAO_Servant("alma/"+name)
       IP=  dao.get_string("IP")
       PORT = int(dao.get_double("PORT"))
       
       msg = self.cl.configure(IP,PORT)
       if msg != 'OK' :
              reason = "cannot get Synthetizer IP %s component: %s" %(IP,msg)
              logger.logError(reason)
              exc = ComponentErrorsImpl.SocketErrorExImpl()
              exc.setData('reason',msg)
              raise exc.getComponentErrorsEx()
       

       addProperty(self, 'frequency', devio_ref=frequencyDevIO(self.cl))
       addProperty(self, 'amplitude', devio_ref=amplitudeDevIO(self.cl))
       addProperty(self, 'isLocked', devio_ref=isLockedDevIO(self,self.cl))
       self.cl.configure(IP,PORT)
   
   def set(self,rf_power,rf_freq):
     try:
        self.cl.setPower(rf_power)
        self.cl.setFrequency(rf_freq)
        self.freq=rf_freq
        self.power=rf_power
        logger.logNotice('SYNT FREQ  set to %f ' %self.freq)
        logger.logNotice('SYNT POWER set to %f ' %self.power)

     except CommandLine.CommandLineError,ex :
          
        logger.logError(ex,message)

       
   
   
   
   
   

   
   def get(self):
     
       msg,power=self.cl.getPower()
       msg,freq= self.cl.getFrequency()
       print power
       print freq
       return (power,freq)
  
   def rfon(self):
    
      pass
  
   def rfoff(self):
    
       pass    
   
   def getInternalFrequency(self):
       return self.freq
   
 No newline at end of file
+103 −0
Original line number Original line Diff line number Diff line
#! /usr/bin/env python
#*******************************************************************************
# ALMA - Atacama Large Millimiter Array
# (c) UNSPECIFIED - FILL IN, 2015 
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#
# "@(#) $Id$"
#
# who       when      what
# --------  --------  ----------------------------------------------
# spoppi  2015-10-14  created
#

#************************************************************************
#   NAME
# 
#   SYNOPSIS
# 
#   DESCRIPTION
#
#   FILES
#
#   ENVIRONMENT
#
#   RETURN VALUES
#
#   CAUTIONS
#
#   EXAMPLES
#
#   SEE ALSO
#
#   BUGS     
#
#------------------------------------------------------------------------
#

import time
from math import radians
import Receivers__POA
from Acspy.Servants.CharacteristicComponent import CharacteristicComponent
from Acspy.Servants.ContainerServices import ContainerServices 
from Acspy.Servants.ComponentLifecycle import ComponentLifecycle 
from Acspy.Util.BaciHelper import addProperty
from Acspy.Clients.SimpleClient import PySimpleClient
from Acspy.Nc.Supplier import Supplier
from Acspy.Common.TimeHelper import getTimeStamp
from maciErrType import CannotGetComponentEx
from ACSErrTypeCommonImpl import CORBAProblemExImpl
from LocalOscillatorImpl.devios import amplitudeDevIO,frequencyDevIO,isLockedDevIO

import Receivers
import ComponentErrorsImpl
import ComponentErrors
import DerotatorErrors

class LocalOscillatorSim(Receivers__POA.LocalOscillator, CharacteristicComponent, ContainerServices, ComponentLifecycle):

   def __init__(self):
      CharacteristicComponent.__init__(self)
      ContainerServices.__init__(self)
#
# ___oOo___
   def cleanUp(self):
  
     
       pass
   
   def initialize(self):
       addProperty(self, 'frequency', devio_ref=frequencyDevIO())
       addProperty(self, 'amplitude', devio_ref=amplitudeDevIO())
       addProperty(self, 'isLocked', devio_ref=isLockedDevIO())

       pass
   
   def set(self,rf_power,rf_freq):
       pass
   
   
   def get(self,rf_power,rf_freq):
     
      pass
  
   def rfon(self):
    
      pass
  
   def rfoff(self):
    
       pass    
 No newline at end of file
+0 −0

Empty file added.

Loading