From 1de6bfe63f901096b3c5ed4ef175d7b751bc2311 Mon Sep 17 00:00:00 2001 From: smathis Date: Wed, 23 Jul 2025 09:14:41 +0200 Subject: [PATCH] Fixed some bugs in value conversionwq! --- common.py | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/common.py b/common.py index 459aea4..70590f6 100644 --- a/common.py +++ b/common.py @@ -6,32 +6,6 @@ import yaml from caproto.sync.client import read, write from caproto import CaprotoTimeoutError, ChannelType -FTYPE_TO_TYPE = { - ChannelType.STRING: str, - ChannelType.INT: int, - ChannelType.FLOAT: float, - ChannelType.ENUM: int, - ChannelType.CHAR: bytes, - ChannelType.LONG: int, - ChannelType.DOUBLE: float, - - ChannelType.TIME_STRING: str, - ChannelType.TIME_INT: int, - ChannelType.TIME_FLOAT: float, - ChannelType.TIME_ENUM: int, - ChannelType.TIME_CHAR: bytes, - ChannelType.TIME_LONG: int, - ChannelType.TIME_DOUBLE: float, - - ChannelType.CTRL_STRING: str, - ChannelType.CTRL_INT: int, - ChannelType.CTRL_FLOAT: float, - ChannelType.CTRL_ENUM: int, - ChannelType.CTRL_CHAR: bytes, - ChannelType.CTRL_LONG: int, - ChannelType.CTRL_DOUBLE: float, -} - def read_config(): root_dir = os.path.dirname(__file__) @@ -88,7 +62,7 @@ class Motor: self.write('.' + self.fields[fieldname], value) def read(self, suffix, as_string=False): - response = read(self.pv + suffix).data + response = read(self.pv + suffix) return self._convert_value(response, as_string) def _convert_value(self, response, as_string=False): @@ -101,13 +75,11 @@ class Motor: value = response.data[0] if isinstance(value, bytes): return value.decode() - # If an empty string is returned, the data has a single entry # (the NULL terminator) if as_string: return bytes(response.data).rstrip(b'\x00').decode( encoding='utf-8', errors='ignore') - return value # Strings are read with their NULL terminator, hence it needs to be