Ejemplo n.º 1
0
    async def _connect_to_hardware(self):
        """Connect to each port from the config.

        This process will cause the connection threads to figure out which processor they've connected to
        and to register themselves.
        """
        ports = None
        if self.config['ports'][0] == "autodetect":
            devices = [port.device for port in serial.tools.list_ports.comports()]
            # Look for four devices with sequential tails of 0-3 or A-D
            seqs = (("0", "1", "2", "3"), ("A", "B", "C", "D"))
            for d in devices:
                for seq in seqs:
                    if d[-1] == seq[0]:
                        root = d[:-1]
                        if "{}{}".format(root, seq[1]) in devices and \
                           "{}{}".format(root, seq[2]) in devices and \
                           "{}{}".format(root, seq[3]) in devices:
                            ports = ("{}{}".format(root, seq[1]), "{}{}".format(root, seq[2]))
                            self.debug_log("Autodetect found ports! {}".format(ports))
                            break
                # If ports were found, skip the rest of the devices
                if ports:
                    break
            if not ports:
                raise RuntimeError("Unable to auto-detect FAST hardware from available devices: {}".format(
                                   ", ".join(devices)))
        else:
            ports = self.config['ports']

        for port in ports:
            comm = FastSerialCommunicator(platform=self, port=port,
                                          baud=self.config['baud'])
            await comm.connect()
            self.serial_connections.add(comm)
Ejemplo n.º 2
0
    async def _connect_to_hardware(self):
        """Connect to each port from the config.

        This process will cause the connection threads to figure out which processor they've connected to
        and to register themselves.
        """
        ports = None
        if self.config['ports'][0] == "autodetect":
            devices = [
                port.device for port in serial.tools.list_ports.comports()
            ]
            # Look for four devices with sequential tails of 0-3 or A-D
            seqs = (("0", "1", "2", "3"), ("A", "B", "C", "D"))
            for d in devices:
                for seq in seqs:
                    if d[-1] == seq[0]:
                        root = d[:-1]
                        if "{}{}".format(root, seq[1]) in devices and \
                           "{}{}".format(root, seq[2]) in devices and \
                           "{}{}".format(root, seq[3]) in devices:
                            ports = ("{}{}".format(root, seq[1]),
                                     "{}{}".format(root, seq[2]))
                            self.debug_log(
                                "Autodetect found ports! {}".format(ports))
                            break
                # If ports were found, skip the rest of the devices
                if ports:
                    break
            if not ports:
                raise MpfRuntimeError(
                    "Unable to auto-detect FAST hardware from available devices: {}"
                    .format(", ".join(devices)), 2, self.log.name)
        else:
            ports = self.config['ports']

        bauds = self.config['baud']
        if len(bauds) == 1:
            bauds = [bauds[0]] * len(ports)
        elif len(bauds) != len(ports):
            raise AssertionError(
                "FAST configuration found {} ports and {} baud rates".format(
                    len(ports), len(bauds)))

        for index, port in enumerate(ports):
            comm = FastSerialCommunicator(platform=self,
                                          port=port,
                                          baud=bauds[index])
            try:
                await comm.connect()
            except SerialException as e:
                raise MpfRuntimeError(
                    "Could not open serial port {}. Check if you configured the correct port in the "
                    "fast config section and if you got sufficient permissions to that "
                    "port".format(port), 1, self.log.name) from e
            self.serial_connections.add(comm)
Ejemplo n.º 3
0
    def _connect_to_hardware(self):
        """Connect to each port from the config.

        This process will cause the connection threads to figure out which processor they've connected to
        and to register themselves.
        """
        for port in self.config['ports']:
            comm = FastSerialCommunicator(platform=self, port=port,
                                          baud=self.config['baud'])
            yield from comm.connect()
            self.serial_connections.add(comm)