def initialize_usb_sync(self,
                            port=None,
                            baudrate=230400,
                            writeChunkMaxSize=0):
        '''
                writing in chunks solves issues writing to certain JLink chips. A max chunkSize of 64 was found to work well for our case.
                For normal usage with Crownstones this is not required.
                writeChunkMaxSize of 0 will not send the payload in chunks
                :param port:
                :param baudrate:
                :param writeChunkMaxSize:
                :return:
                '''
        self.uartManager.config(port, baudrate, writeChunkMaxSize)

        result = [False]

        def handleMessage(result, data):
            result[0] = True

        event = UartEventBus.subscribe(
            SystemTopics.connectionEstablished,
            lambda data: handleMessage(result, data))
        self.uartManager.start()

        try:
            while not result[0] and self.running:
                time.sleep(0.1)
        except KeyboardInterrupt:
            print("\nClosing Crownstone Uart.... Thanks for your time!")
            self.stop()

        UartEventBus.unsubscribe(event)
    def __init__(self, dataToSend: List[int], interval = 0.001):
        """
        This class will handle the event flow around writing to uart and receiving errors or result codes.
        :param dataToSend: This is your data packet
        :param interval: Polling interval. Don't touch. This is cheap and local only. It does not do uart things.
        """
        self.dataToSend : List[int] = dataToSend
        self.interval = interval

        self.error   = None
        self.success = False
        self.result  = None

        self.cleanupIds = []
        self.cleanupIds.append(UartEventBus.subscribe(SystemTopics.resultPacket,     self._handleResult))
        self.cleanupIds.append(UartEventBus.subscribe(SystemTopics.uartWriteSuccess, self._handleSuccess))
        self.cleanupIds.append(UartEventBus.subscribe(SystemTopics.uartWriteError,   self._handleError))
    def __init__(self, topic=None, timeout=10, interval=0.05):
        self.response = None
        self.timeout = timeout
        self.interval = interval

        self.cleanupId = None
        if topic is not None:
            self.cleanupId = UartEventBus.subscribe(topic, self.collect)
    def __init__(self, port, baudrate, writeChunkMaxSize=0):
        self.baudrate = baudrate
        self.port = port
        self.writeChunkMaxSize = writeChunkMaxSize

        self.serialController = None
        self.started = False

        self.running = True
        self.parser = UartParser()
        self.eventId = UartEventBus.subscribe(SystemTopics.uartWriteData, self.write_to_uart)
        threading.Thread.__init__(self)
Beispiel #5
0
    def __init__(self):
        self.port = None  # Port configured by user.
        self.baudRate = 230400
        self.writeChunkMaxSize = 0
        self.running = True
        self.loop = None
        self._availablePorts = list(list_ports.comports())
        self._attemptingIndex = 0
        self._uartBridge = None
        self.ready = False
        self.eventId = UartEventBus.subscribe(SystemTopics.connectionClosed,
                                              self.resetEvent)

        threading.Thread.__init__(self)
Beispiel #6
0
    def initialize_usb_sync(self,
                            port=None,
                            baudrate=230400,
                            writeChunkMaxSize=0):
        """
        Initialize a Crownstone serial device. 
            
        :param port: serial port of the USB. e.g. '/dev/ttyUSB0' or 'COM3'.
        :param baudrate: baudrate that should be used for this connection. default is 230400.
        :param writeChunkMaxSize: writing in chunks solves issues writing to certain JLink chips. A max chunkSize of 64 was found to work well for our case.
            For normal usage with Crownstones this is not required. a writeChunkMaxSize of 0 will not send the payload in chunks.
        """
        self.uartManager.config(port, baudrate, writeChunkMaxSize)

        result = [False]

        def handleMessage(result, data):
            result[0] = True

        event = UartEventBus.subscribe(
            SystemTopics.connectionEstablished,
            lambda data: handleMessage(result, data))
        self.uartManager.start()

        try:
            while not result[0] and self.running:
                try:
                    exc = self.manager_exception_queue.get(block=False)
                    self.uartManager.join()
                    self.stop()
                    raise exc[0](exc[1])
                except queue.Empty:
                    pass

                time.sleep(0.1)

        except KeyboardInterrupt:
            print("\nClosing Crownstone Uart.... Thanks for your time!")
            self.stop()

        UartEventBus.unsubscribe(event)
Beispiel #7
0
 def __init__(self):
     self.stones = {}
     UartEventBus.subscribe(SystemTopics.stateUpdate,
                            self.handleStateUpdate)
Beispiel #8
0
 def __init__(self):
     self.stones = {}
     self.stateManager = StoneStateManager()
     UartEventBus.subscribe(SystemTopics.newCrownstoneFound,
                            self.handleNewStoneFromScan)
 def __init__(self):
     self.uartPackageSubscription = UartEventBus.subscribe(
         SystemTopics.uartNewPackage, self.parse)
     self.uartMessageSubscription = UartEventBus.subscribe(
         SystemTopics.uartNewMessage, self.handleUartMessage)
     self.timestampFormat = "%Y-%m-%d %H:%M:%S.%f"