Commit 6097805f authored by Claudio Scafuri's avatar Claudio Scafuri 💬
Browse files

first import- running server on tom

parent 5852ba4b
.pydevproject
.project
.cproject
.settings
obj
bin
core*
*~
*.pyc
*.so
*.so*
.pylintrc
.metadata
.idea
.cvsignore
.nse_depinfo
software
oldsrc
CVS
*-srv
src/ChangeLog
NAME = pbpm071-srv
MAIN = PBPM071.py
DIRNAME = $(NAME:-srv=)
MODNAME = $(MAIN:.py=)
PY_FILES += $(wildcard src/*.py)
default: bin ${PY_FILES}
@cp ${PY_FILES} bin/${DIRNAME}
@echo "#!/usr/bin/env python3\nimport sys\nsys.path.append(sys.path[0]+'/${DIRNAME}')\nfrom ${MODNAME} import main\nif __name__ == '__main__':\n main()\n" > bin/${NAME}
@chmod +x bin/${NAME} bin/${DIRNAME}/${MAIN}
bin:
@test -d $@ || mkdir -p $@/${DIRNAME}
clean:
@rm -fr bin/ src/*~
.PHONY: clean
#
# Resource backup , created Tue Mar 16 09:05:05 CET 2021
#
#---------------------------------------------------------
# SERVER PBPM071/s71, PBPM071 device declaration
#---------------------------------------------------------
PBPM071/s71/DEVICE/PBPM071: "sr/diagnostics/phbpm_s7.1"
# --- sr/diagnostics/phbpm_s7.1 properties
sr/diagnostics/phbpm_s7.1->CalibCoeff1: 1408.4507042253522
sr/diagnostics/phbpm_s7.1->CalibCoeff2: 1795.3321364452422
sr/diagnostics/phbpm_s7.1->IP_addres: 192.168.203.91
sr/diagnostics/phbpm_s7.1->MinVoltageThreshold: 1
sr/diagnostics/phbpm_s7.1->polled_attr: verticalposition1,\
1000,\
verticalposition2,\
1000,\
voltage2,\
3000,\
voltage3,\
3000,\
voltage0,\
3000,\
voltage1,\
3000,\
voltages,\
1000
sr/diagnostics/phbpm_s7.1->PORT: 30002
# --- sr/diagnostics/phbpm_s7.1 attribute properties
sr/diagnostics/phbpm_s7.1/VerticalPosition1->archive_abs_change: 0.1
sr/diagnostics/phbpm_s7.1/VerticalPosition1->archive_period: 60000
sr/diagnostics/phbpm_s7.1/VerticalPosition2->archive_abs_change: 0.1
sr/diagnostics/phbpm_s7.1/VerticalPosition2->archive_period: 60000
sr/diagnostics/phbpm_s7.1/Voltage0->archive_abs_change: 0.05
sr/diagnostics/phbpm_s7.1/Voltage0->archive_period: 60000
sr/diagnostics/phbpm_s7.1/Voltage1->archive_abs_change: 0.05
sr/diagnostics/phbpm_s7.1/Voltage1->archive_period: 60000
sr/diagnostics/phbpm_s7.1/Voltage2->archive_abs_change: 0.05
sr/diagnostics/phbpm_s7.1/Voltage2->archive_period: 60000
sr/diagnostics/phbpm_s7.1/Voltage3->archive_abs_change: 0.05
sr/diagnostics/phbpm_s7.1/Voltage3->archive_period: 60000
#---------------------------------------------------------
# CLASS PBPM071 properties
#---------------------------------------------------------
# CLASS PBPM071 attribute properties
# --- dserver/PBPM071/s71 properties
dserver/PBPM071/s71->polling_threads_pool_conf: "sr/diagnostics/phbpm_s7.1"
#!/usr/bin/python
# "$Name: $";
# "$Header: $";
#=============================================================================
#
# file : PBPM071.py
#
# description : Python source for the PBPM071 and its commands.
# The class is derived from Device. It represents the
# CORBA servant object which will be accessed from the
# network. All commands which can be executed on the
# PBPM071 are implemented in this file.
#
# project : TANGO Device Server
#
# $Author: $
#
# $Revision: $
#
# $Log: $
#
# copyleft : European Synchrotron Radiation Facility
# BP 220, Grenoble 38043
# FRANCE
#
#=============================================================================
# This file is generated by POGO
# (Program Obviously used to Generate tango Object)
#
# (c) - Software Engineering Group - ESRF
#=============================================================================
#
import PyTango
import sys
import socket
import time
#==================================================================
# PBPM071 Class Description:
#
# FE PBPM 071 Tango device
#
#==================================================================
class PBPM071(PyTango.Device_4Impl):
#--------- Add you global variables here --------------------------
#------------------------------------------------------------------
# Device constructor
#------------------------------------------------------------------
def __init__(self,cl, name):
PyTango.Device_4Impl.__init__(self,cl,name)
PBPM071.init_device(self)
#------------------------------------------------------------------
# Device destructor
#------------------------------------------------------------------
def delete_device(self):
if self.socket != None:
try:
self.socket.close()
except:
pass
self.socket = None
#------------------------------------------------------------------
# Device initialization
#------------------------------------------------------------------
def init_device(self):
self.socket = None
self.voltages = [0.0, 0.0, 0.0, 0.0]
self.positions = [0.0, 0.0]
self.set_state(PyTango.DevState.ON)
self.get_device_properties(self.get_device_class())
self.net_errors = 0
self.last_readout_time = 0
#------------------------------------------------------------------
# Always excuted hook method
#------------------------------------------------------------------
def always_executed_hook(self):
if self.socket != None:
return
try:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((self.IP_addres, self.PORT))
self.set_state(PyTango.DevState.ON)
except:
self.socket = None
self.set_state(PyTango.DevState.FAULT)
#==================================================================
#
# PBPM071 read/write attribute methods
#
#==================================================================
#------------------------------------------------------------------
# Read Attribute Hardware
#------------------------------------------------------------------
def read_attr_hardware(self,data):
#print "In ", self.get_name(), "::read_attr_hardware()"
pass
#------------------------------------------------------------------
# Read Voltage0 attribute
#------------------------------------------------------------------
def read_Voltage0(self, attr):
#print "In ", self.get_name(), "::read_Voltage0()"
# Add your own code here
# Force readout data at least every second
if (time.time() - self.last_readout_time) > 1:
self.read_all_data()
attr_Voltage0_read = self.voltages[0]
attr.set_value(attr_Voltage0_read)
#------------------------------------------------------------------
# Read Voltage1 attribute
#------------------------------------------------------------------
def read_Voltage1(self, attr):
#print "In ", self.get_name(), "::read_Voltage1()"
# Add your own code here
# Force readout data at least every second
if (time.time() - self.last_readout_time) > 1:
self.read_all_data()
attr_Voltage1_read = self.voltages[1]
attr.set_value(attr_Voltage1_read)
#------------------------------------------------------------------
# Read Voltage2 attribute
#------------------------------------------------------------------
def read_Voltage2(self, attr):
#print "In ", self.get_name(), "::read_Voltage2()"
# Add your own code here
# Force readout data at least every second
if (time.time() - self.last_readout_time) > 1:
self.read_all_data()
attr_Voltage2_read = self.voltages[2]
attr.set_value(attr_Voltage2_read)
#------------------------------------------------------------------
# Read Voltage3 attribute
#------------------------------------------------------------------
def read_Voltage3(self, attr):
#print "In ", self.get_name(), "::read_Voltage3()"
# Add your own code here
# Force readout data at least every second
if (time.time() - self.last_readout_time) > 1:
self.read_all_data()
attr_Voltage3_read = self.voltages[3]
attr.set_value(attr_Voltage3_read)
#------------------------------------------------------------------
# Read VerticalPosition1 attribute
#------------------------------------------------------------------
def read_VerticalPosition1(self, attr):
#print "In ", self.get_name(), "::read_VerticalPosition1()"
# Add your own code here
# Force readout data at least every second
if (time.time() - self.last_readout_time) > 1:
self.read_all_data()
sum = self.voltages[0] + self.voltages[1]
diff = self.voltages[0] - self.voltages[1]
if (sum != 0):
self.positions[0] = self.CalibCoeff1 * (diff / sum)
else:
self.positions[0] = 0
pos = self.positions[0]
attr.set_value(pos)
#------------------------------------------------------------------
# Read VerticalPosition2 attribute
#------------------------------------------------------------------
def read_VerticalPosition2(self, attr):
#print "In ", self.get_name(), "::read_VerticalPosition2()"
# Add your own code here
# Force readout data at least every second
if (time.time() - self.last_readout_time) > 1:
self.read_all_data()
sum = self.voltages[2] + self.voltages[3]
diff = self.voltages[2] - self.voltages[3]
if (sum != 0):
self.positions[1] = self.CalibCoeff2 * diff / sum
else:
self.positions[1] = 0
pos = self.positions[1]
attr.set_value(pos)
#------------------------------------------------------------------
# Read Voltages attribute
#------------------------------------------------------------------
def read_Voltages(self, attr):
#print "In ", self.get_name(), "::read_Voltages()"
# Add your own code here
self.read_all_data()
attr.set_value(self.voltages, len(self.voltages))
#------------------------------------------------------------------
# UTIL: read_all_data function
#------------------------------------------------------------------
def read_all_data(self):
try:
if self.socket != None:
self.last_readout_time = time.time()
self.socket.sendall("GETN 0,1,2,3\r\n")
reply = self.socket.recv(512).strip()
self.voltages = map(float,reply.split(" "))
except:
self.net_errors += 1
if self.net_errors == 10:
self.delete_device()
self.set_state(PyTango.DevState.FAULT)
if all(i >= self.MinVoltageThreshold for i in self.voltages):
new_state = PyTango.DevState.ON
else:
new_state = PyTango.DevState.FAULT
if self.get_state() != new_state:
self.set_state(new_state)
#==================================================================
#
# PBPM071 command methods
#
#==================================================================
#==================================================================
#
# PBPM071Class class definition
#
#==================================================================
class PBPM071Class(PyTango.DeviceClass):
# Class Properties
class_property_list = {
}
# Device Properties
device_property_list = {
'IP_addres':
[PyTango.DevString,
"IP address of the PBPM comedi server",
[ "192.168.203.91" ] ],
'PORT':
[PyTango.DevLong,
"",
[ 30002 ] ],
'CalibCoeff1':
[PyTango.DevFloat,
"Calibration coefficient of PBPM1",
[ 1408.4507042253522 ] ],
'CalibCoeff2':
[PyTango.DevFloat,
"Calibration coefficient of PBPM2",
[ 1795.3321364452422 ] ],
'MinVoltageThreshold':
[PyTango.DevFloat,
"Minimum voltage threshold for each PBPM blade readout",
[ 0.5 ] ],
}
# Command definitions
cmd_list = {
}
# Attribute definitions
attr_list = {
'Voltage0':
[[PyTango.DevFloat,
PyTango.SCALAR,
PyTango.READ]],
'Voltage1':
[[PyTango.DevFloat,
PyTango.SCALAR,
PyTango.READ]],
'Voltage2':
[[PyTango.DevFloat,
PyTango.SCALAR,
PyTango.READ]],
'Voltage3':
[[PyTango.DevFloat,
PyTango.SCALAR,
PyTango.READ]],
'VerticalPosition1':
[[PyTango.DevFloat,
PyTango.SCALAR,
PyTango.READ]],
'VerticalPosition2':
[[PyTango.DevFloat,
PyTango.SCALAR,
PyTango.READ]],
'Voltages':
[[PyTango.DevFloat,
PyTango.SPECTRUM,
PyTango.READ, 4]],
}
#------------------------------------------------------------------
# PBPM071Class Constructor
#------------------------------------------------------------------
def __init__(self, name):
PyTango.DeviceClass.__init__(self, name)
self.set_type(name);
#print "In PBPM071Class constructor"
#==================================================================
#
# PBPM071 class main method
#
#==================================================================
if __name__ == '__main__':
try:
py = PyTango.Util(sys.argv)
py.add_TgClass(PBPM071Class,PBPM071,'PBPM071')
U = PyTango.Util.instance()
U.server_init()
U.server_run()
except PyTango.DevFailed,e:
print '-------> Received a DevFailed exception:',e
except Exception,e:
print '-------> An unforeseen exception occured....',e
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment