def setSync(self, syncMode): if self.active: p = snap.SNAPPacket(serialPort, self.address, snap.localAddress, 0, 1, [CMD_SYNC, int(syncMode)]) if p.send(): return True return False
def setNotify(self): #global serialPort if self.active: p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_NOTIFY, snap.localAddress] ) # set notifications to be sent to host if p.send(): return True return False
def backward(self, speed): if self.active: p = snap.SNAPPacket(serialPort, self.address, snap.localAddress, 0, 1, [CMD_REVERSE, int(speed)]) if p.send(): return True return False
def free(self): if self.active: p = snap.SNAPPacket(serialPort, self.address, snap.localAddress, 0, 1, [CMD_FREE]) if p.send(): return True return False
def backward1(self): if self.active: p = snap.SNAPPacket(serialPort, self.address, snap.localAddress, 0, 1, [CMD_BACKWARD1]) if p.send(): return True return False
def setCooler(self, speed): if self.active: p = snap.SNAPPacket(serialPort, self.address, snap.localAddress, 0, 1, [CMD_SETCOOLER, int(speed)]) if p.send(): return True return False
def setVoltateReference(self, val): if self.active: p = snap.SNAPPacket(serialPort, self.address, snap.localAddress, 0, 1, [CMD_SETVREF, int(val)]) if p.send(): return True return False
def setPos(self, pos): if self.active: posMSB ,posLSB = int2bytes( pos ) p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_SETPOS, posMSB, posLSB] ) if p.send(): return True return False
def scanNetwork(): devices = [] for remoteAddress in range( 1, 10): # For every address in range. full range will be 255 print "Trying address " + str(remoteAddress) p = snap.SNAPPacket( serialPort, remoteAddress, snap.localAddress, 0, 1, [CMD_GETMODULETYPE]) # Create snap packet requesting module type #p = snap.SNAPPacket( serialPort, remoteAddress, snap.localAddress, 0, 1, [CMD_VERSION] ) if p.send(): # Send snap packet, if sent ok then await reply rep = p.getReply() if rep: #devices[ rep.dataBytes[1] ] = remoteAddress devices.append({ 'address': remoteAddress, 'type': rep.dataBytes[1], 'subType': rep.dataBytes[2] }) # If device replies then add to device list. else: "print na" else: print "scan no ack" time.sleep(0.5) for d in devices: #now get versions print "device", d
def setHeat(self, lowHeat, highHeat, tempTarget, tempMax): if self.active: tempTargetMSB, tempTargetLSB = int2bytes( tempTarget ) tempMaxMSB ,tempMaxLSB = int2bytes( tempMax ) p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_SETHEAT, int(lowHeat), int(highHeat), tempTargetMSB, tempTargetLSB, tempMaxMSB, tempMaxLSB] ) # assumes MSB first (don't know this!) if p.send(): return True return False
def getSensors(self): if self.active: p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_GETSENSOR] ) if p.send(): rep = p.getReply() data = checkReplyPacket( rep, 3, CMD_GETSENSOR ) # replace this with a proper object in SNAP module? if data: print data[1], data[2] return False
def getTemp(self): if self.active: p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_GETTEMP] ) if p.send(): rep = p.getReply() data = checkReplyPacket( rep, 2, CMD_GETTEMP ) if data: return data[1] return False
def setMotor(self, direction, speed): if self.active: p = snap.SNAPPacket(serialPort, self.address, snap.localAddress, 0, 1, [int(direction), int(speed) ]) ##no command being sent, whats going on? if p.send(): return True return False
def getModuleType(self): #note: do pics not support this yet? I can't see it in code and get no reply from pic if self.active: p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_GETMODULETYPE] ) # Create SNAP packet requesting module type if p.send(): rep = p.getReply() data = checkReplyPacket( rep, 2, CMD_GETMODULETYPE ) # If packet sent ok and was acknoledged then await reply, otherwise return False if data: return data[1] # If valid reply is recieved then return it, otherwise return False return False
def setPower(self, power): if self.active: p = snap.SNAPPacket(serialPort, self.address, snap.localAddress, 0, 1, [CMD_SETPOWER, int(power * 0.63) ]) # This is a value from 0 to 63 (6 bits) if p.send(): return True return False
def getVersion(self): if self.active: p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_VERSION] ) if p.send(): rep = p.getReply() data = checkReplyPacket( rep, 3, CMD_VERSION ) if data: return data[1], data[2] return False
def getPos(self): if self.active: p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_GETPOS] ) if p.send(): rep = p.getReply() data = checkReplyPacket( rep, 3, CMD_GETPOS ) if data: pos = bytes2int( data[1], data[2] ) return pos # return value return False
def DDA( self, speed, seekTo, slaveDelta, waitArrival = True): if self.active and seekTo <= self.limit: masterPosMSB, masterPosLSB = int2bytes( seekTo ) slaveDeltaMSB, slaveDeltaLSB = int2bytes( slaveDelta ) p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_DDA, int(speed), masterPosMSB ,masterPosLSB, slaveDeltaMSB, slaveDeltaLSB] ) #start sync if p.send(): if waitArrival: notif = getNotification( serialPort ) if notif.dataBytes[0] == CMD_DDA: if printDebug: print " valid notification for DDA" # todo: add actual enforement on wrong notification else: return False return True return False
def homeReset(self, speed, waitArrival = True): if self.active: p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_HOMERESET, int(speed)] ) if p.send(): if waitArrival: if printDebug: print "reset wait" notif = getNotification( serialPort ) if notif.dataBytes[0] == CMD_HOMERESET: if printDebug: print " valid notification for reset" else: return False if printDebug: print "reset done" return True return False
def seek(self, pos, speed, waitArrival = True): if self.active and pos <= self.limit: posMSB ,posLSB = int2bytes( pos ) p = snap.SNAPPacket( serialPort, self.address, snap.localAddress, 0, 1, [CMD_SEEK, int(speed), posMSB ,posLSB] ) if p.send(): if waitArrival: if printDebug: print " wait notify" notif = getNotification( serialPort ) if notif.dataBytes[0] == CMD_SEEK: if printDebug: print " valid notification for seek" else: return False if printDebug: print " rec notif" return True return False