Skip to content
This repository
Browse code

fixed bugs with character waveforms holding 1-element arrays

  • Loading branch information...
commit 59ad1f2a6ab5cd6b133e03010eba31ea40766b2a 1 parent 8e9c4da
Matt Newville newville authored

Showing 2 changed files with 18 additions and 10 deletions. Show diff stats Hide diff stats

  1. +15 10 lib/ca.py
  2. +3 0  lib/pv.py
25 lib/ca.py
@@ -1220,10 +1220,10 @@ def put(chid, value, wait=False, timeout=30, callback=None,
1220 1220 """
1221 1221 ftype = field_type(chid)
1222 1222 count = element_count(chid)
1223   - if count > 1: # and not (ftype == dbr.CHAR and isinstance(value, str)):
  1223 + if count > 1:
1224 1224 count = min(len(value), count)
1225   - data = (count*dbr.Map[ftype])()
1226 1225
  1226 + data = (count*dbr.Map[ftype])()
1227 1227 if ftype == dbr.STRING:
1228 1228 if count == 1:
1229 1229 data[0].value = value
@@ -1231,14 +1231,19 @@ def put(chid, value, wait=False, timeout=30, callback=None,
1231 1231 for elem in range(min(count, len(value))):
1232 1232 data[elem].value = value[elem]
1233 1233 elif count == 1:
1234   - try:
1235   - data[0] = value
1236   - except TypeError:
1237   - data[0] = type(data[0])(value)
1238   - except:
1239   - errmsg = "cannot put value '%s' to PV of type '%s'"
1240   - tname = dbr.Name(ftype).lower()
1241   - raise ChannelAccessException(errmsg % (repr(value), tname))
  1234 + if ftype == dbr.CHAR:
  1235 + if isinstance(value, str):
  1236 + value = [ord(value)]
  1237 + data[:] = value
  1238 + else:
  1239 + try:
  1240 + data[0] = value
  1241 + except TypeError:
  1242 + data[0] = type(data[0])(value)
  1243 + except:
  1244 + errmsg = "cannot put value '%s' to PV of type '%s'"
  1245 + tname = dbr.Name(ftype).lower()
  1246 + raise ChannelAccessException(errmsg % (repr(value), tname))
1242 1247
1243 1248 else:
1244 1249 if ftype == dbr.CHAR and isinstance(value, str):
3  lib/pv.py
@@ -292,6 +292,8 @@ def _set_charval(self, val, call_ca=True):
292 292 return val
293 293 # char waveform as string
294 294 if ntype == dbr.CHAR and self.count < ca.AUTOMONITOR_MAXLENGTH:
  295 + if self.count==1: # handles single character in waveform
  296 + val = [val]
295 297 val = list(val)
296 298 if 0 in val:
297 299 firstnull = val.index(0)
@@ -301,6 +303,7 @@ def _set_charval(self, val, call_ca=True):
301 303 cval = ''.join([chr(i) for i in val[:firstnull]]).rstrip()
302 304 except ValueError:
303 305 cval = ''
  306 + self._args['char_value'] = cval
304 307 return cval
305 308
306 309 cval = repr(val)

0 comments on commit 59ad1f2

Please sign in to comment.
Something went wrong with that request. Please try again.