Repository navigation
Expand file tree
/
Copy pathSamplingStepBase.py
More file actions
56 lines (48 loc) · 2.04 KB
/
Copy pathSamplingStepBase.py
File metadata and controls
56 lines (48 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Sampling parent step for the power analyzer example.
Note that the step defined here in is supposed to be the base class for other test steps.
"""
import sys
import math
import opentap
from opentap import *
import System
from System import Double #Import types to reference for generic methods
from System.ComponentModel import BrowsableAttribute
from OpenTap import DisplayAttribute, UnitAttribute
from .PowerAnalyzer import PowerAnalyzer
import threading
@attribute(DisplayAttribute, "SamplingStepBase", "An example of a base class for a TestStep", "Python Example")
class SamplingStepBase(TestStep):
__clr_abstract__ = True #class marked 'abstract' as it should not be used without inheritance
MeasurementInterval = property(Double, 0.2)\
.add_attribute(UnitAttribute, "s")\
.add_attribute(DisplayAttribute, "Measure Interval", "The time between measurements", "Measurements", -50)
PowerAnalyzer = property(PowerAnalyzer, None)\
.add_attribute(DisplayAttribute, "Power Analyzer", "", "Resources", -100)
def __init__(self):
super(SamplingStepBase, self).__init__() # The base class initializer must be invoked.
self._sampleNo = 0
def Run(self):
running = True
def timer_Elapsed():
if running == False:
return
voltage = self.PowerAnalyzer.MeasureVoltage()
current = self.PowerAnalyzer.MeasureCurrent()
self.OnSample(voltage, current, self._sampleNo)
self._sampleNo = self._sampleNo + 1
threading.Timer(self.MeasurementInterval, timer_Elapsed).start()
self._sampleNo = 0
timer_Elapsed()
try:
# Sleep, while the timer thread generates data.
# Will stop when the charge/discharge gets within margin
self.WhileSampling()
self.RunChildSteps(); # If step has child steps.
finally:
running = False
def WhileSampling(self):
pass
def OnSample(self, voltage, current, sampleNo):
pass