def getDwell(self, idx): """ Retrieve one of the dwell values. These are measured in seconds. """ WbDefs.checkRange(idx, 0, WbDefs.DWELLCOUNT) nodeList = self.dom.getElementsByTagName("CW") return int(getElemText(nodeList[idx]))
def getScene(self, idx): """ Retrieve a dictionary defining the configuration of a scene. """ WbDefs.checkRange(idx, 0, WbDefs.SCENECOUNT) result = dict() # empty dictionary nodeList = self.dom.getElementsByTagName("CC") node = nodeList[idx] Dm = int(node.attributes["Dm"].value) Ds = int(node.attributes["Ds"].value) Am = int(node.attributes["Am"].value) Av = int(node.attributes["Av"].value) for i in range(8): if ( ( Dm & ( 1 << i) ) != 0 ): if ( ( Ds & ( 1 << i) ) != 0 ): result["Digital"+str(i)] = "On" else: result["Digital"+str(i)] = "Off" else: result["Digital"+str(i)] = "Ignore" for i in range(4): if ( ( Am & ( 1 << i) ) != 0 ): result["Analogue"+str(i)] = "SetPoint"+str(Av & 0x0F) else: result["Analogue"+str(i)] = "Ignore" Av >>= 4 return result
def getSetPoint(self,idx): """ Retrieve one of the set points, these are a number between 0 and 100 (%) """ WbDefs.checkRange(idx, 0, WbDefs.SPCOUNT) nodeList = self.dom.getElementsByTagName("CS") return int(getElemText(nodeList[idx]))
def getRotary(self, idx): """ Retrieve a rotary encoder step value. The current webbrick only supports a single encoder that connects to analog output zero. """ WbDefs.checkRange(idx, 0, WbDefs.ROTARYCOUNT) return self.RotaryStep[idx]
def getAnalogOutMimic(self, idx): """ Retrieve the mimic output channel number for an analog output channel, or -1 if no mimic is defined for the specified channel. """ WbDefs.checkRange(idx, 0, WbDefs.AOCOUNT) return self.MimicMapAnalog[idx]
def setDigOutMimic(self, idx, val): """ Set the mimic output channel number for an analog output channel, or -1 if no mimic is defined for the specified channel. """ WbDefs.checkRange(idx, 0, WbDefs.DOCOUNT) self.MimicMapDigital[idx] = val
def ConfigTemp(self, iChn, thType, thVal, tgtType, tgtIdx, action, sp, dwell, udpType, associatedValue, reserved = None ): """ """ WbDefs.checkRange(iChn, 0, WbDefs.TEMPCOUNT) WbDefs.checkRange(thVal, -50, 125) # CTchn;[L|H]Val;Trigger cmd = "CT%i;%s%1.1f%s" % ( iChn, thType, thVal, self._CreateTriggerString(tgtType, tgtIdx, action, sp, dwell, udpType, associatedValue, reserved ) ) self.Send( cmd )
def getRotary(self, idx): """ Retrieve a rotary encoder step value, the current webbrick only supports a single encoder that connects to analog output zero. """ WbDefs.checkRange(idx, 0, WbDefs.ROTARYCOUNT) nodeList = self.dom.getElementsByTagName("SR") s = nodeList[idx].attributes["Value"].value return int(s)
def setSceneAlt(self, idx, val): """ Set a scene configuration using an alternative interface: Dictionary entries are of the form: ["Digital"] = List of 8 values, each "On", "Off" or None ["Analog"] = List of 4 values, each None or an integer set point number """ WbDefs.checkRange(idx, 0, WbDefs.SCENECOUNT) self.Scene[idx] = val
def getSceneAlt(self, idx): """ Alternative scene configuration. Dictionary entries are of the form: ["Digital"] = List of 8 values, each "On", "Off" or None ["Analog"] = List of 4 values, each None or an integer set point number """ WbDefs.checkRange(idx, 0, WbDefs.SCENECOUNT) return self.Scene[idx]
def getDwellStr(self,idx): """ Retrieve one of the dwell values as a user displayable string """ WbDefs.checkRange(idx, 0, WbDefs.DWELLCOUNT) dw = self.getDwell(idx) if (dw<=60): return u'%s Secs' % dw if (dw<=3600): return u'%i Mins' % round(dw/60) return u'%i Hours' % round(dw/3600)
def setScene(self, idx, val): """ Set a dictionary defining the configuration of a scene. Dictionary entries are of the form: ["Digital<n>"] = ("On"|"Off"|"Ignore") ["Analogue<n>"] = ("SetPoint<m>"|"Ignore") """ ### Currently broke -- consider removing this method ### WbDefs.checkRange(idx, 0, WbDefs.SCENECOUNT) self.Scene[idx] = val
def ConfigTempThreshold(self, iChn, thType, thVal ): """ Configure the threshold for a temperature sensor. This only sets the active value. iChn - channel number thType - a single character identiying the threshold hight or low thVal - The threshold value """ WbDefs.checkRange(iChn, 0, WbDefs.TEMPCOUNT) WbDefs.checkRange(thVal, -50, 125) cmd = "TT%i;%s%1.1f" % ( iChn, thType, thVal ) self.Send( cmd )
def getDigOutMimic(self, idx): """ Retrieve the mimic output channel number for an analog output channel, or -1 if no mimic is defined for the specified channel. """ WbDefs.checkRange(idx, 0, WbDefs.DOCOUNT) dms = getNamedNodeAttrText(self.dom, "MM", "dig") if dms: dm = int(dms) dv = dm >> (idx*4) & 0xF if dv < 8: return dv return -1
def getAnalogOutMimic(self, idx): """ Retrieve the mimic output channel number for an analog output channel, or -1 if no mimic is defined for the specified channel. """ WbDefs.checkRange(idx, 0, WbDefs.AOCOUNT) ams = getNamedNodeAttrText(self.dom, "MM", "an") if ams: am = int(ams) av = am >> (idx*4) & 0xF if av < 8: return av return -1
def getDigInTrigger(self, idx): """ Retrieve a dictionary defining the configuration of a single digital input. """ WbDefs.checkRange(idx, 0, WbDefs.DICOUNT) nodeList = self.dom.getElementsByTagName("CD") if idx >= len(nodeList): return {} # For b/w compatibility - was fewer DIs node = nodeList[idx] result = self._decodeTrigger( node.getElementsByTagName("Trg")[0]) result["name"] = node.attributes["Name"].value result["options"] = int(node.getAttribute("Opt") or "2") ### result["options"] = int(node.attributes["Opt"].value) return result
def getTempTriggerHigh(self, idx): """ Retrieve a dictionary defining the configuration of a temperature high threshold """ WbDefs.checkRange(idx, 0, WbDefs.TEMPCOUNT) nodeList = self.dom.getElementsByTagName("CT") node = nodeList[idx] trg = node.getElementsByTagName("TrgH")[0] result = self._decodeTrigger( trg) result["name"] = node.attributes["Name"].value ta = trg.getAttribute("Val") or trg.getAttribute("Hi") result["threshold"] = float(ta)/16.0 ### result["threshold"] = float(trg.attributes["Hi"].value)/16.0 return result
def getAnalogTriggerHigh(self, idx): """ Retrieve a dictionary defining the configuration of a analog high threshold """ WbDefs.checkRange(idx, 0, WbDefs.AICOUNT) nodeList = self.dom.getElementsByTagName("CI") node = nodeList[idx] trg = node.getElementsByTagName("TrgH")[0] result = self._decodeTrigger( trg) result["name"] = node.attributes["Name"].value ta = trg.getAttribute("Val") or trg.getAttribute("Hi") result["threshold"] = int(ta) ### result["threshold"] = int(trg.attributes["Hi"].value) return result
def getScheduledEvent(self, idx): """ Retrieve a dictionary defining the configuration of a scheduled event """ WbDefs.checkRange(idx, 0, WbDefs.SCHEDCOUNT) nodeList = self.dom.getElementsByTagName("CE") node = nodeList[idx] result = self._decodeTrigger( node.getElementsByTagName("Trg")[0]) result["days"] = int(node.getAttribute("Days")) result["hours"] = int(node.getAttribute("Hours") or node.getAttribute("Hrs")) result["mins"] = int(node.getAttribute("Mins")) ###result["days"] = int(node.attributes["Days"].value) ###result["hours"] = int(node.attributes["Hours"].value) ###result["mins"] = int(node.attributes["Mins"].value) return result
def ConfigAnThreshold(self, iChn, thType, thVal ): """ Configure the threshold for an analogue input. This only sets the active value. iChn - channel number thType - a single character identiying the threshold hight or low thVal - The threshold value """ # CI<chn>;<L|H><val>;<ADS><tgtChn>;<sp>;<actionType>;<dwell>;<udpType>;<associatedValue>: WbDefs.checkRange(iChn, 0, WbDefs.AICOUNT) WbDefs.checkRange(thVal, 0, 256) cmd = "TA%i;%s%i" % ( iChn, thType, thVal ) self.Send( cmd )
def setAnalogTriggerHigh(self, idx, val): """ Set a dictionary defining the configuration of a analog high threshold: ["name"] = Analog input name ["threshold"] = Analog input high threshold value (float) ["actionNr"] = Trigger action code (see WbDefs.AT_NONE, etc.) ["action"] = Trigger action descriptive string ["typeNr"] = Trigger target type code (see WbDefs.TT_DIGITAL, etc.) ["type"] = Trigger target type descriptive string ["UDPRemNr"] = UDP packet type code (see WbDefs.UDPT_NONE, etc.) ["UDPRem"] = UDP packet type descriptive string ["dwell"] = dwell period ["RemNode"] = remote node target for UDP packet ["setPoint"] = Set point number ["pairChn"] = Trigger target analog output, digital output or scene number """ WbDefs.checkRange(idx, 0, WbDefs.AICOUNT) self.AnalogTriggerHigh[idx] = val
def ConfigScene(self, iScene, digOut, anOut ): # CC\param{nr};[NFI][NFI][NFI][NFI][NFI][NFI][NFI][NFI];[I|S\param{nn}];[I|S\param{nn}];[I|S\param{nn}];[I|S\param{nn}]: WbDefs.checkRange(iScene, 0, WbDefs.SCENECOUNT) assert (len(digOut) == WbDefs.DOCOUNT ) assert (len(anOut) == WbDefs.AOCOUNT ) cmd = "CC%i;" % (iScene) for d in digOut: assert d in ["N","F","I"], "Bad digital parameter" cmd = cmd + d for a in anOut: if ( a == "I" ): cmd = "%s;I" % cmd elif (a[0] == "S"): WbDefs.checkRange(a[1], 0, WbDefs.SPCOUNT) cmd = "%s;S%i"% (cmd,a[1]) else: assert False, "Bad analogue parameter" self.Send( cmd )
def ConfigSerial(self, mode, baud): """ Configure the serial port mode=0 no change mode=2 RS232 mode=3 DMX mode=4 RS485 baud=0 300 baud=1 600 baud=2 1200 baud=3 2400 baud=4 4800 baud=5 9600 """ WbDefs.checkRange(mode, 0, 5) WbDefs.checkRange(baud, 0, 6) self.Send("CR%i;%i" % (mode,baud))
def setDigInTrigger(self, idx, val): """ Set a dictionary with the configuration of a single digital input: ["name"] = Digital input name ["options"] = Digital input configuration options ["actionNr"] = Trigger action code (see WbDefs.AT_NONE, etc.) ["action"] = Trigger action descriptive string ["typeNr"] = Trigger target type code (see WbDefs.TT_DIGITAL, etc.) ["type"] = Trigger target type descriptive string ["UDPRemNr"] = UDP packet type code (see WbDefs.UDPT_NONE, etc.) ["UDPRem"] = UDP packet type descriptive string ["dwell"] = dwell period ["RemNode"] = remote node target for UDP packet ["setPoint"] = Set point number ["pairChn"] = Trigger target analog output, digital output or scene number """ WbDefs.checkRange(idx, 0, WbDefs.DICOUNT) self.DigInTrigger[idx] = val
def getScheduledEvent(self, idx): """ Retrieve a dictionary defining the configuration of a scheduled event ["days"] = (Mask) days-of-week on which the scheduled event occurs ["hours"] = (Int) hour-of-day on which the scheduled event occurs ["mins"] = (Int) minute-of-hour on which the scheduled event occurs ["actionNr"] = Trigger action code (see WbDefs.AT_NONE, etc.) ["action"] = Trigger action descriptive string ["typeNr"] = Trigger target type code (see WbDefs.TT_DIGITAL, etc.) ["type"] = Trigger target type descriptive string ["UDPRemNr"] = UDP packet type code (see WbDefs.UDPT_NONE, etc.) ["UDPRem"] = UDP packet type descriptive string ["dwell"] = dwell period ["RemNode"] = remote node target for UDP packet ["setPoint"] = Set point number ["pairChn"] = Trigger ta """ WbDefs.checkRange(idx, 0, WbDefs.SCHEDCOUNT) return self.ScheduledEvent[idx]
def ConfigAnIn(self, iChn, thType, thVal, tgtType, tgtIdx, action, sp, dwell, udpType, associatedValue, reserved = None ): """ Configure the trigger action for a analog input, the later two parameters are optional at present. iChn - channel number tgtType - a single character identiying the target type tgtIdx - the index/channel number of tgtType sp - setpoint if relevant. dwell - if relevant udpType - control whether UDP packet sent and what type. associatedValue - an action/udpType value. """ # CI<chn>;<L|H><val>;<ADS><tgtChn>;<sp>;<actionType>;<dwell>;<udpType>;<associatedValue>: WbDefs.checkRange(iChn, 0, WbDefs.AICOUNT) WbDefs.checkRange(thVal, 0, 256) trg = self._CreateTriggerString(tgtType, tgtIdx, action, sp, dwell, udpType, associatedValue, reserved ) cmd = "CI%i;%s%i%s"%(iChn, thType, thVal, trg) self.Send( cmd )
def getAnalogTriggerLow(self, idx): """ Retrieve a dictionary defining the configuration of a analog low threshold The result returned has the following values: ["name"] = Analog input name ["threshold"] = Analog input low threshold value (float) ["actionNr"] = Trigger action code (see WbDefs.AT_NONE, etc.) ["action"] = Trigger action descriptive string ["typeNr"] = Trigger target type code (see WbDefs.TT_DIGITAL, etc.) ["type"] = Trigger target type descriptive string ["UDPRemNr"] = UDP packet type code (see WbDefs.UDPT_NONE, etc.) ["UDPRem"] = UDP packet type descriptive string ["dwell"] = dwell period ["RemNode"] = remote node target for UDP packet ["setPoint"] = Set point number ["pairChn"] = Trigger target analog output, digital output or scene number """ WbDefs.checkRange(idx, 0, WbDefs.AICOUNT) return self.AnalogTriggerLow[idx]
def getSceneAlt(self, idx): """ Retrieve an alternative dictionary defining the configuration of a scene. """ WbDefs.checkRange(idx, 0, WbDefs.SCENECOUNT) nodeList = self.dom.getElementsByTagName("CC") dscene = [None for i in range(8)] ascene = [None for i in range(4)] if idx < len(nodeList): # For b/w compatibility - was fewer scenes node = nodeList[idx] Dm = int(node.attributes["Dm"].value) Ds = int(node.attributes["Ds"].value) Am = int(node.attributes["Am"].value) Av = int(node.attributes["Av"].value) for i in range(8): if ( ( Dm & ( 1 << i) ) != 0 ): dscene[i] = ( ( Ds & ( 1 << i) ) != 0 ) for i in range(4): if ( ( Am & ( 1 << i) ) != 0 ): ascene[i] = Av & 0x0F Av >>= 4 return { "Digital": dscene, "Analog": ascene }
def SetTime(self, day, hr, min): """ Update the webbrick clock. """ WbDefs.checkRange(day,0,7) WbDefs.checkRange(hr,0,24) WbDefs.checkRange(min,0,60) SendHTTPCmd(self._wbAddress,"ST" + str(day) + ";" + str(hr) + ";" + str(min) )
def ConfigScheduled(self, iEv, days, hour, min, tgtType, tgtIdx, action, sp, dwell, udpType, associatedValue, reserved = None ): # CE<num>;<Days>;<Hours>;<Mins>;<ADS><tgtChn>;<sp>;<actionType>;<dwell>;<udpType>;<nodeNr>;<val>: WbDefs.checkRange(iEv, 0, WbDefs.SCHEDCOUNT) WbDefs.checkRange(hour, 0, 24) WbDefs.checkRange(min, 0, 60) cmd = "CE%i;%s;%i;%i%s" % ( iEv, days, hour, min, self._CreateTriggerString(tgtType, tgtIdx, action, sp, dwell, udpType, associatedValue, reserved ) ) self.Send( cmd )