Skip to content

Commit

Permalink
Merge pull request #21 from prjemian/issue_19
Browse files Browse the repository at this point in the history
Issue 19: let user choose to write waveform strings as string or array of integers
  • Loading branch information
prjemian authored Sep 7, 2016
2 parents 7dc857d + f624356 commit 05306aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/pvWebMonitor/pvlist.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ XML Schema to validate the pvlist.xml file
# See LICENSE file for details.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xs:element name="pvwatch">
<xs:complexType>
<xs:sequence>
Expand All @@ -22,14 +22,15 @@ XML Schema to validate the pvlist.xml file
<!-- used to tell humans what the terms mean in a pvlist.xml file -->
<xs:attribute name="name" use="required" type="xs:NCName" />
</xs:complexType>

<xs:complexType name="pv_type">
<!-- defines the declaration of one PV to be monitored -->
<xs:attribute name="PV" type="xs:NMTOKEN" use="required" />
<xs:attribute name="description" type="xs:string" use="required" />
<xs:attribute name="display_format" type="xs:string" use="optional" default="%s" />
<xs:attribute name="mne" type="xs:NCName" use="required" />
<xs:attribute name="_ignore_" type="xs:boolean" use="optional" default="false" />
<xs:attribute name="as_string" type="xs:boolean" use="optional" default="false" />
</xs:complexType>

<xs:attributeGroup name="version_type">
Expand All @@ -43,5 +44,5 @@ XML Schema to validate the pvlist.xml file
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>

</xs:schema>
38 changes: 23 additions & 15 deletions src/pvWebMonitor/pvwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,34 @@ def get_pvlist(self):
pv = key.get("PV")
desc = key.get("description")
fmt = key.get("display_format", "%s") # default format
as_string = key.get("as_string", False) # default format
# :see: http://cars9.uchicago.edu/software/python/pyepics3/pv.html?highlight=as_string#pv.get
try:
self.add_pv(mne, pv, desc, fmt)
self.add_pv(mne, pv, desc, fmt, as_string)
except:
msg = "%s: problem connecting: %s" % (pvlist_file, etree.tostring(key))
utils.logException(msg)

def add_pv(self, mne, pv, desc, fmt):
def add_pv(self, mne, pv, desc, fmt, as_string):
'''Connect to a EPICS (PyEpics) process variable'''
if pv in self.pvdb:
msg = "key '%s' already defined by id=%s" % (pv, self.pvdb[pv]['id'])
raise KeyError(msg)

ch = epics.PV(pv)
entry = {
'name': pv, # EPICS PV name
'id': mne, # symbolic name used in the python code
'description': desc, # text description for humans
'timestamp': None, # client time last monitor was received
'counter': 0, # number of monitor events received
'units': "", # engineering units
'ch': ch, # EPICS PV channel
'format': fmt, # format for display
'value': None, # formatted value
'raw_value': None # unformatted value
'name': pv, # EPICS PV name
'id': mne, # symbolic name used in the python code
'description': desc, # text description for humans
'timestamp': None, # client time last monitor was received
'counter': 0, # number of monitor events received
'units': "", # engineering units
'ch': ch, # EPICS PV channel
'format': fmt, # format for display
'value': None, # formatted value
'raw_value': None, # unformatted value
'char_value': None, # string value
'as_string': as_string, # whether to return the string representation of the value
}
self.pvdb[pv] = entry
self.xref[mne] = pv # mne is local mnemonic, define actual PV in pvlist.xml
Expand Down Expand Up @@ -207,11 +211,15 @@ def update_pvdb(self, pv, raw_value):
msg = '!!!ERROR!!! %s was not found in pvdb!' % pv
raise PvNotRegistered, msg
entry = self.pvdb[pv]
# ch = entry['ch']
ch = entry['ch']
entry['timestamp'] = utils.getTime()
entry['counter'] += 1
entry['raw_value'] = raw_value
entry['value'] = entry['format'] % raw_value
entry['char_value'] = ch.char_value
if entry['as_string']:
entry['value'] = ch.char_value
else:
entry['value'] = entry['format'] % raw_value

def EPICS_monitor_receiver(self, *args, **kws):
'''Response to an EPICS (PyEpics) monitor on the channel'''
Expand All @@ -233,7 +241,7 @@ def buildReport(self):

sorted_id_list = sorted(self.xref)
fields = ("name", "id", "description", "timestamp", "record_type",
"counter", "units", "value", "raw_value", "format")
"counter", "units", "value", "char_value", "raw_value", "format")

for mne in sorted_id_list:
pv = self.xref[mne]
Expand Down

0 comments on commit 05306aa

Please sign in to comment.