pvplot 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pvplot-0.1.1/LICENSE +22 -0
- pvplot-0.1.1/PKG-INFO +39 -0
- pvplot-0.1.1/README.md +24 -0
- pvplot-0.1.1/config/scopeTektronixMSO_pp.py +117 -0
- pvplot-0.1.1/epicsDevTektronixMSO/__init__.py +0 -0
- pvplot-0.1.1/epicsDevTektronixMSO/__main__.py +33 -0
- pvplot-0.1.1/epicsDevTektronixMSO/mainModule.py +723 -0
- pvplot-0.1.1/pyproject.toml +24 -0
pvplot-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrey Sukhanov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
pvplot-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pvplot
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: EPICS PVAccess server for Tektronix MSO oscilloscopes
|
|
5
|
+
Project-URL: Homepage, https://github.com/ASukhanov/epicsDevTektronixMSO
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/ASukhanov/epicsDevTektronixMSO/issues
|
|
7
|
+
Author-email: Andrey Sukhanov <sukhanov@bnl.gov>
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Requires-Dist: p4p
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# epicsDevTektronixMSO
|
|
17
|
+
Python-based EPICS PVAccess server for Tektronix MSO scopes.<br>
|
|
18
|
+
|
|
19
|
+
## installation and run
|
|
20
|
+
```
|
|
21
|
+
pip install epicsDevTektronixMSO
|
|
22
|
+
python -m epicsDevTektronixMSO -h
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Test Control and Plotting
|
|
27
|
+
Requirements:<br>
|
|
28
|
+
- **pypeto** python module for control application
|
|
29
|
+
- **pvplot** python module for plotting application
|
|
30
|
+
|
|
31
|
+
They both could be installed using ```pip install pypeto, pvplot```
|
|
32
|
+
|
|
33
|
+
To run the control application, copy /config/scopeTektronixMSO_pp.py to a folder
|
|
34
|
+
of your choise.
|
|
35
|
+
```
|
|
36
|
+
python -m pypeto -c folder -f scopeTektronixMSO
|
|
37
|
+
python -m pvplot -a V:tekMSO: "c1Waveform c2Waveform c3Waveform c4Waveform c5Waveform c6Waveform"
|
|
38
|
+
```
|
|
39
|
+
|
pvplot-0.1.1/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# epicsDevTektronixMSO
|
|
2
|
+
Python-based EPICS PVAccess server for Tektronix MSO scopes.<br>
|
|
3
|
+
|
|
4
|
+
## installation and run
|
|
5
|
+
```
|
|
6
|
+
pip install epicsDevTektronixMSO
|
|
7
|
+
python -m epicsDevTektronixMSO -h
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Test Control and Plotting
|
|
12
|
+
Requirements:<br>
|
|
13
|
+
- **pypeto** python module for control application
|
|
14
|
+
- **pvplot** python module for plotting application
|
|
15
|
+
|
|
16
|
+
They both could be installed using ```pip install pypeto, pvplot```
|
|
17
|
+
|
|
18
|
+
To run the control application, copy /config/scopeTektronixMSO_pp.py to a folder
|
|
19
|
+
of your choise.
|
|
20
|
+
```
|
|
21
|
+
python -m pypeto -c folder -f scopeTektronixMSO
|
|
22
|
+
python -m pvplot -a V:tekMSO: "c1Waveform c2Waveform c3Waveform c4Waveform c5Waveform c6Waveform"
|
|
23
|
+
```
|
|
24
|
+
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Pypet page for Tektronix MSO scopes"""
|
|
2
|
+
# format: pypeto 1.2+
|
|
3
|
+
__version__ = 'v1.2.2 2025-01-02'#
|
|
4
|
+
print(f'Tek5Scope_Setup {__version__}')
|
|
5
|
+
|
|
6
|
+
#``````````````````Definitions````````````````````````````````````````````````
|
|
7
|
+
# python expressions and functions, used in the spreadsheet
|
|
8
|
+
_ = ''
|
|
9
|
+
def span(x,y=1): return {'span':[x,y]}
|
|
10
|
+
def color(*v): return {'color':v[0]} if len(v)==1 else {'color':list(v)}
|
|
11
|
+
def font(size): return {'font':['Arial',size]}
|
|
12
|
+
def just(i): return {'justify':{0:'left',1:'center',2:'right'}[i]}
|
|
13
|
+
def slider(minValue,maxValue):
|
|
14
|
+
"""Definition of the GUI element: horizontal slider with flexible range"""
|
|
15
|
+
return {'widget':'hslider','opLimits':[minValue,maxValue],'span':[2,1]}
|
|
16
|
+
|
|
17
|
+
LargeFont = {'color':'light gray', **font(18), 'fgColor':'dark green'}
|
|
18
|
+
ButtonFont = {'font':['Open Sans Extrabold',14]}# Comic Sans MS
|
|
19
|
+
# Attributes for gray row, it should be in the first cell:
|
|
20
|
+
#GrayRow = {'ATTRIBUTES':{'color':'light gray', **font(12)}}
|
|
21
|
+
LYRow = {'ATTRIBUTES':{'color':'light yellow'}}
|
|
22
|
+
lColor = color('lightGreen')
|
|
23
|
+
|
|
24
|
+
# definition for plotting cell
|
|
25
|
+
PyPath = '~sukhanov/venv/bin/python -m'
|
|
26
|
+
PaneP2P = ' '.join([f'c{i+1}Peak2Peak' for i in range(6)])
|
|
27
|
+
PaneWF = ' '.join([f'c{i+1}Waveform' for i in range(6)])
|
|
28
|
+
PaneT = 'timing[1] timing[3]'
|
|
29
|
+
Plot = {'Plot':{'launch':f'{PyPath} pvplot -Y-0.04:0.04 -aV:tekMSO: -#0"{PaneP2P}" -#1"{PaneWF}" -#2"{PaneT}"',
|
|
30
|
+
**lColor, **ButtonFont}}
|
|
31
|
+
print(f'Plot command: {Plot}')
|
|
32
|
+
#``````````````````PyPage Object``````````````````````````````````````````````
|
|
33
|
+
class PyPage():
|
|
34
|
+
def __init__(self, instance='tekMSO:', title="Tektronix MSO46 Oscilloscope"):
|
|
35
|
+
"""instance: unique name of the page.
|
|
36
|
+
For EPICS it is usually device prefix
|
|
37
|
+
"""
|
|
38
|
+
print(f'Instantiating Page {instance,title}')
|
|
39
|
+
|
|
40
|
+
#``````````Mandatory class members starts here````````````````````````
|
|
41
|
+
self.namespace = 'PVA'
|
|
42
|
+
self.title = title
|
|
43
|
+
|
|
44
|
+
#``````````Page attributes, optional`````````````````````````
|
|
45
|
+
self.page = {**color(240,240,240)}# Does not work
|
|
46
|
+
#self.page['editable'] = False
|
|
47
|
+
|
|
48
|
+
#``````````Definition of columns`````````````````````````````
|
|
49
|
+
self.columns = {
|
|
50
|
+
1: {'width': 120, 'justify': 'right'},
|
|
51
|
+
2: {'width': 80},
|
|
52
|
+
3: {'width': 80},
|
|
53
|
+
4: {'width': 80},
|
|
54
|
+
5: {'width': 80},
|
|
55
|
+
6: {'width': 80},
|
|
56
|
+
7: {'width': 80},
|
|
57
|
+
8: {'width': 80},
|
|
58
|
+
9: {'width': 80},
|
|
59
|
+
}
|
|
60
|
+
"""`````````````````Configuration of rows`````````````````````````````
|
|
61
|
+
A row is a list of comma-separated cell definitions.
|
|
62
|
+
The cell definition is one of the following:
|
|
63
|
+
1)string, 2)device:parameters, 3)dictionary.
|
|
64
|
+
The dictionary is used when the cell requires extra features like color, width,
|
|
65
|
+
description etc. The dictionary is single-entry {key:value}, where the key is a
|
|
66
|
+
string or device:parameter and the value is dictionary of the features.
|
|
67
|
+
"""
|
|
68
|
+
D = instance
|
|
69
|
+
|
|
70
|
+
#``````````Abbreviations, used in cell definitions
|
|
71
|
+
def ChLine(suffix):
|
|
72
|
+
return [f'{D}c{ch+1}{suffix}' for ch in range(6)]
|
|
73
|
+
#FOption = ' -file '+logreqMap.get(D,'')
|
|
74
|
+
host = '130.199.41.111'
|
|
75
|
+
scopeWWW = {'WWW':{'launch':f'firefox http://{host}/Tektronix/#/client/c/ Tek%20e*Scope',
|
|
76
|
+
**lColor, **ButtonFont, **span(1,2)}}
|
|
77
|
+
|
|
78
|
+
#``````````mandatory member```````````````````````````````````````````
|
|
79
|
+
self.rows = [
|
|
80
|
+
['Device:',D,D+'server',D+'setup','scope time:',{D+'dateTime':span(2,1)},_],
|
|
81
|
+
['Status:',{D+'status': span(8,1)}],
|
|
82
|
+
['Polling Interval:', D+'polling',_,_,_,Plot,scopeWWW],
|
|
83
|
+
#'', {D+'ReadSetting':
|
|
84
|
+
#{**color('cyan'),**span(2,1)}},_,_,],
|
|
85
|
+
['Triggers recorded:', D+'acqCount', 'Lost:', D+'lostTrigs',
|
|
86
|
+
'Acquisitions:',D+'scopeAcqCount'],
|
|
87
|
+
['Horizontal scale:', D+'timePerDiv', ' samples:', D+'recLength',
|
|
88
|
+
'SamplRate:', {D+'samplingRate':span(2,1)},_],
|
|
89
|
+
#['Trigger:', D+'trigSourceS', D+'trigCouplingS', D+'trigSlopeS', 'level:', D+'trigLevelS', 'delay:', {D+'trigDelay':span(2,1)},''],
|
|
90
|
+
['Trigger state:',D+'trigState',' trigMode:',D+'trigMode',
|
|
91
|
+
'TrigLevel','TrigDelay'],
|
|
92
|
+
[{D+'trigger':color('lightCyan')}, D+'trigSource', D+'trigCoupling',
|
|
93
|
+
D+'trigSlope', D+'trigLevel', D+'trigDelay'],
|
|
94
|
+
[{'ATTRIBUTES':color('lightGreen')}, 'Channels:','CH1','CH2','CH3','CH4','CH5','CH6'],
|
|
95
|
+
['Gain:']+ChLine('VoltsPerDiv'),
|
|
96
|
+
['Offset:']+ChLine('Position'),
|
|
97
|
+
['Coupling:']+ChLine('Coupling'),
|
|
98
|
+
['Termination:']+ChLine('Termination'),
|
|
99
|
+
['On/Off:']+ChLine('OnOff'),
|
|
100
|
+
#['Delay:']+ChLine('DelayFromTriggerM'),
|
|
101
|
+
#['Waveform:']+ChLine('WaveforM'),
|
|
102
|
+
['Peak2Peak:']+ChLine('Peak2Peak'),
|
|
103
|
+
#[''],
|
|
104
|
+
# ["Trigger",D+'trigSourceS',D+'trigLevelS',D+'trigSlopeS',D+'trigModeS'],
|
|
105
|
+
# ['',"Setup"],
|
|
106
|
+
# ["Repair:",D+'updateDataA',D+'deviceClearA',D+'resetScopeA',D+'forceTrigA'],
|
|
107
|
+
# ["Session",D+'SaveSession',D+'RecallSession',"folder:",D+'folderS'],
|
|
108
|
+
# [D+'currentSessionS',"<-current",D+'nextSessionS',"out off",D+'sessionsM'],
|
|
109
|
+
#[{'ATTRIBUTES':{'color':'yellow'}},
|
|
110
|
+
#['tAxis:',D+'tAxis'],
|
|
111
|
+
[LYRow,'',{'For Experts only!':{**span(6,1),**font(14)}}],
|
|
112
|
+
[LYRow,'Scope command:', {D+'instrCmdS':span(2,1)},_,{D+'instrCmdR':span(4,1)}],
|
|
113
|
+
[LYRow,'Special commands', {D+'instrCtrl':span(2,1)},_,_,_,_,_,],
|
|
114
|
+
[LYRow,'Timing:',{D+'timing':span(6,1)}],
|
|
115
|
+
[LYRow,'ActOnEvent',D+'actOnEvent','AOE_Limit',D+'aOE_Limit',_,_,_],
|
|
116
|
+
]
|
|
117
|
+
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""PVAccess server of Tektronix MSO scopes"""
|
|
2
|
+
import argparse
|
|
3
|
+
from . import mainModule
|
|
4
|
+
|
|
5
|
+
def main():
|
|
6
|
+
"""parse common arguments and start the server"""
|
|
7
|
+
parser = argparse.ArgumentParser(description = __doc__,
|
|
8
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
9
|
+
epilog=f'{mainModule.C_.AppName, mainModule.__version__}')
|
|
10
|
+
parser.add_argument('-a','--addr', default= '130.199.41.111:4000', help=
|
|
11
|
+
'Intstrument address:port')
|
|
12
|
+
parser.add_argument('-C','--channels', type=int, default=4, help=
|
|
13
|
+
'Number of channels at the scope')
|
|
14
|
+
parser.add_argument('-l', '--listPVs', action='store_true', help=
|
|
15
|
+
'List all generated PVs')
|
|
16
|
+
parser.add_argument('-p', '--prefix', default='tekMSO:', help=
|
|
17
|
+
'Prefix, to be applied to all PVs')
|
|
18
|
+
parser.add_argument('-t', '--timing', help=
|
|
19
|
+
'Parameter to be benchmarked')
|
|
20
|
+
parser.add_argument('-v', '--verbose', action='count', default=0, help=
|
|
21
|
+
'Show more log messages (-vv: show even more)')
|
|
22
|
+
parser.add_argument('-w', '--waveforms', action='store_false', help=
|
|
23
|
+
'Disable acquisition of waveforms')
|
|
24
|
+
pargs = parser.parse_args()
|
|
25
|
+
|
|
26
|
+
print(f'pargs: {pargs}')
|
|
27
|
+
mainModule.C_.verbose = pargs.verbose #verbose is needed for printv
|
|
28
|
+
mainModule.C_.pargs = pargs
|
|
29
|
+
|
|
30
|
+
mainModule.start()
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
main()
|
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
"""PVAccess server for Tektronix MSO oscilloscopes.
|
|
2
|
+
"""
|
|
3
|
+
# pylint: disable=invalid-name
|
|
4
|
+
__version__= 'v0.1.1 2026-01-05'# timestamps corrected
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
#import os
|
|
8
|
+
import time
|
|
9
|
+
from time import perf_counter as timer
|
|
10
|
+
from collections import namedtuple
|
|
11
|
+
import threading
|
|
12
|
+
import re
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
import pyvisa as visa
|
|
16
|
+
|
|
17
|
+
from p4p.nt import NTScalar, NTEnum
|
|
18
|
+
from p4p.nt.enum import ntenum
|
|
19
|
+
from p4p.server import Server
|
|
20
|
+
from p4p.server.thread import SharedPV
|
|
21
|
+
|
|
22
|
+
class C_():
|
|
23
|
+
"""Namespace for module properties"""
|
|
24
|
+
AppName = 'epicsDevTektronixMSO'
|
|
25
|
+
verbose = 0
|
|
26
|
+
pargs = None# Program arguments from main()
|
|
27
|
+
cycle = 0
|
|
28
|
+
lastRareUpdate = 0.
|
|
29
|
+
server = None
|
|
30
|
+
serverState = ''
|
|
31
|
+
|
|
32
|
+
# Applications-specific constants
|
|
33
|
+
scope = None
|
|
34
|
+
PvDefs = []
|
|
35
|
+
PVs = {}# dictionary of {pvName:PV}
|
|
36
|
+
scpi = {}# {pvName:SCPI} map
|
|
37
|
+
setterMap = {}
|
|
38
|
+
readSettingQuery = None
|
|
39
|
+
timeDelta = {}# execution times of different operations
|
|
40
|
+
tstart = 0.
|
|
41
|
+
exceptionCount = {}
|
|
42
|
+
numacq = 0
|
|
43
|
+
triggersLost = 0
|
|
44
|
+
trigTime = 0
|
|
45
|
+
channelsTriggered = ''
|
|
46
|
+
prevTscale = 0.
|
|
47
|
+
|
|
48
|
+
#Conversion map of python variables to EPICS types
|
|
49
|
+
EpicsType = {
|
|
50
|
+
bool: '?',
|
|
51
|
+
str: 's',
|
|
52
|
+
int: 'i',
|
|
53
|
+
float: 'd',
|
|
54
|
+
bytes: 'Y',
|
|
55
|
+
type(None): 'V',
|
|
56
|
+
}
|
|
57
|
+
#``````````````````Constants``````````````````````````````````````````````````
|
|
58
|
+
Threadlock = threading.Lock()
|
|
59
|
+
OK = 0
|
|
60
|
+
IF_CHANGED =True
|
|
61
|
+
ElapsedTime = {}
|
|
62
|
+
#```````````````````Helper methods````````````````````````````````````````````
|
|
63
|
+
def printTime(): return time.strftime("%m%d:%H%M%S")
|
|
64
|
+
def printi(msg): print(f'inf_@{printTime()}: {msg}')
|
|
65
|
+
def printw(msg):
|
|
66
|
+
txt = f'WAR_@{printTime()}: {msg}'
|
|
67
|
+
print(txt)
|
|
68
|
+
publish('status',txt)
|
|
69
|
+
def printe(msg):
|
|
70
|
+
txt = f'ERR_{printTime()}: {msg}'
|
|
71
|
+
print(txt)
|
|
72
|
+
publish('status',txt)
|
|
73
|
+
def _printv(msg, level):
|
|
74
|
+
if C_.verbose >= level: print(f'DBG{level}: {msg}')
|
|
75
|
+
def printv(msg): _printv(msg, 1)
|
|
76
|
+
def printvv(msg): _printv(msg, 2)
|
|
77
|
+
def printv3(msg): _printv(msg, 3)
|
|
78
|
+
|
|
79
|
+
def pvobj(pvname):
|
|
80
|
+
"""Return PV named as pvname"""
|
|
81
|
+
pvsEntry = C_.PVs[pvname]
|
|
82
|
+
return next(iter(pvsEntry.values()))
|
|
83
|
+
|
|
84
|
+
def pvv(pvname):
|
|
85
|
+
"""Return PV value"""
|
|
86
|
+
return pvobj(pvname).current()
|
|
87
|
+
|
|
88
|
+
def publish(pvname, value, ifChanged=False, t=None):
|
|
89
|
+
"""Post PV with new value"""
|
|
90
|
+
pv = pvobj(pvname)
|
|
91
|
+
if t is None:
|
|
92
|
+
t = time.time()
|
|
93
|
+
if not ifChanged or pv.current() != value:
|
|
94
|
+
pv.post(value, timestamp=t)
|
|
95
|
+
|
|
96
|
+
def query(pvnames, explicitSCPIs=None):
|
|
97
|
+
"""Execute query request of the instrument for multiple PVs"""
|
|
98
|
+
scpis = [C_.scpi[pvname] for pvname in pvnames]
|
|
99
|
+
if explicitSCPIs:
|
|
100
|
+
scpis += explicitSCPIs
|
|
101
|
+
combinedScpi = '?;:'.join(scpis) + '?'
|
|
102
|
+
r = C_.scope.query(combinedScpi)
|
|
103
|
+
return r.split(';')
|
|
104
|
+
|
|
105
|
+
#``````````````````Initialization and run``````````````````````````````````````
|
|
106
|
+
def start():
|
|
107
|
+
"""Start p4p server and run it until C_.serverState = Exited"""
|
|
108
|
+
init()
|
|
109
|
+
set_server('Start')
|
|
110
|
+
|
|
111
|
+
# Loop
|
|
112
|
+
#Server.forever(providers = list(C_.PVs.values()))
|
|
113
|
+
C_.server = Server(providers=list(C_.PVs.values()))
|
|
114
|
+
printi(f'Start server with polling interval {pvv("polling")}')
|
|
115
|
+
while not C_.serverState.startswith('Exit'):
|
|
116
|
+
time.sleep(pvv("polling"))
|
|
117
|
+
if not C_.serverState.startswith('Stop'):
|
|
118
|
+
poll()
|
|
119
|
+
printi('Server is exited')
|
|
120
|
+
|
|
121
|
+
def init():
|
|
122
|
+
"""Module initialization"""
|
|
123
|
+
init_visa()
|
|
124
|
+
create_PVs()
|
|
125
|
+
adopt_local_setting()
|
|
126
|
+
|
|
127
|
+
def poll():
|
|
128
|
+
"""Poll the instrument and process data"""
|
|
129
|
+
C_.cycle += 1
|
|
130
|
+
tnow = time.time()
|
|
131
|
+
if tnow - C_.lastRareUpdate > 1.:
|
|
132
|
+
C_.lastRareUpdate = tnow
|
|
133
|
+
rareUpdate()
|
|
134
|
+
|
|
135
|
+
if trigger_is_detected():
|
|
136
|
+
acquire_waveforms()
|
|
137
|
+
|
|
138
|
+
printvv(f'poll {C_.cycle}')
|
|
139
|
+
|
|
140
|
+
def rareUpdate():
|
|
141
|
+
"""Called for infrequent updates"""
|
|
142
|
+
printvv(f'rareUpdate {time.time()}')
|
|
143
|
+
with Threadlock:
|
|
144
|
+
r = query(['actOnEvent'],['DATE?;:TIMe'])
|
|
145
|
+
publish('actOnEvent', r[0], IF_CHANGED)
|
|
146
|
+
publish('dateTime', ' '.join(r[1:3]).replace('"',''))
|
|
147
|
+
publish('scopeAcqCount', C_.numacq, IF_CHANGED)
|
|
148
|
+
publish('lostTrigs', C_.triggersLost, IF_CHANGED)
|
|
149
|
+
#print(f'ElapsedTime: {ElapsedTime}')
|
|
150
|
+
publish('timing', [(round(-i,6)) for i in ElapsedTime.values()])
|
|
151
|
+
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
152
|
+
#``````````````````Initialization functions```````````````````````````````````
|
|
153
|
+
def create_PVs():
|
|
154
|
+
"""Create PVs from PvDefs"""
|
|
155
|
+
#``````````````````Definition of PVs``````````````````````````````````````
|
|
156
|
+
R,W = False,True # values for the 'writable' field
|
|
157
|
+
# abbreviations of EPICS Value fields
|
|
158
|
+
U,CL,CH = 'display.units','control.limitLow','control.limitHigh'
|
|
159
|
+
# abbreviations of extra fields
|
|
160
|
+
LV,SCPI,SET = 'legalValues', 'SCPI', 'setter'
|
|
161
|
+
PvDef = namedtuple('PvDef',
|
|
162
|
+
[ 'name', 'desc', 'value', 'writable', 'fields', 'extra'], defaults=[False,{},{}])
|
|
163
|
+
C_.PvDefs = [
|
|
164
|
+
# test PVs
|
|
165
|
+
PvDef('strS', 'Test string', 'Hello world', W),
|
|
166
|
+
PvDef('int', 'Integer', 27, W, {U:'digits',CH:16}),
|
|
167
|
+
# Note: Currently there is no distinction between fixed and floating arrays.
|
|
168
|
+
PvDef('intVarArray', 'Variable array of integers', [0], W),
|
|
169
|
+
PvDef('floatArray', 'Variable array of floats', [0.], W, {U:'V'}),
|
|
170
|
+
|
|
171
|
+
# instruments's PVs
|
|
172
|
+
PvDef('status', 'Server status', ''),
|
|
173
|
+
PvDef('hostPort', 'IP_address:port', C_.pargs.addr, R),
|
|
174
|
+
PvDef('server', 'Server control', 'Stop', W, {},
|
|
175
|
+
{LV:'Start,Stop,Clear,Exit,Started,Stopped,Exited',SET:set_server}),
|
|
176
|
+
PvDef('polling', 'Polling interval', 1.0, W, {U:'S'}),
|
|
177
|
+
PvDef('instrCtrl', 'Scope control commands', '*OPC', W, {},
|
|
178
|
+
{LV:'*OPC,*OPC?,*CLS?,*RST,!d,*TST,*IDN?,ACQuire:STATE?,AUTOset EXECute'}),
|
|
179
|
+
PvDef('instrCmdS', 'Execute a scope command', '*IDN?', W, {},
|
|
180
|
+
{SET:set_instrCmdS}),
|
|
181
|
+
PvDef('instrCmdR', 'Response of the instrCmdS', ''),
|
|
182
|
+
PvDef('timing', 'Timing: [trigger,waveforms,publish_wf,query_wf,preamble]', [0.], R, {U:'S'}),
|
|
183
|
+
|
|
184
|
+
# scope-specific PVs
|
|
185
|
+
PvDef('dateTime', 'Scope`s date & time', '?'),#, R, {},{SCPI:'DATE?;:TIMe'}),
|
|
186
|
+
PvDef('acqCount', 'Number of acquisition recorded', 0),
|
|
187
|
+
PvDef('scopeAcqCount', 'Acquisition count of the scope', 0, R, {},
|
|
188
|
+
{SCPI:'ACQuire:NUMACq'}),
|
|
189
|
+
PvDef('recLength', 'Number of points per waveform', 1000, W, {},
|
|
190
|
+
{CL: 100, CH:1000000, SCPI:'HORizontal:RECOrdlength'}),
|
|
191
|
+
PvDef('samplingRate', 'Sampling Rate', 0., W, {U:'Hz'},
|
|
192
|
+
{SCPI:'HORizontal:SAMPLERate'}),
|
|
193
|
+
PvDef('timePerDiv', 'Horizontal scale', 2.e-6, R, {U:'S'},
|
|
194
|
+
{SCPI: 'HORizontal:SCAle'}),
|
|
195
|
+
PvDef('tAxis', 'Array of horizontal axis', [0.], R, {U:'S'}),
|
|
196
|
+
PvDef('date', 'Scope date time', '?'),
|
|
197
|
+
PvDef('lostTrigs', 'Number of triggers lost', 0),
|
|
198
|
+
PvDef('trigger', 'Click to force trigger event to occur', 'Trigger',W,{},
|
|
199
|
+
{LV:'Force!,Trigger', SET:set_trigger}),
|
|
200
|
+
PvDef('trigSource', 'Trigger source', 'CH1', W, {},
|
|
201
|
+
{LV:'CH1,CH2,CH3,CH4,CH5,CH6,CH7,CH8,LINE,AUX', SCPI:'TRIGger:A:EDGE:SOUrce'}),
|
|
202
|
+
PvDef('trigLevel', 'Trigger level', 0., W, {U:'V'},
|
|
203
|
+
{SET:set_trigLevel}),
|
|
204
|
+
PvDef('trigDelay', 'Trigger delay', 0., W, {U:'S'},
|
|
205
|
+
{SCPI:'HORizontal:DELay:MODe ON;:HORizontal:DELay:TIMe'}),
|
|
206
|
+
PvDef('trigHoldoff', 'Time after trigger when it will not accept another triggers',
|
|
207
|
+
5.0E-3, W, {U:'S'}, {SCPI:'TRIGger:A:HOLDoff:TIMe'}),
|
|
208
|
+
PvDef('trigSlope', 'Trigger slope', 'RISE', W, {},
|
|
209
|
+
{LV:'RISE,FALL,EITHER', SCPI:'TRIGger:A:EDGE:SLOpe'}),
|
|
210
|
+
PvDef('trigCoupling', 'Trigger coupling', 'DC', W, {},
|
|
211
|
+
{LV:'DC,HFRej,LFRej,NoiseRej', SCPI:'TRIGger:A:EDGE:COUPling'}),
|
|
212
|
+
PvDef('trigMode', 'Trigger mode. Should be NORMAL.', 'NORMAL', W, {},
|
|
213
|
+
{LV:'NORMAL,AUTO', SCPI:'TRIGger:A:MODe'}),
|
|
214
|
+
PvDef('trigState', 'State of the triggering system, Should be: READY', '?', R, {},
|
|
215
|
+
{SCPI:'TRIGger:STATE'}),
|
|
216
|
+
PvDef('actOnEvent', 'Enables the saving waveforms on trigger', 0, W, {},
|
|
217
|
+
{CL: 0, CH:1, SCPI:'ACTONEVent:ENable'}),
|
|
218
|
+
PvDef('aOE_Limit', 'Limit of Action On Event saves', 80, W, {},
|
|
219
|
+
{SCPI:'ACTONEVent:LIMITCount'}),
|
|
220
|
+
PvDef('setup', 'Save/recall instrument state', 'Setup', W, {},
|
|
221
|
+
{SET:set_setup, LV:'Save,Recall,Setup'}),
|
|
222
|
+
]
|
|
223
|
+
# Templates for channel-related PVs
|
|
224
|
+
ChannelTemplates = [
|
|
225
|
+
PvDef('c$VoltsPerDiv', 'Vertical sensitivity', 0., W, {U:'V/du'},
|
|
226
|
+
{SCPI:'CH$:SCAle'}),
|
|
227
|
+
PvDef('c$VoltsPerDiv', 'Vertical sensitivity associated with waveform', 0., W, {U:'V/du'}),
|
|
228
|
+
PvDef('c$Position', 'Vertical position', 0., W, {U:'du'},
|
|
229
|
+
{SCPI:'CH$:OFFSet 0;POSition'}),
|
|
230
|
+
PvDef('c$Coupling', 'Coupling', 'DC', W, {},
|
|
231
|
+
{LV:'AC,DC', SCPI:'CH$:COUPling'}),
|
|
232
|
+
PvDef('c$Termination', 'Termination', '50.000', W, {U:'Ohm'},
|
|
233
|
+
{LV:'50.000,1.0000E+6', SCPI:'CH$:TER'}),
|
|
234
|
+
PvDef('c$OnOff', 'Trace On/Off', '0', W, {},
|
|
235
|
+
{LV:'0,1', SCPI:'DISplay:WAVEView1:CH$:STATE'}),
|
|
236
|
+
PvDef('c$Waveform', 'Channel data', [0.], R),
|
|
237
|
+
PvDef('c$Peak2Peak', 'Peak to peak amplitude', 0., R, {U:'du'}),
|
|
238
|
+
]
|
|
239
|
+
# extend PvDefs with channel-related PVs
|
|
240
|
+
for pvdef in ChannelTemplates:
|
|
241
|
+
for ch in range(C_.pargs.channels):
|
|
242
|
+
newname = pvdef.name.replace('$',str(ch+1))
|
|
243
|
+
fields = pvdef
|
|
244
|
+
newpvdef = PvDef(newname, *fields[1:])
|
|
245
|
+
C_.PvDefs.append(newpvdef)
|
|
246
|
+
|
|
247
|
+
# Create PVs from updated PvDefs
|
|
248
|
+
for pvdef in C_.PvDefs:
|
|
249
|
+
count = 1
|
|
250
|
+
if isinstance(pvdef.value, str):
|
|
251
|
+
first = pvdef.value
|
|
252
|
+
else:
|
|
253
|
+
try:
|
|
254
|
+
first = pvdef.value[0]
|
|
255
|
+
count = len(pvdef.value)
|
|
256
|
+
if count == 1:
|
|
257
|
+
count = 0# variable array
|
|
258
|
+
except TypeError:
|
|
259
|
+
first = pvdef.value
|
|
260
|
+
count = 1
|
|
261
|
+
ptype = EpicsType[type(first)]
|
|
262
|
+
if count != 1:
|
|
263
|
+
ptype = 'a'+ptype
|
|
264
|
+
printvv(f'>creating {pvdef.name} of type {ptype}, v:{pvdef.value}')
|
|
265
|
+
ts = time.time()
|
|
266
|
+
|
|
267
|
+
# handle the field 'extra'
|
|
268
|
+
if len(pvdef.extra) == 0:
|
|
269
|
+
normativeType = NTScalar(ptype, display=True, control=pvdef.writable)
|
|
270
|
+
value = pvdef.value
|
|
271
|
+
else:
|
|
272
|
+
# handle legalValues
|
|
273
|
+
lv = pvdef.extra.get(LV)
|
|
274
|
+
if lv is None:
|
|
275
|
+
normativeType = NTScalar(ptype, display=True, control=pvdef.writable)
|
|
276
|
+
value = pvdef.value
|
|
277
|
+
else:
|
|
278
|
+
lv = lv.split(',')
|
|
279
|
+
try:
|
|
280
|
+
idx = lv.index(pvdef.value)
|
|
281
|
+
except ValueError:
|
|
282
|
+
printe(f'Could not create PV for {pvdef.name}: its value {pvdef.value} is not in legalValues')
|
|
283
|
+
sys.exit(1)
|
|
284
|
+
normativeType = NTEnum(control=pvdef.writable)
|
|
285
|
+
value = {'choices': lv, 'index': idx}
|
|
286
|
+
printvv(f'LegalValues of {pvdef.name}: {lv}, value: {value}')
|
|
287
|
+
|
|
288
|
+
# create PV
|
|
289
|
+
try:
|
|
290
|
+
pv = SharedPV(nt=normativeType)
|
|
291
|
+
pv.open(value)
|
|
292
|
+
if isinstance(normativeType,NTEnum):
|
|
293
|
+
pv.post(value, timestamp=ts)
|
|
294
|
+
else:
|
|
295
|
+
V = pv._wrap(value, timestamp=ts)
|
|
296
|
+
V['display.description'] = pvdef.desc
|
|
297
|
+
for k,v in pvdef.fields.items():
|
|
298
|
+
V[k] = v
|
|
299
|
+
pv.post(V)
|
|
300
|
+
except Exception as e:
|
|
301
|
+
printw(f'Could not create PV for {pvdef.name}: {str(e)[:200]}')
|
|
302
|
+
continue
|
|
303
|
+
pv.name = C_.pargs.prefix + pvdef.name
|
|
304
|
+
|
|
305
|
+
# for writables we need to add setters
|
|
306
|
+
if pvdef.writable:
|
|
307
|
+
@pv.put
|
|
308
|
+
def handle(pv, op):
|
|
309
|
+
ct = time.time()
|
|
310
|
+
tt0 = timer()
|
|
311
|
+
v = op.value()
|
|
312
|
+
tt1 = timer()
|
|
313
|
+
vr = v.raw.value
|
|
314
|
+
printvv(f'v type: {type(v)} = {v}, {vr}')
|
|
315
|
+
if isinstance(v, ntenum):
|
|
316
|
+
vr = v
|
|
317
|
+
corename = pv.name.removeprefix(C_.pargs.prefix)
|
|
318
|
+
|
|
319
|
+
printv(f'setting {corename} to {vr}')
|
|
320
|
+
# execute SCPI command for corresponding PVs
|
|
321
|
+
scpi = C_.scpi.get(corename)
|
|
322
|
+
setter = C_.setterMap.get(corename)
|
|
323
|
+
if setter: # it is higher priority
|
|
324
|
+
printv(f'>setter[{setter}]')
|
|
325
|
+
setter(vr)
|
|
326
|
+
# value could change by the setter
|
|
327
|
+
if corename not in ['instrCmdS']:
|
|
328
|
+
printv(f'update vr of {corename}: {vr}')
|
|
329
|
+
vr = pvv(corename)
|
|
330
|
+
elif scpi:
|
|
331
|
+
printv(f'>scopeCmd({scpi})')
|
|
332
|
+
scopeCmd(f'{scpi} {vr}')
|
|
333
|
+
|
|
334
|
+
tt2 = timer()
|
|
335
|
+
pv.post(vr, timestamp=ct) # update subscribers
|
|
336
|
+
op.done()
|
|
337
|
+
tt3 = timer()
|
|
338
|
+
dt = [round(i,6) for i in (tt2-tt1,tt3-tt2,tt1-tt0)]
|
|
339
|
+
#print(f'timing set,post: {dt}')
|
|
340
|
+
if C_.pargs.timing:
|
|
341
|
+
C_.timeDelta['local set'].append(dt[0])
|
|
342
|
+
C_.timeDelta['PVA_post'].append(dt[1])
|
|
343
|
+
|
|
344
|
+
if C_.pargs.listPVs:
|
|
345
|
+
printi(f'PV {pv.name} created: {pv}')
|
|
346
|
+
C_.PVs[pvdef.name] = {pv.name:pv}
|
|
347
|
+
|
|
348
|
+
# Make a map of pvNames to SCPI commands and a combined query for all SCPI-related parameters
|
|
349
|
+
printv('>make_par2scpiMap and setterMap')
|
|
350
|
+
for pvdef in C_.PvDefs:
|
|
351
|
+
scpi = pvdef.extra.get('SCPI')
|
|
352
|
+
if scpi:
|
|
353
|
+
scpi = scpi.replace('$',pvdef.name[1])
|
|
354
|
+
# remove lower case letter for brevity
|
|
355
|
+
scpi = ''.join([char for char in scpi if not char.islower()])
|
|
356
|
+
# check, if scpi is correct:
|
|
357
|
+
if C_.verbose > 1:
|
|
358
|
+
s = scpi+'?'
|
|
359
|
+
printvv(f'>query {s}')
|
|
360
|
+
C_.scope.query(s)
|
|
361
|
+
if not scpi[0] in '!*':
|
|
362
|
+
C_.scpi[pvdef.name] = scpi
|
|
363
|
+
setter = pvdef.extra.get('setter')
|
|
364
|
+
if setter:
|
|
365
|
+
C_.setterMap[pvdef.name] = setter
|
|
366
|
+
# add special case of TrigLevel
|
|
367
|
+
C_.scpi['trigLevel'] = trigLevelCmd()
|
|
368
|
+
|
|
369
|
+
C_.readSettingQuery = '?;:'.join(C_.scpi.values()) + '?'
|
|
370
|
+
printv(f'setterMap: {C_.setterMap}')
|
|
371
|
+
printv(f'readSettingQuery:\n{C_.readSettingQuery}')
|
|
372
|
+
|
|
373
|
+
def init_visa():
|
|
374
|
+
'''Init VISA interface to device'''
|
|
375
|
+
try:
|
|
376
|
+
C_.rm = visa.ResourceManager('@py')
|
|
377
|
+
except ModuleNotFoundError as e:
|
|
378
|
+
printe(f'in visa.ResourceManager: {e}')
|
|
379
|
+
sys.exit(1)
|
|
380
|
+
|
|
381
|
+
rn = C_.pargs.addr.replace(':','::')
|
|
382
|
+
resourceName = 'TCPIP::'+rn+'::SOCKET'
|
|
383
|
+
printi(f'Open resource {resourceName}')
|
|
384
|
+
C_.scope = C_.rm.open_resource(resourceName)
|
|
385
|
+
C_.scope.set_visa_attribute( visa.constants.VI_ATTR_TERMCHAR_EN, True)
|
|
386
|
+
C_.scope.timeout = 2000 # ms
|
|
387
|
+
print('C_scope created')
|
|
388
|
+
print(f"IDN: {C_.scope.query('*IDN?')}")
|
|
389
|
+
|
|
390
|
+
try:
|
|
391
|
+
C_.scope.write('*CLS') # clear ESR, previous error messages will be cleared
|
|
392
|
+
except Exception as e:
|
|
393
|
+
printe(f'Resource {resourceName} not responding: {e}')
|
|
394
|
+
sys.exit()
|
|
395
|
+
C_.scope.write('*OPC')# that does not work!
|
|
396
|
+
resetNeeded = False
|
|
397
|
+
try: printi('*OPC?'+C_.scope.query('*OPC?'))
|
|
398
|
+
except:
|
|
399
|
+
printw('*OPC? failed'); resetNeeded = True
|
|
400
|
+
try: printi('*ESR?'+C_.scope.query('*ESR?'))
|
|
401
|
+
except:
|
|
402
|
+
printw('*ESR? failed'); resetNeeded = True
|
|
403
|
+
|
|
404
|
+
if resetNeeded:
|
|
405
|
+
printw('To recover the scope a command !d was sent')
|
|
406
|
+
C_.scope.write('!d')
|
|
407
|
+
sys.exit(1)
|
|
408
|
+
|
|
409
|
+
C_.scope.encoding = 'latin_1'
|
|
410
|
+
C_.scope.read_termination = '\n'#Important.
|
|
411
|
+
|
|
412
|
+
C_.scope.write('HORizontal:DELay:MODe ON')
|
|
413
|
+
C_.scope.write('HORizontal:MODE MANual')
|
|
414
|
+
C_.scope.write('HORizontal:MODE:MANual:CONFIGure HORIZontalscale')
|
|
415
|
+
|
|
416
|
+
#C_.scope.write('DATa:ENCdg SRIBINARY')
|
|
417
|
+
C_.scope.write(( ':WFMOUTPRE:ENCdg BINARY;'
|
|
418
|
+
':WFMOUTPRE:BN_Fmt RI;'
|
|
419
|
+
':WFMOUTPRE:BYT_NR 2;'
|
|
420
|
+
':WFMOUTPRE:BYT_Or LSB;'))
|
|
421
|
+
|
|
422
|
+
# def close_visa(C_):
|
|
423
|
+
# C_.rm.close()
|
|
424
|
+
# C_.scope = None
|
|
425
|
+
|
|
426
|
+
#``````````````````Setters
|
|
427
|
+
def set_instrCmdS(cmd):
|
|
428
|
+
"""Setter for the instrCmdS PV"""
|
|
429
|
+
return scopeCmd(cmd, True)
|
|
430
|
+
|
|
431
|
+
def set_server(state=None):
|
|
432
|
+
"""setter for the server PV"""
|
|
433
|
+
#printv(f'>set_server({state}), {type(state)}')
|
|
434
|
+
if state is None:
|
|
435
|
+
state = pvv('server')
|
|
436
|
+
printi(f'Setting server state to {state}')
|
|
437
|
+
state = str(state)
|
|
438
|
+
if state == 'Start':
|
|
439
|
+
printi('starting the server')
|
|
440
|
+
adopt_local_setting()
|
|
441
|
+
publish('server','Started')
|
|
442
|
+
elif state == 'Stop':
|
|
443
|
+
printi('server stopped')
|
|
444
|
+
publish('server','Stopped')
|
|
445
|
+
elif state == 'Exit':
|
|
446
|
+
printi('server is exiting')
|
|
447
|
+
publish('server','Exited')
|
|
448
|
+
elif state == 'Clear':
|
|
449
|
+
publish('acqCount', 0)
|
|
450
|
+
#publish('lostTrigs', 0)
|
|
451
|
+
C_.triggersLost = 0
|
|
452
|
+
publish('status','Cleared')
|
|
453
|
+
# set server to previous state
|
|
454
|
+
set_server(C_.serverState)
|
|
455
|
+
C_.serverState = state
|
|
456
|
+
return OK
|
|
457
|
+
|
|
458
|
+
def set_setup(action):
|
|
459
|
+
"""setter for the setup PV"""
|
|
460
|
+
action = str(action)
|
|
461
|
+
with Threadlock:
|
|
462
|
+
if action == 'Save':
|
|
463
|
+
C_.scope.write("SAVE:SETUP 'c:/latest.set'")
|
|
464
|
+
elif action == 'Recall':
|
|
465
|
+
if str(pvv('server')).startswith('Start'):
|
|
466
|
+
printw('Please set server to Stop before Recalling')
|
|
467
|
+
publish('setup','Setup')
|
|
468
|
+
return
|
|
469
|
+
C_.scope.write("RECAll:SETUp 'c:/latest.set'")
|
|
470
|
+
elif action != 'Setup':
|
|
471
|
+
printw(f'WAR: wrong setup action: {action}')
|
|
472
|
+
if action == 'Recall':
|
|
473
|
+
adopt_local_setting()
|
|
474
|
+
publish('setup','Setup')
|
|
475
|
+
|
|
476
|
+
def set_trigger(action):
|
|
477
|
+
action = str(action)
|
|
478
|
+
if action.startswith('Force'):
|
|
479
|
+
C_.scope.write('TRIGger FORCe')
|
|
480
|
+
publish('trigger','Trigger')
|
|
481
|
+
|
|
482
|
+
def set_trigLevel(value):
|
|
483
|
+
printv(f'set_trigLevel: {type(value),value}')
|
|
484
|
+
with Threadlock:
|
|
485
|
+
C_.scope.write(trigLevelCmd() + f' {value}')
|
|
486
|
+
v = C_.scope.query(trigLevelCmd() + '?')
|
|
487
|
+
publish('trigLevel',v)
|
|
488
|
+
|
|
489
|
+
#``````````````````````````````````````````````````````````````````````````````
|
|
490
|
+
def scopeCmd(cmd, updateCmdM=False):
|
|
491
|
+
"""send command to scope, update instrCmdR if needed, return 0 if OK"""
|
|
492
|
+
printv(f'>scopeCmd: {cmd, updateCmdM} @{round(time.time(),6)}')
|
|
493
|
+
rc = 0
|
|
494
|
+
try:
|
|
495
|
+
with Threadlock:
|
|
496
|
+
if '?' in cmd:
|
|
497
|
+
reply = C_.scope.query(cmd)
|
|
498
|
+
printv(f'scope reply:{reply}')
|
|
499
|
+
if updateCmdM:
|
|
500
|
+
printv('updating instrCmdR')
|
|
501
|
+
publish('instrCmdR',reply)
|
|
502
|
+
else:
|
|
503
|
+
C_.scope.write(cmd)
|
|
504
|
+
except:
|
|
505
|
+
return handle_exception('in scopeCmd(%s)'%cmd)
|
|
506
|
+
printv(f'<scopeCmd {rc}')
|
|
507
|
+
return rc
|
|
508
|
+
|
|
509
|
+
def handle_exception(where):
|
|
510
|
+
"""Handle exception"""
|
|
511
|
+
#print('handle_exception',sys.exc_info())
|
|
512
|
+
exceptionText = str(sys.exc_info()[1])
|
|
513
|
+
tokens = exceptionText.split()
|
|
514
|
+
msg = 'ERR:'+tokens[0] if tokens[0] == 'VI_ERROR_TMO' else exceptionText
|
|
515
|
+
msg = msg+': '+where
|
|
516
|
+
printe(msg)
|
|
517
|
+
with Threadlock:
|
|
518
|
+
C_.scope.write('*CLS')
|
|
519
|
+
return -1
|
|
520
|
+
|
|
521
|
+
def adopt_local_setting():
|
|
522
|
+
"""Read scope setting and update PVs"""
|
|
523
|
+
printv(f'>adopt_local_setting')
|
|
524
|
+
ct = time.time()
|
|
525
|
+
try:
|
|
526
|
+
with Threadlock:
|
|
527
|
+
values = C_.scope.query(C_.readSettingQuery).split(';')
|
|
528
|
+
nothingChanged = True
|
|
529
|
+
printvv(f'parnames: {C_.scpi.keys()}')
|
|
530
|
+
printvv(f'C_.readSettingQuery: {C_.readSettingQuery}')
|
|
531
|
+
printvv(f'values: {values}')
|
|
532
|
+
if len(C_.scpi) != len(values):
|
|
533
|
+
l = min(len(C_.scpi),len(values))
|
|
534
|
+
printe(f'ReadSetting failed for {list(C_.scpi.keys())[l]}')
|
|
535
|
+
sys.exit(1)
|
|
536
|
+
for parname,v in zip(C_.scpi, values):
|
|
537
|
+
pv = pvobj(parname)
|
|
538
|
+
pvValue = pv.current()
|
|
539
|
+
|
|
540
|
+
if isinstance(pvValue, ntenum):
|
|
541
|
+
pvValue = str(pvValue)
|
|
542
|
+
else:
|
|
543
|
+
v = type(pvValue.raw.value)(v)
|
|
544
|
+
printv(f'parname,v: {parname, type(v), v, type(pvValue), pvValue}')
|
|
545
|
+
valueChanged = pvValue != v
|
|
546
|
+
if valueChanged:
|
|
547
|
+
printv(f'posting {pv.name}={v}')
|
|
548
|
+
pv.post(v, timestamp=ct)
|
|
549
|
+
nothingChanged = False
|
|
550
|
+
printv(f'PV {pv.name} changed using local value {v}')
|
|
551
|
+
|
|
552
|
+
except Exception as e:
|
|
553
|
+
printe('Exception in adopt_local_setting:'+str(e))
|
|
554
|
+
if nothingChanged:
|
|
555
|
+
printi('Local setting did not change.')
|
|
556
|
+
|
|
557
|
+
def trigLevelCmd():
|
|
558
|
+
"""Generate SCPI command for trigger level control"""
|
|
559
|
+
ch = str(pvv('trigSource'))
|
|
560
|
+
if ch[:2] != 'CH':
|
|
561
|
+
return ''
|
|
562
|
+
r = 'TRIGger:A:LEVel:'+ch
|
|
563
|
+
printv(f'tlcmd: {r}')
|
|
564
|
+
return r
|
|
565
|
+
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
566
|
+
#``````````````````Acquisition-related functions``````````````````````````````
|
|
567
|
+
def trigger_is_detected():
|
|
568
|
+
"""check if scope was triggered"""
|
|
569
|
+
try:
|
|
570
|
+
with Threadlock:
|
|
571
|
+
r = query(['trigState','scopeAcqCount','recLength',
|
|
572
|
+
'timePerDiv'], ['DATa:SOUrce:AVAILable'])
|
|
573
|
+
except Exception as e:
|
|
574
|
+
printe(f'in query for trigger: {e}')
|
|
575
|
+
for exc in C_.exceptionCount:
|
|
576
|
+
if exc in str(e):
|
|
577
|
+
C_.exceptionCount[exc] += 1
|
|
578
|
+
errCountLimit = 2
|
|
579
|
+
if C_.exceptionCount[exc] >= errCountLimit:
|
|
580
|
+
printe(f'Processing stopped due to {exc} happened {errCountLimit} times')
|
|
581
|
+
set_server('Exit')
|
|
582
|
+
else:
|
|
583
|
+
printw(f'Exception #{C_.exceptionCount[exc]} during processing: {exc}')
|
|
584
|
+
return False
|
|
585
|
+
|
|
586
|
+
# last query was successfull, clear error counts
|
|
587
|
+
ElapsedTime['trigger_detection'] = timer()
|
|
588
|
+
for i in C_.exceptionCount:
|
|
589
|
+
C_.exceptionCount[i] = 0
|
|
590
|
+
try:
|
|
591
|
+
trigstate,numacq,rl,timePerDiv,C_.channelsTriggered = r
|
|
592
|
+
except Exception as e:
|
|
593
|
+
printw(f'wrong trig info: {r}, exception:{e}')
|
|
594
|
+
return False
|
|
595
|
+
numacq = int(numacq)
|
|
596
|
+
if numacq == 0 or C_.numacq == 0:
|
|
597
|
+
C_.triggersLost = 0
|
|
598
|
+
else:
|
|
599
|
+
C_.triggersLost += numacq - C_.numacq - 1
|
|
600
|
+
C_.triggersLost = max(C_.triggersLost, 0)
|
|
601
|
+
if numacq <= C_.numacq:
|
|
602
|
+
C_.numacq = numacq
|
|
603
|
+
return False
|
|
604
|
+
|
|
605
|
+
C_.numacq = numacq
|
|
606
|
+
C_.trigtime = time.time()
|
|
607
|
+
d = {'recLength': int(rl), 'timePerDiv': float(timePerDiv),
|
|
608
|
+
'trigState':trigstate}
|
|
609
|
+
for pvname,value in d.items():
|
|
610
|
+
publish(pvname, value, IF_CHANGED, t=C_.trigtime)
|
|
611
|
+
ElapsedTime['trigger_detection'] -= timer()
|
|
612
|
+
return True
|
|
613
|
+
|
|
614
|
+
def acquire_waveforms():
|
|
615
|
+
"""acquire scope waveforms"""
|
|
616
|
+
printv('>acquire_waveform')
|
|
617
|
+
if not C_.pargs.waveforms:
|
|
618
|
+
return
|
|
619
|
+
publish('acqCount', pvv('acqCount') + 1, t=C_.trigTime)
|
|
620
|
+
#print('rl,channels',rl,channels)
|
|
621
|
+
ElapsedTime['acquire_wf'] = timer()
|
|
622
|
+
ElapsedTime['publish_wf'] = 0.
|
|
623
|
+
ElapsedTime['query_wf'] = 0.
|
|
624
|
+
ElapsedTime['preamble'] = 0.
|
|
625
|
+
channels = C_.channelsTriggered.split(',')
|
|
626
|
+
for ch in channels:
|
|
627
|
+
# refresh scalings
|
|
628
|
+
#TODO: this section is quite time consuming and can be avoided
|
|
629
|
+
# but if we monitor XINCR, YMULT, YZERO, V/DIV separately then it takes twice longer
|
|
630
|
+
ts = timer()
|
|
631
|
+
try:
|
|
632
|
+
# most of the time is spent here, 4 times longer than the reading of waveform:
|
|
633
|
+
with Threadlock:
|
|
634
|
+
preamble = C_.scope.query(f'DATA:SOUrce {ch};:WFMOutpre?')
|
|
635
|
+
#TODO: query and decode the WFMOutpre in the rareUpdate
|
|
636
|
+
#t = timer()
|
|
637
|
+
#C_.scope.write(f'DATA:SOUrce {ch}')
|
|
638
|
+
#print(f'Data source time: {timer()-t}')
|
|
639
|
+
#t = timer()
|
|
640
|
+
#preamble = C_.scope.query(f':WFMOutpre?')
|
|
641
|
+
#print(f'preamble time: {timer()-t}')
|
|
642
|
+
except Exception as e:
|
|
643
|
+
printe(f'Exception in getting waveform preamble for {ch}:{e}')
|
|
644
|
+
break
|
|
645
|
+
ElapsedTime['preamble'] -= timer() - ts
|
|
646
|
+
#TODO: if preamble did not change, then we can skip its decoding, we can save ~65us
|
|
647
|
+
preambleMap = decode_preamble(preamble)# timing=60us
|
|
648
|
+
#print(f'preambleMap:{preambleMap.keys()}')
|
|
649
|
+
if preambleMap is None:
|
|
650
|
+
break
|
|
651
|
+
|
|
652
|
+
xincr = float(preambleMap['XINCR'])
|
|
653
|
+
ymult = float(preambleMap['YMULT'])
|
|
654
|
+
yzero = float(preambleMap['YZERO'])
|
|
655
|
+
bigEndian = preambleMap['BYT_Or'] == 'MSB'
|
|
656
|
+
vPerDiv = preambleMap['V/DIV']
|
|
657
|
+
|
|
658
|
+
if xincr != C_.prevTscale:
|
|
659
|
+
msg = f'Horizontal scale changed, new tAxis. {xincr,C_.prevTscale}'
|
|
660
|
+
printi(msg)
|
|
661
|
+
publish('status',msg)
|
|
662
|
+
C_.prevTscale = xincr
|
|
663
|
+
tAxis = np.arange(pvv('recLength'))*C_.prevTscale
|
|
664
|
+
publish('tAxis', list(tAxis), t=C_.trigTime)
|
|
665
|
+
ts = timer()
|
|
666
|
+
try:
|
|
667
|
+
with Threadlock:
|
|
668
|
+
bin_wave = C_.scope.query_binary_values('curve?',
|
|
669
|
+
datatype='h', is_big_endian=bigEndian,
|
|
670
|
+
container=np.array)
|
|
671
|
+
except Exception as e:
|
|
672
|
+
printe(f'in query_binary_values: {e}')
|
|
673
|
+
break
|
|
674
|
+
ElapsedTime['query_wf'] -= timer() - ts
|
|
675
|
+
#printv(f'bin_wave: {bin_wave}')
|
|
676
|
+
wfmax = float(bin_wave.max())
|
|
677
|
+
wfmin = float(bin_wave.min())
|
|
678
|
+
v = bin_wave*ymult + yzero
|
|
679
|
+
v = v/vPerDiv
|
|
680
|
+
|
|
681
|
+
ts = timer()
|
|
682
|
+
publish(f'c{ch[2]}Waveform', v, t=C_.trigTime)
|
|
683
|
+
publish(f'c{ch[2]}VoltsPerDiv', vPerDiv, t=C_.trigtime)
|
|
684
|
+
try:
|
|
685
|
+
publish(f'c{ch[2]}Peak2Peak',
|
|
686
|
+
(wfmax - wfmin)*ymult,
|
|
687
|
+
t = C_.trigtime)
|
|
688
|
+
except Exception as e:
|
|
689
|
+
printe(f'Exception updating Peak2Peak {e}')
|
|
690
|
+
#print(f'{wfmax,wfmin,preambleMap}')
|
|
691
|
+
ElapsedTime['publish_wf'] -= timer() - ts
|
|
692
|
+
ElapsedTime['acquire_wf'] -= timer()
|
|
693
|
+
|
|
694
|
+
#````````````````````````````Decoding of the waveform preamble````````````````
|
|
695
|
+
#typical preamble:
|
|
696
|
+
#2;16;BINARY;RI;INTEGER;LSB;"Ch1, DC coupling, 500.0mV/div, 1.000us/div, 1250 points, Sample mode";1250;Y;LINEAR;"s";8.0E-9;4.7950E-9;505;"V";78.1250E-6;0.0E+0;1.9400;TIME;ANALOG
|
|
697
|
+
#The element names of the wafeform preamble reported by WFMOutpre command
|
|
698
|
+
PreambleKeys = (
|
|
699
|
+
'BYT_NR; BIT_NR; ENCdg; BN_Fmt; integer; BYT_Or; WFID; NR_PT;'
|
|
700
|
+
'PT_FMT; PT_ORDER; XUNIT; XINCR; XZERO; PT_OFF; YUNIT; YMULT; YOFF; YZERO')
|
|
701
|
+
#Note, the integer field is not documented
|
|
702
|
+
PreambleKeys = PreambleKeys.replace(' ','').split(';')
|
|
703
|
+
def decode_preamble(preamble):
|
|
704
|
+
"""Decode the waveform preamble"""
|
|
705
|
+
tokens = preamble.replace('"','').split(';')
|
|
706
|
+
try:
|
|
707
|
+
preambleMap = {key:v for key,v in zip(PreambleKeys,tokens)}
|
|
708
|
+
wfid = preambleMap['WFID']
|
|
709
|
+
voltsPerDivTxt = wfid.split(',')[2].lstrip()
|
|
710
|
+
_,number,vPerDiv = re.split(r'(-?\d*\.?\d+)',
|
|
711
|
+
voltsPerDivTxt)
|
|
712
|
+
try:
|
|
713
|
+
g = {'m':0.001, 'u':0.000001}[vPerDiv[0]]
|
|
714
|
+
except:
|
|
715
|
+
g = 1.
|
|
716
|
+
voltsPerDiv = float(number)*g
|
|
717
|
+
preambleMap['V/DIV'] = voltsPerDiv
|
|
718
|
+
printv(f'preambleMap: {preambleMap}')
|
|
719
|
+
except Exception as e:
|
|
720
|
+
printw(f'wrong preamble: {preamble}: {e}')
|
|
721
|
+
return None
|
|
722
|
+
return preambleMap
|
|
723
|
+
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pvplot"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Andrey Sukhanov", email="sukhanov@bnl.gov" },
|
|
10
|
+
]
|
|
11
|
+
description = "EPICS PVAccess server for Tektronix MSO oscilloscopes"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"p4p",
|
|
21
|
+
]
|
|
22
|
+
[project.urls]
|
|
23
|
+
"Homepage" = "https://github.com/ASukhanov/epicsDevTektronixMSO"
|
|
24
|
+
"Bug Tracker" = "https://github.com/ASukhanov/epicsDevTektronixMSO/issues"
|