Beispiel #1
0
    def search_bus(self, broadcast=False):
        """ Initialize bus with broadcast on or off and find the devices from the bus

        """
        addrs = self.unused_addresses()
        i = self.get_interface()
        i.send(gear.Terminate())
        i.send(gear.Initialise(broadcast=broadcast, address=None))
        i.send(gear.Randomise())
        # Randomise may take up to 100ms
        time.sleep(0.1)
        low = 0
        high = 0xffffff
        while low is not None:
            low = self.find_next(low, high)
            if low is not None:
                if addrs:
                    new_addr = addrs.pop(0)
                    i.send(gear.ProgramShortAddress(new_addr))
                    r = i.send(gear.VerifyShortAddress(new_addr))
                    if r.value is not True:
                        print(f"Error in programming short address {new_addr}")
                    i.send(gear.Withdraw())
                    Device(address=new_addr, randomAddress=low, bus=self)
                else:
                    i.send(gear.Terminate())
                    print("No free address")
                low = low + 1
        i.send(gear.Terminate())
Beispiel #2
0
 def assign_short_addresses(self):
     """Search for devices on the bus with no short address allocated, and
     allocate each one a short address from the set of unused
     addresses.
     """
     if not self._bus_scanned:
         self.scan()
     addrs = self.unused_addresses()
     i = self.get_interface()
     i.send(gear.Terminate())
     i.send(gear.Initialise(broadcast=False, address=None))
     i.send(gear.Randomise())
     # Randomise may take up to 100ms
     time.sleep(0.1)
     low = 0
     high = 0xffffff
     while low is not None:
         low = self.find_next(low, high)
         if low is not None:
             if addrs:
                 new_addr = addrs.pop(0)
                 i.send(gear.ProgramShortAddress(new_addr))
                 r = i.send(gear.VerifyShortAddress(new_addr))
                 if r.value is not True:
                     raise ProgramShortAddressFailure(new_addr)
                 i.send(gear.Withdraw())
                 device.Device(address=new_addr, bus=self)
             else:
                 i.send(gear.Terminate())
                 raise NoFreeAddress
             low = low + 1
     i.send(gear.Terminate())