From 8a0c35e6db8dea39d3621f5b28da42654b713e17 Mon Sep 17 00:00:00 2001 From: William Duckitt Date: Fri, 9 Feb 2024 13:50:49 +0200 Subject: [PATCH 1/3] Refactor code to handle numpy arrays in pvServer.py --- pvServer/pvServer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pvServer/pvServer.py b/pvServer/pvServer.py index f1da69e0..f5a73da7 100644 --- a/pvServer/pvServer.py +++ b/pvServer/pvServer.py @@ -302,9 +302,9 @@ def check_pv_initialized_after_disconnect(): as_numpy=True, with_ctrlvars=True, use_monitor=True ) else: - clientPVlist[pvname]["pv"].get(as_string=True) + clientPVlist[pvname]["pv"].get(as_string=True, as_numpy=False) d = clientPVlist[pvname]["pv"].get_with_metadata( - with_ctrlvars=True, use_monitor=True + with_ctrlvars=True, use_monitor=True, as_numpy=False ) if (clientPVlist[pvname]["pv"].value) is not None: if d is not None: @@ -507,6 +507,7 @@ def on_change_value( room=str(pvname), namespace="/pvServer", ) + elif float(count) == 1: new_char_value = str(char_value) if len(new_char_value) == 0: @@ -530,6 +531,8 @@ def on_change_value( new_char_value = str(char_value) if len(new_char_value) == 0: new_char_value = str(value) + if isinstance(value, np.ndarray): + value=value.tolist() d = { "pvname": pvname, "newmetadata": "False", From 4e4f7cfd587f8af821efe70c4d1087dadcdb91a5 Mon Sep 17 00:00:00 2001 From: William Duckitt Date: Fri, 9 Feb 2024 13:51:21 +0200 Subject: [PATCH 2/3] Refactor code for better readability and formatting --- pvServer/pvServer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pvServer/pvServer.py b/pvServer/pvServer.py index f5a73da7..6d0d9207 100644 --- a/pvServer/pvServer.py +++ b/pvServer/pvServer.py @@ -302,7 +302,9 @@ def check_pv_initialized_after_disconnect(): as_numpy=True, with_ctrlvars=True, use_monitor=True ) else: - clientPVlist[pvname]["pv"].get(as_string=True, as_numpy=False) + clientPVlist[pvname]["pv"].get( + as_string=True, as_numpy=False + ) d = clientPVlist[pvname]["pv"].get_with_metadata( with_ctrlvars=True, use_monitor=True, as_numpy=False ) @@ -507,7 +509,7 @@ def on_change_value( room=str(pvname), namespace="/pvServer", ) - + elif float(count) == 1: new_char_value = str(char_value) if len(new_char_value) == 0: @@ -532,7 +534,7 @@ def on_change_value( if len(new_char_value) == 0: new_char_value = str(value) if isinstance(value, np.ndarray): - value=value.tolist() + value = value.tolist() d = { "pvname": pvname, "newmetadata": "False", From 770702140278d746c365c6178e5629a6209d0274 Mon Sep 17 00:00:00 2001 From: wduckitt Date: Mon, 12 Feb 2024 11:15:43 +0200 Subject: [PATCH 3/3] added check for numpy ndarray --- pvServer/pvServer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pvServer/pvServer.py b/pvServer/pvServer.py index 6d0d9207..dd836380 100644 --- a/pvServer/pvServer.py +++ b/pvServer/pvServer.py @@ -320,7 +320,10 @@ def check_pv_initialized_after_disconnect(): ].tobytes() # convert numpy array to binary else: if clientPVlist[pvname]["pv"].count > 1: - d["value"] = list(d["value"]) + if isinstance(d["value"], np.ndarray): + d["value"] = d["value"].tolist() + else: + d["value"] = list(d["value"]) if clientPVlist[pvname]["pv"].count == 0: d["value"] = [] if clientPVlist[pvname]["pv"].count == 1: