[pytango] 439/483: Add PyTango objects API examples

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:15:10 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.

commit 934a8bb3adefc17d4f95898d41dae2c171187416
Author: coutinho <coutinho at esrf.fr>
Date:   Fri Feb 6 09:08:47 2015 +0100

    Add PyTango objects API examples
---
 examples/dynamic/common/__init__.py |   0
 examples/dynamic/common/roi.py      |  13 ++++++++++
 examples/dynamic/dynamic_client.py  |  23 ++++++++++++++++++
 examples/dynamic/dynamic_server.py  |  44 +++++++++++++++++++++++++++++++++
 examples/many/many_client           | Bin 0 -> 586610 bytes
 examples/many/many_client.py        |  17 +++++++++++++
 examples/many/many_server.py        |  36 +++++++++++++++++++++++++++
 examples/multi/multi_client.py      |  24 ++++++++++++++++++
 examples/multi/multi_server.py      |  47 ++++++++++++++++++++++++++++++++++++
 examples/simple/common/__init__.py  |   0
 examples/simple/common/roi.py       |  13 ++++++++++
 examples/simple/simple_client.py    |  23 ++++++++++++++++++
 examples/simple/simple_server.py    |  45 ++++++++++++++++++++++++++++++++++
 13 files changed, 285 insertions(+)

diff --git a/examples/dynamic/common/__init__.py b/examples/dynamic/common/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/examples/dynamic/common/roi.py b/examples/dynamic/common/roi.py
new file mode 100644
index 0000000..7c74ff3
--- /dev/null
+++ b/examples/dynamic/common/roi.py
@@ -0,0 +1,13 @@
+class ROI:
+    def __init__(self, x, y, w, h):
+        self.x = x
+        self.y = y
+        self.w = w
+        self.h = h
+
+    def __repr__(self):
+        return str(self)
+
+    def __str__(self):
+        txt = "ROI(x={o.x}, y={o.y}, w={o.w}, h={o.h})".format(o=self)
+        return txt
diff --git a/examples/dynamic/dynamic_client.py b/examples/dynamic/dynamic_client.py
new file mode 100644
index 0000000..541e6b5
--- /dev/null
+++ b/examples/dynamic/dynamic_client.py
@@ -0,0 +1,23 @@
+import PyTango.client
+
+my_object = PyTango.client.Object("my_object")
+
+print("my_object.bla = {0}".format(my_object.bla))
+print("my_object.ble = {0}".format(my_object.ble))
+print("my_object.bli = {0}".format(my_object.bli))
+print("my_object.array = {0}".format(my_object.array))
+
+r1 = my_object.func1()
+print("my_object.func1() = {0}".format(r1))
+
+r2 = my_object.func2(96.44)
+print("my_object.func2(96.44) = {0}".format(r2))
+
+r3 = my_object.func3(45.86, 'hello', d=False, c='world')
+print("my_object.func3(45.86, 'hello', d=False, c='world') = {0}".format(r3))
+
+r4 = my_object.func4()
+print("my_object.func4() = {0}".format(r4))
+
+r5 = my_object.zeros((500, 1000))
+print("my_object.zeros((500, 1000)) = {0}".format(r5))
diff --git a/examples/dynamic/dynamic_server.py b/examples/dynamic/dynamic_server.py
new file mode 100644
index 0000000..0ae7e74
--- /dev/null
+++ b/examples/dynamic/dynamic_server.py
@@ -0,0 +1,44 @@
+import numpy
+
+from PyTango.server import Server
+from common.roi import ROI
+
+class MyClass:
+
+    def __init__(self):
+        self.bla = 55.6
+        self.ble = 11
+        self.bli = False
+        self.array = numpy.ones((1000,1000))
+        self.buff = bytearray(100000*"Hello ")
+        self.__rois = {}
+
+    def func1(self):
+        return "executed func1"
+
+    def func2(self, v):
+        return 2*v
+
+    def func3(self, a, b, c=1, d=3):
+        """Just some documentation"""
+        return "done func3"
+
+    def add_roi(self, name, roi):
+        self.__rois[name] = roi
+        server.register_object(roi, name)
+
+    def remove_roi(self, name):
+        del self.__rois[name] # no need to unregister object
+
+
+import logging
+logging.basicConfig(level=logging.DEBUG)
+
+my_object = MyClass()
+a_roi = ROI(0,0,0,0)
+
+server = Server("Dynamic")
+
+server.register_object(my_object, "dynamic_object")
+server.register_object(a_roi, "dummy_roi")
+server.run()
diff --git a/examples/many/many_client b/examples/many/many_client
new file mode 100755
index 0000000..5a503b2
Binary files /dev/null and b/examples/many/many_client differ
diff --git a/examples/many/many_client.py b/examples/many/many_client.py
new file mode 100644
index 0000000..17de7a4
--- /dev/null
+++ b/examples/many/many_client.py
@@ -0,0 +1,17 @@
+from time import time
+
+import tango.client
+
+N = 100
+
+obj_names = ["obj%04d" % i for i in range(N)]
+
+start = time()
+objs = map(tango.client.Object, obj_names)
+dt = time() - start
+print "Took %fs to create %d objects (avg %fs/object)" % (dt, N, dt/N)
+
+start = time()
+res = [ obj.func3(1,2) for obj in objs ]
+dt = time() - start
+print "Took %fs to call func3 on %d objects (avg %fs/object)" % (dt, N, dt/N)
diff --git a/examples/many/many_server.py b/examples/many/many_server.py
new file mode 100644
index 0000000..0cbb286
--- /dev/null
+++ b/examples/many/many_server.py
@@ -0,0 +1,36 @@
+from PyTango.server import Server
+
+class MyClass:
+
+    def __init__(self):
+        self.bla = 55.6
+        self.ble = 11
+        self.bli = False
+
+    def func1(self):
+        return "executed func1"
+
+    def func2(self, v):
+        return 2*v
+
+    def func3(self, a, b, c=1, d=3):
+        """Just some documentation"""
+        return "done func3"
+
+    def func(self, nap_time):
+        import time
+        time.sleep(nap_time)
+        return "Finished sleep for {0}s".format(nap_time)
+
+server = Server("many", server_type="Server")
+
+N = 100
+
+objs = []
+for i in range(N):
+    name = "obj%04d" % i
+    obj = MyClass()
+    objs.append(obj)
+    server.register_object(obj, name)
+
+server.run()
diff --git a/examples/multi/multi_client.py b/examples/multi/multi_client.py
new file mode 100644
index 0000000..563609b
--- /dev/null
+++ b/examples/multi/multi_client.py
@@ -0,0 +1,24 @@
+import PyTango.client
+
+my_object = PyTango.client.Object("multi_my_object")
+
+print("my_object.bla = {0}".format(my_object.bla))
+print("my_object.ble = {0}".format(my_object.ble))
+print("my_object.bli = {0}".format(my_object.bli))
+
+r1 = my_object.func1()
+print("my_object.func1() = {0}".format(r1))
+
+r2 = my_object.func2(96.44)
+print("my_object.func2(96.44) = {0}".format(r2))
+
+r3 = my_object.func3(45.86, 'hello', d=False, c='world')
+print("my_object.func3(45.86, 'hello', d=False, c='world') = {0}".format(r3))
+
+another_object = PyTango.client.Object("multi_another_object")
+
+r1 = another_object.is_valid()
+print("another_object.is_valid() = {0}".format(r1))
+
+r2 = another_object.lets_go("hello, world!")
+print("another_object.lets_go('hello, world!') = {0}".format(r2))
diff --git a/examples/multi/multi_server.py b/examples/multi/multi_server.py
new file mode 100644
index 0000000..a3aed27
--- /dev/null
+++ b/examples/multi/multi_server.py
@@ -0,0 +1,47 @@
+from PyTango.server import Server
+
+class MyClass:
+
+    def __init__(self):
+        self.bla = 55.6
+        self.ble = 11
+        self.bli = False
+
+    def func1(self):
+        return "executed func1"
+
+    def func2(self, v):
+        return 2*v
+    
+    def func3(self, a, b, c=1, d=3):
+        """Just some documentation"""
+        return "done func3"
+
+
+class AnotherClass:
+
+    def __init__(self, valid=True):
+        self.__valid = valid
+
+    def is_valid(self):
+        return self.__valid
+    
+    def lets_go(self, p1):
+        return "lets_go done!", p1
+
+    def fft(self, a, n=None, axis=-1):
+        import numpy.fft
+        return numpy.fft.fft(a, n=n, axis=axis)
+
+    def array(self, a):
+        return a
+
+my_object = MyClass()
+another_object = AnotherClass(valid=False)
+
+server = Server("multi", server_type="Server")
+
+server.register_object(my_object, "multi_my_object")
+server.register_object(another_object, "multi_another_object")
+
+server.run()
diff --git a/examples/simple/common/__init__.py b/examples/simple/common/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/examples/simple/common/roi.py b/examples/simple/common/roi.py
new file mode 100644
index 0000000..7c74ff3
--- /dev/null
+++ b/examples/simple/common/roi.py
@@ -0,0 +1,13 @@
+class ROI:
+    def __init__(self, x, y, w, h):
+        self.x = x
+        self.y = y
+        self.w = w
+        self.h = h
+
+    def __repr__(self):
+        return str(self)
+
+    def __str__(self):
+        txt = "ROI(x={o.x}, y={o.y}, w={o.w}, h={o.h})".format(o=self)
+        return txt
diff --git a/examples/simple/simple_client.py b/examples/simple/simple_client.py
new file mode 100644
index 0000000..541e6b5
--- /dev/null
+++ b/examples/simple/simple_client.py
@@ -0,0 +1,23 @@
+import PyTango.client
+
+my_object = PyTango.client.Object("my_object")
+
+print("my_object.bla = {0}".format(my_object.bla))
+print("my_object.ble = {0}".format(my_object.ble))
+print("my_object.bli = {0}".format(my_object.bli))
+print("my_object.array = {0}".format(my_object.array))
+
+r1 = my_object.func1()
+print("my_object.func1() = {0}".format(r1))
+
+r2 = my_object.func2(96.44)
+print("my_object.func2(96.44) = {0}".format(r2))
+
+r3 = my_object.func3(45.86, 'hello', d=False, c='world')
+print("my_object.func3(45.86, 'hello', d=False, c='world') = {0}".format(r3))
+
+r4 = my_object.func4()
+print("my_object.func4() = {0}".format(r4))
+
+r5 = my_object.zeros((500, 1000))
+print("my_object.zeros((500, 1000)) = {0}".format(r5))
diff --git a/examples/simple/simple_server.py b/examples/simple/simple_server.py
new file mode 100644
index 0000000..26f69ca
--- /dev/null
+++ b/examples/simple/simple_server.py
@@ -0,0 +1,45 @@
+import numpy
+from PyTango.server import Server
+from common.roi import ROI
+
+class MyClass:
+
+    def __init__(self):
+        self.bla = 55.6
+        self.ble = 11
+        self.bli = False
+        self.array = numpy.ones((1000,1000))
+        self.buff = bytearray(100000*"Hello ")
+
+    def func1(self):
+        return "executed func1"
+
+    def func2(self, v):
+        return 2*v
+
+    def func3(self, a, b, c=1, d=3):
+        """Just some documentation"""
+        return "done func3"
+
+    def func4(self):
+        roi1 = ROI(10, 20, 640, 480)
+        roi2 = ROI(0, 0, 1024, 768)
+        return roi1.__dict__
+
+    def zeros(self, shape, dtype='float'):
+        import numpy
+        return numpy.zeros(shape, dtype=dtype)
+
+    def func5(self, nap_time):
+        import time
+        time.sleep(nap_time)
+        return "Finished sleep for {0}s".format(nap_time)
+
+
+my_object = MyClass()
+
+server = Server("Bla")
+
+server.register_object(my_object, "my_object")
+
+server.run()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list