generated from MBI-Div-B/pytango-TemplateDeviceServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6b67d57
Showing
5 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 MBI-Division-B / Berlin / Germany | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Template for a Tango Device Server | ||
This is a template for what your Readme for a Tango Device Server should look like. This first abstract should summarize what your Tango DS is for. | ||
Direct further documentation of classes or methods used to the <em>docs</em> folder. Make sure the manuals you upload to <em>manuals</em> are freely accessible. | ||
|
||
## Installation | ||
Describe how to install necessary packages (maybe drivers) needed for your Tango DS. Maybe it is needed to install by <code>pip3</code> or clone and install from another git. | ||
|
||
## Configuration | ||
(Optional) | ||
Add some configuration details that need to be set up when registering the Server (which device properties to declare etc.). | ||
|
||
## Authors | ||
Refer to your organization and leave some contact details of how to reach you in case there are any questions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
# Copyright (C) 2020 MBI-Division-B | ||
# MIT License, refer to LICENSE file | ||
# Author: Luca Barbera / Email: [email protected] | ||
|
||
|
||
from tango import AttrWriteType, DevState, DebugIt, DispLevel | ||
from tango.server import Device, attribute, command, device_property | ||
|
||
# import the drivers you will use | ||
|
||
|
||
class TemplateDeviceServer(Device): | ||
''' | ||
This docstring should describe your Tango Class and optionally | ||
what it depends on (drivers etc). | ||
''' | ||
|
||
|
||
# ------ Attributes ------ # | ||
|
||
humidity = attribute(label='Humidity', | ||
dtype=float, | ||
access=AttrWriteType.READ, | ||
doc='Example for an attribute that can only be read.') | ||
|
||
# optionally use fget/fset to point to read and write functions. | ||
# Default is "read_temperature"/"write_temperature". | ||
# Added some optional attribute properties. | ||
temperature = attribute(label='Temperature', | ||
fget='get_temperature', | ||
dtype=float, | ||
access=AttrWriteType.READ_WRITE, | ||
display_level=DispLevel.EXPERT, | ||
min_value=-273.15, | ||
min_alarm=-100, | ||
max_alarm=100, | ||
min_warning=-50, | ||
max_warning=50, | ||
unit='C', | ||
format="8.4f", | ||
doc='Attribute that can be read/written.') | ||
|
||
|
||
# ------ Device Properties ------ # | ||
# device_properties will be set once per family-member and usually - | ||
# contain serial numbers or a certain port-ID that needs to be set once - | ||
# and will not change while the server is running. | ||
|
||
port = device_property(dtype=int, default_value=10000) | ||
|
||
# ------ default functions that are inherited from parent "Device" ------ # | ||
def init_device(self): | ||
Device.init_device(self) | ||
self.info_stream('Connection established') # prints this line while - | ||
# in logging mode "info" or lower | ||
self.set_state(DevState.ON) | ||
|
||
# here you could initiate first contact to the hardware (driver) | ||
|
||
self.__temp = 0 # declaring values for the attributes if needed | ||
self.__humid = 0 | ||
|
||
def delete_device(self): | ||
self.set_state(DevState.OFF) | ||
self.error_stream('A device was deleted!') # prints this line while - | ||
# in logging mode "error" or lower. | ||
|
||
# define what is executed when Tango checks for the state. | ||
# Here you could inquire the state of the hardware and not just - | ||
# (as it is in default) of the TDS. | ||
# Default returns state but also sets state from ON to ALARM if - | ||
# some attribute alarm limits are surpassed. | ||
def dev_state(self): | ||
# possible pseudo code: | ||
# if hardware-state and TDS-state is ON: | ||
# return DevState.ON | ||
# else: | ||
# return DevState.FAULT | ||
return DevState | ||
|
||
def always_executed_hook(self): | ||
# a method that is executed continuously and by default does nothing. | ||
# if you want smth done polled/continuously, put it in this method. | ||
# check connection to hardware or whether status is acceptable etc. | ||
pass | ||
|
||
# ------ Read/Write functions ------ # | ||
def read_humidity(self): # this is default to read humidity | ||
return self.__humid # returns the value of the "humidity" attr. | ||
|
||
def get_temperature(self): # this was set by fget in attribute declaration | ||
return self.__temp | ||
|
||
def write_temperature(self, value): | ||
# possibly execute some function here to talk to the hardware - | ||
# (e.g. set temperature with a thermostat) | ||
self.__temp = value # update the declared server value of the attr. | ||
|
||
# ------ Internal Methods ------ # | ||
# method that works with multiple input parameters only "inside" this code | ||
|
||
def internal_method(self, param1, param2): | ||
# do something with param1, param2 | ||
pass | ||
|
||
|
||
# ------ COMMANDS ------ # | ||
|
||
@DebugIt() # let the execution of this command be logged in debugging mode | ||
@command() # make method executable through the client - | ||
# (as opposed to just callable inside this code) | ||
def external_method(self, param): | ||
# this kind of method only allows one input parameter | ||
pass | ||
|
||
# more examples of externally executable methods | ||
@command() | ||
def turn_off(self): | ||
self.set_state(DevState.OFF) | ||
|
||
@command() | ||
def turn_on(self): | ||
self.set_state(DevState.ON) | ||
|
||
|
||
# start the server | ||
if __name__ == "__main__": | ||
TemplateDeviceServer.run_server() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Here you can explain something about your code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Some manual. |