Fixed some bugs in value conversionwq!
This commit is contained in:
30
common.py
30
common.py
@@ -6,32 +6,6 @@ import yaml
|
|||||||
from caproto.sync.client import read, write
|
from caproto.sync.client import read, write
|
||||||
from caproto import CaprotoTimeoutError, ChannelType
|
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():
|
def read_config():
|
||||||
root_dir = os.path.dirname(__file__)
|
root_dir = os.path.dirname(__file__)
|
||||||
@@ -88,7 +62,7 @@ class Motor:
|
|||||||
self.write('.' + self.fields[fieldname], value)
|
self.write('.' + self.fields[fieldname], value)
|
||||||
|
|
||||||
def read(self, suffix, as_string=False):
|
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)
|
return self._convert_value(response, as_string)
|
||||||
|
|
||||||
def _convert_value(self, response, as_string=False):
|
def _convert_value(self, response, as_string=False):
|
||||||
@@ -101,13 +75,11 @@ class Motor:
|
|||||||
value = response.data[0]
|
value = response.data[0]
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
return value.decode()
|
return value.decode()
|
||||||
|
|
||||||
# If an empty string is returned, the data has a single entry
|
# If an empty string is returned, the data has a single entry
|
||||||
# (the NULL terminator)
|
# (the NULL terminator)
|
||||||
if as_string:
|
if as_string:
|
||||||
return bytes(response.data).rstrip(b'\x00').decode(
|
return bytes(response.data).rstrip(b'\x00').decode(
|
||||||
encoding='utf-8', errors='ignore')
|
encoding='utf-8', errors='ignore')
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
# Strings are read with their NULL terminator, hence it needs to be
|
# Strings are read with their NULL terminator, hence it needs to be
|
||||||
|
|||||||
Reference in New Issue
Block a user