Newer
Older
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- coding: utf-8 -*-
#
# This file is part of the PowerSupply project
#
#
#
# Distributed under the terms of the GPL license.
# See LICENSE.txt for more info.
""" bla
"""
# PyTango imports
import PyTango
from PyTango import DebugIt
from PyTango.server import run
from PyTango.server import Device, DeviceMeta
from PyTango.server import attribute, command
from PyTango.server import device_property
from PyTango import AttrQuality, DispLevel, DevState
from PyTango import AttrWriteType, PipeWriteType
# Additional import
# PROTECTED REGION ID(PowerSupply.additionnal_import) ENABLED START #
# PROTECTED REGION END # // PowerSupply.additionnal_import
__all__ = ["PowerSupply", "main"]
class PowerSupply(Device):
"""
"""
__metaclass__ = DeviceMeta
# PROTECTED REGION ID(PowerSupply.class_variable) ENABLED START #
# PROTECTED REGION END # // PowerSupply.class_variable
# -----------------
# Device Properties
# -----------------
LoadImpedance = device_property(
dtype='double',
mandatory=True
)
HWUpdateTime = device_property(
dtype='double',
mandatory=True
)
# ----------
# Attributes
# ----------
current = attribute(
dtype='double',
)
voltage = attribute(
dtype='double',
access=AttrWriteType.READ_WRITE,
)
# ---------------
# General methods
# ---------------
def init_device(self):
Device.init_device(self)
# PROTECTED REGION ID(PowerSupply.init_device) ENABLED START #
self.voltage = 0.0
self.current = 0.0
self.set_state(DevState.OFF)
# PROTECTED REGION END # // PowerSupply.init_device
def always_executed_hook(self):
# PROTECTED REGION ID(PowerSupply.always_executed_hook) ENABLED START #
t = 'Voltage = %s, Current = %s' % (self.voltage, self.current)
self.set_status(t)
print(t)
# PROTECTED REGION END # // PowerSupply.always_executed_hook
def delete_device(self):
# PROTECTED REGION ID(PowerSupply.delete_device) ENABLED START #
pass
# PROTECTED REGION END # // PowerSupply.delete_device
# ------------------
# Attributes methods
# ------------------
def read_current(self):
# PROTECTED REGION ID(PowerSupply.current_read) ENABLED START #
return self.current
# PROTECTED REGION END # // PowerSupply.current_read
def read_voltage(self):
# PROTECTED REGION ID(PowerSupply.voltage_read) ENABLED START #
return self.voltage
# PROTECTED REGION END # // PowerSupply.voltage_read
def write_voltage(self, value):
# PROTECTED REGION ID(PowerSupply.voltage_write) ENABLED START #
self.voltage = value
self.current = self.voltage / self.LoadImpedance
# PROTECTED REGION END # // PowerSupply.voltage_write
# --------
# Commands
# --------
@command(
)
@DebugIt()
def On(self):
# PROTECTED REGION ID(PowerSupply.On) ENABLED START #
self.set_state(DevState.ON)
# PROTECTED REGION END # // PowerSupply.On
@command(
)
@DebugIt()
def Off(self):
# PROTECTED REGION ID(PowerSupply.Off) ENABLED START #
self.set_state(DevState.OFF)
# PROTECTED REGION END # // PowerSupply.Off
# ----------
# Run server
# ----------
def main(args=None, **kwargs):
# PROTECTED REGION ID(PowerSupply.main) ENABLED START #
return run((PowerSupply,), args=args, **kwargs)
# PROTECTED REGION END # // PowerSupply.main
if __name__ == '__main__':
main()