Permalink
Browse files

fixed bugs with character waveforms holding 1-element arrays

  • Loading branch information...
1 parent 8e9c4da commit 59ad1f2a6ab5cd6b133e03010eba31ea40766b2a @newville newville committed May 21, 2012
Showing with 18 additions and 10 deletions.
  1. +15 −10 lib/ca.py
  2. +3 −0 lib/pv.py
View
@@ -1220,25 +1220,30 @@ def put(chid, value, wait=False, timeout=30, callback=None,
"""
ftype = field_type(chid)
count = element_count(chid)
- if count > 1: # and not (ftype == dbr.CHAR and isinstance(value, str)):
+ if count > 1:
count = min(len(value), count)
- data = (count*dbr.Map[ftype])()
+ data = (count*dbr.Map[ftype])()
if ftype == dbr.STRING:
if count == 1:
data[0].value = value
else:
for elem in range(min(count, len(value))):
data[elem].value = value[elem]
elif count == 1:
- try:
- data[0] = value
- except TypeError:
- data[0] = type(data[0])(value)
- except:
- errmsg = "cannot put value '%s' to PV of type '%s'"
- tname = dbr.Name(ftype).lower()
- raise ChannelAccessException(errmsg % (repr(value), tname))
+ if ftype == dbr.CHAR:
+ if isinstance(value, str):
+ value = [ord(value)]
+ data[:] = value
+ else:
+ try:
+ data[0] = value
+ except TypeError:
+ data[0] = type(data[0])(value)
+ except:
+ errmsg = "cannot put value '%s' to PV of type '%s'"
+ tname = dbr.Name(ftype).lower()
+ raise ChannelAccessException(errmsg % (repr(value), tname))
else:
if ftype == dbr.CHAR and isinstance(value, str):
View
@@ -292,6 +292,8 @@ def _set_charval(self, val, call_ca=True):
return val
# char waveform as string
if ntype == dbr.CHAR and self.count < ca.AUTOMONITOR_MAXLENGTH:
+ if self.count==1: # handles single character in waveform
+ val = [val]
val = list(val)
if 0 in val:
firstnull = val.index(0)
@@ -301,6 +303,7 @@ def _set_charval(self, val, call_ca=True):
cval = ''.join([chr(i) for i in val[:firstnull]]).rstrip()
except ValueError:
cval = ''
+ self._args['char_value'] = cval
return cval
cval = repr(val)

0 comments on commit 59ad1f2

Please sign in to comment.