From 657b2214cd3dcf4be96ce3ed34e7539c5c0bf7ac Mon Sep 17 00:00:00 2001 From: Sergio Poppi <spoppi@oa-cagliari.inaf.it> Date: Mon, 20 Jun 2016 09:27:22 +0000 Subject: [PATCH] Added PyLocalOscillator to noto-tag01 --- Common/Servers/PyLocalOscillator/ChangeLog | 1 + .../src/LocalOscillatorImpl/CommandLine.py | 199 +++++++++++++++++ .../LocalOscillatorImpl/LocalOscillator.py | 151 +++++++++++++ .../LocalOscillatorImpl/LocalOscillatorSim.py | 103 +++++++++ .../src/LocalOscillatorImpl/__init__.py | 0 .../src/LocalOscillatorImpl/devios.py | 91 ++++++++ .../LocalOscillatorSimImpl/LocalOscillator.py | 40 ++++ .../src/LocalOscillatorSimImpl/__init__.py | 0 .../src/LocalOscillatorSimImpl/devios.py | 15 ++ Common/Servers/PyLocalOscillator/src/Makefile | 210 ++++++++++++++++++ .../test/test_commandline.py | 77 +++++++ .../PyLocalOscillator/test/test_component.py | 25 +++ 12 files changed, 912 insertions(+) create mode 100644 Common/Servers/PyLocalOscillator/ChangeLog create mode 100644 Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/CommandLine.py create mode 100644 Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/LocalOscillator.py create mode 100644 Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/LocalOscillatorSim.py create mode 100644 Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/__init__.py create mode 100644 Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/devios.py create mode 100644 Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/LocalOscillator.py create mode 100644 Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/__init__.py create mode 100644 Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/devios.py create mode 100644 Common/Servers/PyLocalOscillator/src/Makefile create mode 100644 Common/Servers/PyLocalOscillator/test/test_commandline.py create mode 100644 Common/Servers/PyLocalOscillator/test/test_component.py diff --git a/Common/Servers/PyLocalOscillator/ChangeLog b/Common/Servers/PyLocalOscillator/ChangeLog new file mode 100644 index 000000000..a6bf091b5 --- /dev/null +++ b/Common/Servers/PyLocalOscillator/ChangeLog @@ -0,0 +1 @@ +"@(#) $Id$" diff --git a/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/CommandLine.py b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/CommandLine.py new file mode 100644 index 000000000..ba65b47e8 --- /dev/null +++ b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/CommandLine.py @@ -0,0 +1,199 @@ +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 diff --git a/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/LocalOscillator.py b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/LocalOscillator.py new file mode 100644 index 000000000..7a4f9f63f --- /dev/null +++ b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/LocalOscillator.py @@ -0,0 +1,151 @@ +#! /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 diff --git a/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/LocalOscillatorSim.py b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/LocalOscillatorSim.py new file mode 100644 index 000000000..8eab33fbe --- /dev/null +++ b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/LocalOscillatorSim.py @@ -0,0 +1,103 @@ +#! /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 diff --git a/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/__init__.py b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/devios.py b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/devios.py new file mode 100644 index 000000000..ce1b7542d --- /dev/null +++ b/Common/Servers/PyLocalOscillator/src/LocalOscillatorImpl/devios.py @@ -0,0 +1,91 @@ +from ACSImpl.DevIO import DevIO +from math import fabs +from CommandLine import CommandLineError +from IRAPy import logger + +SYNTH_TOLLERANCE = 1. + +class GenericDevIO(DevIO): + def __init__(self, value=0): + DevIO.__init__(self, value) + + def read(self): + return self.value + + def write(self, value): + self.value = value + + +class amplitudeDevIO(DevIO): + def __init__(self, cl,value=0): + DevIO.__init__(self, value) + + def read(self): + return self.value + + def write(self, value): + self.value = value + +class frequencyDevIO(DevIO): + ''' + frequency read from the synth. + + ''' + def __init__(self, cl,value=0): + DevIO.__init__(self,value) + self.cl=cl + def read(self): + try: + msg,value=self.cl.getFrequency() + return value + except CommandLineError, ex: + success = False + msg = ex.message if ex.message else 'unexpected exception' + answer = 'Error - %s' %(ex.getReason() if hasattr(ex, 'getReason') else msg) + logger.logError(answer) + return 0 + + except Exception, ex: + success = False + msg = ex.message if ex.message else 'unexpected exception' + answer = 'Error - %s' %(ex.getReason() if hasattr(ex, 'getReason') else msg) + logger.logError(answer) + return 0 + + def write(self, value): + self.value = value +class isLockedDevIO(DevIO): + ''' + This checks if the Synthetizer is actually set to the set frequecy + + ''' + + def __init__(self, component,commandline,value=0): + DevIO.__init__(self, value) + self.cl=commandline + self.impl=component + def read(self): + try: + component_frequency=self.impl.getInternalFrequency() #read freq from component + msg,synth_frequency=self.cl.getFrequency() #read freq from synth + offset=fabs(component_frequency-synth_frequency) + if offset <= SYNTH_TOLLERANCE: + return 1 + else: + return 0 + except CommandLineError, ex: + success = False + msg = ex.message if ex.message else 'unexpected exception' + answer = 'Error - %s' %(ex.getReason() if hasattr(ex, 'getReason') else msg) + logger.logError(answer) + return 0 + + except Exception, ex: + success = False + msg = ex.message if ex.message else 'unexpected exception' + answer = 'Error - %s' %(ex.getReason() if hasattr(ex, 'getReason') else msg) + logger.logError(answer) + return 0 + + def write(self, value): + self.value = value diff --git a/Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/LocalOscillator.py b/Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/LocalOscillator.py new file mode 100644 index 000000000..ec74617d5 --- /dev/null +++ b/Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/LocalOscillator.py @@ -0,0 +1,40 @@ +import Receivers__POA +from Acspy.Servants.CharacteristicComponent import CharacteristicComponent as CC +from Acspy.Servants.ContainerServices import ContainerServices as CS +from Acspy.Servants.ComponentLifecycle import ComponentLifecycle as CL +from Acspy.Util.BaciHelper import addProperty +from LocalOscillatorSimImpl.devios import GenericDevIO as GDevIO + + +class LocalOscillator(Receivers__POA.LocalOscillator, CC, CS, CL): + + def __init__(self): + CC.__init__(self) + CS.__init__(self) + self.power = 0 + self.frequency = 0 + self.amplitude = 0 + self.isLocked = 0 + + + def initialize(self): + addProperty(self, 'frequency', devio_ref=GDevIO(self, 'frequency')) + addProperty(self, 'amplitude', devio_ref=GDevIO(self, 'amplitude')) + addProperty(self, 'isLocked', devio_ref=GDevIO(self, 'isLocked')) + + + def set(self, power, frequency): + self.power = power + self.frequency = frequency + + + def get(self): + return self.power, self.frequency + + + def rfon(self): + pass + + + def rfoff(self): + pass diff --git a/Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/__init__.py b/Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/devios.py b/Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/devios.py new file mode 100644 index 000000000..0e8e24ab3 --- /dev/null +++ b/Common/Servers/PyLocalOscillator/src/LocalOscillatorSimImpl/devios.py @@ -0,0 +1,15 @@ +from ACSImpl.DevIO import DevIO + + +class GenericDevIO(DevIO): + + def __init__(self, lo, property_name, value=0): + DevIO.__init__(self, value) + self.lo = lo + self.property_name = property_name + + def read(self): + return getattr(self.lo, property_name) + + def write(self, value): + self.value = value diff --git a/Common/Servers/PyLocalOscillator/src/Makefile b/Common/Servers/PyLocalOscillator/src/Makefile new file mode 100644 index 000000000..abf1a5dfc --- /dev/null +++ b/Common/Servers/PyLocalOscillator/src/Makefile @@ -0,0 +1,210 @@ +#******************************************************************************* +# PPPPPPPP +# +# "@(#) $Id$" +# +# Makefile of ........ +# +# who when what +# -------- -------- ---------------------------------------------- +# spoppi 14/10/15 created +# + +#******************************************************************************* +# This Makefile follows VLT Standards (see Makefile(5) for more). +#******************************************************************************* +# REMARKS +# None +#------------------------------------------------------------------------ + +# +# user definable C-compilation flags +#USER_CFLAGS = + +# +# additional include and library search paths +#USER_INC = +#USER_LIB = + +# +# MODULE CODE DESCRIPTION: +# ------------------------ +# As a general rule: public file are "cleaned" and "installed" +# local (_L) are not "installed". + +# +# C programs (public and local) +# ----------------------------- +EXECUTABLES = +EXECUTABLES_L = + +# +# <brief description of xxxxx program> +xxxxx_OBJECTS = +xxxxx_LDFLAGS = +xxxxx_LIBS = + +# +# special compilation flags for single c sources +#yyyyy_CFLAGS = + +# +# Includes (.h) files (public only) +# --------------------------------- +INCLUDES = + +# +# Libraries (public and local) +# ---------------------------- +LIBRARIES = +LIBRARIES_L = + +# +# <brief description of lllll library> +lllll_OBJECTS = + +# +# Scripts (public and local) +# ---------------------------- +SCRIPTS = +SCRIPTS_L = + +# +# TCL scripts (public and local) +# ------------------------------ +TCL_SCRIPTS = +TCL_SCRIPTS_L = + +# +# Python stuff (public and local) +# ---------------------------- +PY_SCRIPTS = +PY_SCRIPTS_L = + +PY_MODULES = +PY_MODULES_L = + +PY_PACKAGES =LocalOscillatorImpl LocalOscillatorSimImpl +PY_PACKAGES_L = +pppppp_MODULES = + +# +# <brief description of tttttt tcl-script> +tttttt_OBJECTS = +tttttt_TCLSH = +tttttt_LIBS = + +# +# TCL libraries (public and local) +# ------------------------------ +TCL_LIBRARIES = +TCL_LIBRARIES_L = + +# +# <brief description of tttlll library> +tttlll_OBJECTS = + +# +# Configuration Database Files +# ---------------------------- +CDB_SCHEMAS = + +# +# IDL Files and flags +# +IDL_FILES = +TAO_IDLFLAGS = +USER_IDL = +# +# Jarfiles and their directories +# +JARFILES= +jjj_DIRS= +jjj_EXTRAS= +# +# java sources in Jarfile on/off +DEBUG= +# +# ACS XmlIdl generation on/off +# +XML_IDL= +# +# Java Component Helper Classes generation on/off +# +COMPONENT_HELPERS= +# +# Java Entity Classes generation on/off +# +XSDBIND= +# +# Schema Config files for the above +# +XSDBIND_INCLUDE= +# man pages to be done +# -------------------- +MANSECTIONS = +MAN1 = +MAN3 = +MAN5 = +MAN7 = +MAN8 = + +# +# local man pages +# --------------- +MANl = + +# +# ASCII file to be converted into Framemaker-MIF +# -------------------- +ASCII_TO_MIF = + +# +# other files to be installed +#---------------------------- +INSTALL_FILES = + +# +# list of all possible C-sources (used to create automatic dependencies) +# ------------------------------ +CSOURCENAMES = \ + $(foreach exe, $(EXECUTABLES) $(EXECUTABLES_L), $($(exe)_OBJECTS)) \ + $(foreach rtos, $(RTAI_MODULES) , $($(rtos)_OBJECTS)) \ + $(foreach lib, $(LIBRARIES) $(LIBRARIES_L), $($(lib)_OBJECTS)) + +# +#>>>>> END OF standard rules + +# +# INCLUDE STANDARDS +# ----------------- + +MAKEDIRTMP := $(shell searchFile include/acsMakefile) +ifneq ($(MAKEDIRTMP),\#error\#) + MAKEDIR := $(MAKEDIRTMP)/include + include $(MAKEDIR)/acsMakefile +endif + +# +# TARGETS +# ------- +all: do_all + @echo " . . . 'all' done" + +clean : clean_all + $(RM) *~ *Impl/*~ LocalOscillator*/*.pyc + $(RM) ../lib/python/site-packages/* + $(RM) $(INTROOT)/lib/python/site-packages/LocalOscillator*Impl* + @echo " . . . clean done" + +clean_dist : clean_all clean_dist_all + @echo " . . . clean_dist done" + +man : do_man + @echo " . . . man page(s) done" + +install : install_all + @echo " . . . installation done" + + +#___oOo___ diff --git a/Common/Servers/PyLocalOscillator/test/test_commandline.py b/Common/Servers/PyLocalOscillator/test/test_commandline.py new file mode 100644 index 000000000..0b11ff188 --- /dev/null +++ b/Common/Servers/PyLocalOscillator/test/test_commandline.py @@ -0,0 +1,77 @@ +import unittest2 +import socket + +from LocalOscillatorImpl import CommandLine +#ip,port ='192.168.200.143',5025 #simulator +ip, port = "192.168.200.149", 5025 #real hw + +class TestCommandLine(unittest2.TestCase): + + + def setUp(self): + self.cl=CommandLine.CommandLine() + self.cl.configure(ip,port) + +# def test_configure(self): + +# self.assertRaises(socket.error,self.cl.configure,'localhost',5555) + #def test_query(self): + + #msg=self.cl.query('*IDN?') + #print 'aa:',msg + #self.assertEqual('0,\"No error\"\n',msg) + + def test_1_sendCmd(self): + + msg=self.cl.sendCmd('FREQ 2188 MHZ\n') + print 'aa:',msg + self.assertEqual(True,msg) + + + def test_2_sendFrequency(self): + msg,err=self.cl.setFrequency(2000) + self.assertEqual('0,\"No error\"\n',msg) + +# def test_3_getFrequency(self): + val=0. + msg,val=self.cl.getFrequency() + self.assertEqual(2000,val) + @unittest2.skip("demonstrating skipping") + def test_3_getFrequency_err(self): + self.assertRaises(CommandLine.CommandLineError, self.cl.getFrequency) + + def test_4_sendPower(self): + msg,err=self.cl.setPower(13) + self.assertEqual('0,\"No error\"\n',msg) + + # @unittest2.skip("demonstrating skipping") + def test_4_sendPower(self): + msg,err=self.cl.setPower(13) + self.assertEqual('0,\"No error\"\n',msg) + + def test_5_getPower(self): + + msg,val=self.cl.getPower() + self.assertEqual(13,val) + def test_5_getPower(self): + + msg,val=self.cl.getPower() + self.assertEqual(13,val) + self.assertEqual('0,\"No error\"\n',msg) + + def test_6_readStatus(self): + msg=self.cl.readStatus() + self.assertEqual('0,\"No error\"\n',msg) + + @unittest2.skip("demonstrating skipping") + def test_7_sendWrongCMD(self): + # try: + self.cl.sendCmd('WOWOW \n') #wrong msg + # except Commandline.CommandLineError ,msg: + self.assertRaises(CommandLine.CommandLineError, self.cl.readStatus) + + + +if __name__ == '__main__': + unittest2.main() + \ No newline at end of file diff --git a/Common/Servers/PyLocalOscillator/test/test_component.py b/Common/Servers/PyLocalOscillator/test/test_component.py new file mode 100644 index 000000000..a9951ef4a --- /dev/null +++ b/Common/Servers/PyLocalOscillator/test/test_component.py @@ -0,0 +1,25 @@ +import time +import unittest2 +from ComponentErrors import ComponentErrorsEx, ComponentErrorsEx +from Acspy.Clients.SimpleClient import PySimpleClient +from LocalOscillatorImpl import CommandLine + +class TestCommandLine(unittest2.TestCase): + + + def setUp(self): + client = PySimpleClient() + self.lo = client.getComponent('RECEIVERS/LO_LP') + + + def test_get(self): + self.lo.set(13,2000) + power,freq=self.lo.get() + self.assertEqual(2000,freq) + + + + + +if __name__ == '__main__': + unittest2.main() -- GitLab