From 5bf3a0f82fe48ca76a502c7b45eb26f3e4c3fd15 Mon Sep 17 00:00:00 2001
From: Romain Broucquart <romain.broucquart@synchrotron-soleil.fr>
Date: Thu, 17 Sep 2020 10:24:41 +0200
Subject: [PATCH] [ContextSaver] Array Fix, Catch exception

* Add a little more debug messages.
* If attribute is numpy array, convert to python list.
  We have to do so to serialize with json.
* Catch exception when trying to access attribute.
  We signal a warning. The defualt case is with an attribute that has
  no name...
---
 ContextSaver.py | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/ContextSaver.py b/ContextSaver.py
index 09efdbc..63c23fb 100644
--- a/ContextSaver.py
+++ b/ContextSaver.py
@@ -9,6 +9,7 @@ import PyTango as tango
 import logging
 import argparse
 import json
+import numpy
 
 __version__ = "1.0.0"
 
@@ -32,15 +33,25 @@ def get_wattr(proxy):
 
     # Scan all attributes
     for attr in proxy.get_attribute_list():
-        if proxy.get_attribute_config(attr).writable in [
-                tango.AttrWriteType.WRITE,
-                tango.AttrWriteType.READ_WRITE,
-                tango.AttrWriteType.READ_WITH_WRITE]:
-            config[attr]=proxy[attr].value
-
-            logger.debug("Detect writtable attribute %s = %s"%(
-                attr,
-                proxy[attr].value))
+        logger.debug("Analyse attribute '%s' "%(
+                attr))
+
+        try:
+            if proxy.get_attribute_config(attr).writable in [
+                    tango.AttrWriteType.WRITE,
+                    tango.AttrWriteType.READ_WRITE,
+                    tango.AttrWriteType.READ_WITH_WRITE]:
+                v= proxy[attr].value
+                if type(v) is numpy.ndarray:
+                    v=v.tolist()
+
+                config[attr]=v
+
+                logger.debug("Detect writtable attribute '%s' = %s"%(
+                    attr,
+                    proxy[attr].value))
+        except tango.DevFailed:
+            logger.warning("Failed to save attribute '%s'"%attr)
 
     return config
 
-- 
GitLab