[pytango] 472/483: Add simple Clock example

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:15:14 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 dc78dd1767868ec0d15c8f8f56f67b9ae042e973
Author: coutinho <coutinho at esrf.fr>
Date:   Fri Apr 17 18:09:40 2015 +0200

    Add simple Clock example
---
 examples/Clock/ClockDS.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 examples/Clock/client.py  | 36 ++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/examples/Clock/ClockDS.py b/examples/Clock/ClockDS.py
new file mode 100644
index 0000000..11ffe26
--- /dev/null
+++ b/examples/Clock/ClockDS.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# ------------------------------------------------------------------------------
+# This file is part of PyTango (http://www.tinyurl.com/PyTango)
+#
+# Copyright 2013-2015 European Synchrotron Radiation Facility, Grenoble, France
+#
+# Distributed under the terms of the GNU Lesser General Public License,
+# either version 3 of the License, or (at your option) any later version.
+# See LICENSE.txt for more info.
+# ------------------------------------------------------------------------------
+
+"""
+Clock Device server showing how to write a TANGO server with a Clock device
+which has attributes:
+
+  - time: read-only scalar float
+  - gmtime: read-only sequence (spectrum) of integers
+
+commands:
+
+  - ctime: in: float parameter; returns a string
+  - mktime: in: sequence (spectrum) of 9 integers; returns a float
+"""
+
+import time
+
+from PyTango.server import Device, DeviceMeta
+from PyTango.server import attribute, command
+from PyTango.server import run
+
+
+class Clock(Device):
+    __metaclass__ = DeviceMeta
+
+    @attribute(dtype=float)
+    def time(self):
+        return time.time()
+
+    gmtime = attribute(dtype=(int,), max_dim_x=9)
+
+    def read_gmtime(self):
+        return time.gmtime()
+
+    @command(dtype_in=float, dtype_out=str)
+    def ctime(self, seconds):
+        """
+        Convert a time in seconds since the Epoch to a string in local time.
+        This is equivalent to asctime(localtime(seconds)). When the time tuple
+        is not present, current time as returned by localtime() is used.
+        """
+        return time.ctime(seconds)
+
+    @command(dtype_in=(int,), dtype_out=float)
+    def mktime(self, tupl):
+        return time.mktime(tupl)
+
+
+if __name__ == "__main__":
+    run([Clock,])
diff --git a/examples/Clock/client.py b/examples/Clock/client.py
new file mode 100644
index 0000000..0497e2c
--- /dev/null
+++ b/examples/Clock/client.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# ------------------------------------------------------------------------------
+# This file is part of PyTango (http://www.tinyurl.com/PyTango)
+#
+# Copyright 2013-2015 European Synchrotron Radiation Facility, Grenoble, France
+#
+# Distributed under the terms of the GNU Lesser General Public License,
+# either version 3 of the License, or (at your option) any later version.
+# See LICENSE.txt for more info.
+# ------------------------------------------------------------------------------
+
+"""
+Simple client to show how to connect to a Clock device from ClockDS
+
+usage: client clock_dev_name
+"""
+
+import sys
+import PyTango
+
+if len(sys.argv) != 2:
+    print "must provide one and only one clock device name"
+    sys.exit(1)
+
+clock = PyTango.DeviceProxy(sys.argv[1])
+t = clock.time
+gmt = clock.gmtime
+print(t)
+print(gmt)
+print(clock.ctime(t))
+print(clock.mktime(gmt))
+
+
+
+

-- 
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