def __init__(self, threshold, mode=MNRLDefs.HIGH_ON_THRESHOLD, id=None, report=False, reportId=None, attributes={}): #validate that the threshold is a non-negative int if not (isinstance(threshold, int) and threshold >= 0): raise mnrlerror.UpCounterThresholdError(threshold) #validate mode if mode not in [ MNRLDefs.TRIGGER_ON_THRESHOLD, MNRLDefs.HIGH_ON_THRESHOLD, MNRLDefs.ROLLOVER_ON_THRESHOLD ]: raise mnrlerror.UpCounterModeError(mode) super(UpCounter, self).__init__( id=id, enable=MNRLDefs. ENABLE_ON_START_AND_ACTIVATE_IN, #a counter is always active report=report, reportEnable=reportEnable, inputDefs=[(MNRLDefs.UP_COUNTER_COUNT, 1), (MNRLDefs.UP_COUNTER_RESET, 1)], outputDefs=[(MNRLDefs.UP_COUNTER_OUTPUT, 1)], attributes=attributes) self.reportId = reportId self.threshold = threshold self.mode = mode
def toMNRLCounterMode(m): if m == MNRLDefs.TRIGGER_ON_THRESHOLD: return "trigger" elif m == MNRLDefs.HIGH_ON_THRESHOLD: return "high" elif m == MNRLDefs.ROLLOVER_ON_THRESHOLD: return "rollover" else: raise mnrlerror.UpCounterModeError(m)
def fromMNRLCounterMode(m): if m == "trigger": return MNRLDefs.TRIGGER_ON_THRESHOLD elif m == "high": return MNRLDefs.HIGH_ON_THRESHOLD elif m == "rollover": return MNRLDefs.ROLLOVER_ON_THRESHOLD else: raise mnrlerror.UpCounterModeError(m)