-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMeasureDutyCycleStep.py
33 lines (24 loc) · 1.26 KB
/
MeasureDutyCycleStep.py
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
from OpenTap import Display, Unit, Verdict
from System import Double
from opentap import *
from .LogicAnalyzer import *
@attribute(
Display("Measure Duty Cycle", "Measures the duty cycle and period (in ms)",
Groups=["PSLab", "Logic Analyzer"]))
class MeasureDutyCycleStep(TestStep):
# Properties
channel = property(DigitalPin, DigitalPin.LA1) \
.add_attribute(Display("Channel", "Name of digital channel to listen on", "Measurements", -50))
timeout = property(Double, 1) \
.add_attribute(Display("Timeout", "Timeout before cancelling measurement", "Measurements", -40)) \
.add_attribute(Unit("s"))
LogicAnalyzer = property(LogicAnalyzer, None) \
.add_attribute(Display("Logic Analyzer", "", "Resources", 0))
def __init__(self):
super(MeasureDutyCycleStep, self).__init__()
self.Rules.Add(Rule("timeout", lambda: self.timeout >= 0, lambda: 'Timeout must not be negative.'))
def Run(self):
super().Run() # 3.0: Required for debugging to work.
period, duty_cycle = self.LogicAnalyzer.measure_duty_cycle(self.channel, self.timeout)
self.PublishResult("Measured Duty Cycle", ["Period (ms)", "Duty Cycle"], [period, duty_cycle])
self.UpgradeVerdict(Verdict.Pass)