Skip to content

Instantly share code, notes, and snippets.

@cpascual
Created February 6, 2020 17:28
Show Gist options
  • Save cpascual/c80dfd07a6220471bd2d8a3ed2ed559d to your computer and use it in GitHub Desktop.
Save cpascual/c80dfd07a6220471bd2d8a3ed2ed559d to your computer and use it in GitHub Desktop.
FooBar DS (A DS to test taurus issue https://github.com/taurus-org/taurus/issues/1060
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Basic DS for testing events"""
import numpy
from tango import DevState
from tango.server import Device, attribute
class FooBar(Device):
foo = attribute(label="Foo", dtype=int, abs_change=0.1)
bar = attribute(label="Bar", dtype=int,
#polling_period=1,
#abs_change=0.1,
#rel_change=0.1
)
def init_device(self):
Device.init_device(self)
self.set_state(DevState.RUNNING)
self.poll_attribute('foo', 100)
print("Polled attributes:", self.get_polled_attr())
def read_foo(self):
print("f", end='', flush=True)
return numpy.random.randint(1, 5)
def read_bar(self):
print("b", end='', flush=True)
return numpy.random.randint(100, 999)
if __name__ == "__main__":
# register in the DB (becareful when running in production servers!)
import tango
dev_info = tango.DbDevInfo()
dev_info.server = "FooBar/test"
dev_info._class = "FooBar"
dev_info.name = "test/foobar/1"
db = tango.Database()
db.add_device(dev_info)
# run
FooBar.run_server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment