Public: Make connection to Arduino.

 Returns Firmata::Board board.
184160
def connect
      unless @connected
        once('report_version', ->() do
          once('firmware_query', ->() do
            once('capability_query', ->() do
              once('analog_mapping_query', ->() do

                2.times { |i| toggle_pin_reporting(i) }

                @connected = true
                emit('ready')
              end)
              query_analog_mapping
           end)
            query_capabilities
          end)
        end)

         until connected?
          read_and_process
          delay(0.5)
        end
      end

      self
    end
1095831
def get_serial():
    
    port, serial_number = find_microbit()
    if port is None:
        raise IOError('Could not find micro:bit.')
    return Serial(port, SERIAL_BAUD_RATE, timeout=1, parity='N')
1289045
private Optional<String> getArduinoPathWithDialog() {
        String savedPath = Preferences.userNodeForPackage(ArduinoLibraryInstaller.class)
                .get(ARDUINO_CUSTOM_PATH, homeDirectory);

        Path libsPath = Paths.get(savedPath, "libraries");
        if (Files.exists(libsPath)) return Optional.of(savedPath);

        TextInputDialog dialog = new TextInputDialog(savedPath);
        dialog.setTitle("Manually enter Arduino Path");
        dialog.setHeaderText("Please manually enter the full path to the Arduino folder");
        dialog.setContentText("Arduino Path");
        Optional<String> path = dialog.showAndWait();
        path.ifPresent((p) -> Preferences.userNodeForPackage(ArduinoLibraryInstaller.class).put(ARDUINO_CUSTOM_PATH, p));
        return path;
    }
928667
function Board(options) {
    EventEmitter.call(this);

    this._options = options;
    this._buf = [];
    this._digitalPort = [];
    this._numPorts = 0;
    this._analogPinMapping = [];
    this._digitalPinMapping = [];
    this._i2cPins = [];
    this._ioPins = [];
    this._totalPins = 0;
    this._totalAnalogPins = 0;
    this._samplingInterval = 19;
    this._isReady = false;
    this._firmwareName = '';
    this._firmwareVersion = 0;
    this._capabilityQueryResponseReceived = false;
    this._numPinStateRequests = 0;
    this._numDigitalPortReportRequests = 0;
    this._transport = null;
    this._pinStateEventCenter = new EventEmitter();
    this._logger = new Logger('Board');

    this._initialVersionResultHandler = onInitialVersionResult.bind(this);
    this._openHandler = onOpen.bind(this);
    this._reOpenHandler = onReOpen.bind(this);
    this._messageHandler = onMessage.bind(this);
    this._errorHandler = onError.bind(this);
    this._closeHandler = onClose.bind(this);
    this._cleanupHandler = cleanup.bind(this);

    attachCleanup(this);
    this._setTransport(this._options.transport);
  }
1263363
def board(self, *, _cache: bool = False) -> chess.Board:
        
        return self.headers.board()
375232
def connection(self):
        
        connection = getattr(self.state, "connection", None)
        if connection is None:
            connection = self.state.connection = pika.BlockingConnection(
                parameters=self.parameters)
            self.connections.add(connection)
        return connection
1068346
def _connect(self):
        

        if self.recvConn:
            if self.pid != os.getpid():
                raise UseAfterFork(
                    "do not re-use a connection after fork; open a new client instead"
                )
            return

        if self.sockpath is None:
            self.sockpath = self._resolvesockname()

        kwargs = {}
        if self.transport == CLIProcessTransport:
            kwargs["binpath"] = self.binpath

        self.tport = self.transport(self.sockpath, self.timeout, **kwargs)
        self.sendConn = self.sendCodec(self.tport)
        self.recvConn = self.recvCodec(self.tport)
        self.pid = os.getpid()
14037
def install_metaboard(
    replace_existing=False,
):
    
    metaboard = AutoBunch()
    metaboard.name = 'Metaboard'

    metaboard.upload.protocol = 'usbasp'
    metaboard.upload.maximum_size = '14336'
    metaboard.upload.speed = '19200'

    metaboard.build.mcu = 'atmega168'
    metaboard.build.f_cpu = '16000000L'
    metaboard.build.core = 'arduino'

    metaboard.upload.disable_flushing = 'true'

    board_id = 'metaboard'

    install_board(board_id, metaboard, replace_existing=replace_existing)
1165930
def connect(self):
                        
        self.serial = serial.Serial(port=self.port, baudrate=self.baudrate, timeout=self.timeout)
        # Start read thread
        self.alive = True 
        self.rxThread = threading.Thread(target=self._readLoop)
        self.rxThread.daemon = True
        self.rxThread.start()
547716
def make_socket():
    '''
    '''
    mreq = struct.pack("4sl", socket.inet_aton(MCAST_IP), socket.INADDR_ANY)
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind(('', MCAST_PORT))
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
    sock.settimeout(0.2)
    return sock
892339
def connect(self):
    
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("127.0.0.1", self._port))
    return sock
1053731
def open
			@serial ||= SerialPort.new @port, @rate
			@serial_input = Enumerator.new { |y| loop do
				y.yield @serial.readbyte
			end }
			@connected = true
		end
38720
def reset(mode):
    
    _board.enter_raw_repl()
    if mode == "SOFT":
        _board.exit_raw_repl()
        return

    _board.exec_(
        """if 1:
        def on_next_reset(x):
            try:
                import microcontroller
            except:
                if x == 'NORMAL': return ''
                return 'Reset mode only supported on CircuitPython'
            try:
                microcontroller.on_next_reset(getattr(microcontroller.RunMode, x))
            except ValueError as e:
                return str(e)
            return ''
        def reset():
            try:
                import microcontroller
            except:
                import machine as microcontroller
            microcontroller.reset()
    """
    )
    r = _board.eval("on_next_reset({})".format(repr(mode)))
    print("here we are", repr(r))
    if r:
        click.echo(r, err=True)
        return

    try:
        _board.exec_("reset()")
    except serial.serialutil.SerialException as e:
        # An error is expected to occur, as the board should disconnect from
        # serial when restarted via microcontroller.reset()
        pass
1200572
async def get_controller(self):
        
        from juju.controller import Controller
        controller = Controller(jujudata=self._connector.jujudata)
        kwargs = self.connection().connect_params()
        kwargs.pop('uuid')
        await controller._connect_direct(**kwargs)
        return controller
1001393
def install_board_with_programmer(mcu,
                                  programmer,
                                  f_cpu=16000000,
                                  core='arduino',
                                  replace_existing=False,
                                  ):
    """"""
    bunch = AutoBunch()
    board_id = '{mcu}_{f_cpu}_{programmer}'.format(f_cpu=f_cpu,
                                             mcu=mcu,
                                             programmer=programmer,
                                             )
    bunch.name = '{mcu}@{f} Prog:{programmer}'.format(f=strfreq(f_cpu),
                                                      mcu=mcu,
                                                      programmer=programmer,
                                                      )

    bunch.upload.using = programmer

    bunch.build.mcu = mcu
    bunch.build.f_cpu = str(f_cpu) + 'L'
    bunch.build.core = core

    install_board(board_id, bunch, replace_existing=replace_existing)
526299
def create_hardware(klass, pin = nil)
      klass = NullHardware unless @initialized_hardware
      key = [klass, pin]
      @hardware_cache.synchronize do
        @hardware_cache[key] ||= klass.new(pin: pin)
      end
      @hardware_cache[key]
    end
216874
def getAllConnectedInterface():
        

        devices = hid.enumerate()

        if not devices:
            logging.debug("No Mbed device connected")
            return []

        boards = []

        for deviceInfo in devices:
            product_name = deviceInfo['product_string']
            if (product_name.find("MicArray") < 0):
                # Skip non cmsis-dap devices
                continue

            try:
                dev = hid.device(vendor_id=deviceInfo['vendor_id'], product_id=deviceInfo['product_id'],
                    path=deviceInfo['path'])
            except IOError:
                logging.debug("Failed to open Mbed device")
                continue

            # Create the USB interface object for this device.
            new_board = HidApiUSB()
            new_board.vendor_name = deviceInfo['manufacturer_string']
            new_board.product_name = deviceInfo['product_string']
            new_board.serial_number = deviceInfo['serial_number']
            new_board.vid = deviceInfo['vendor_id']
            new_board.pid = deviceInfo['product_id']
            new_board.device_info = deviceInfo
            new_board.device = dev
            try:
                dev.open_path(deviceInfo['path'])
            except AttributeError:
                pass
            except IOError:
                # Ignore failure to open a device by skipping the device.
                continue

            boards.append(new_board)

        return boards