Ejemplo n.º 1
0
        public async Task <DeviceConnectionResponse> Connect()
        {
            if (this.socket == null)
            {
                Java.Util.UUID uuid = Java.Util.UUID.FromString("00001101-0000-1000-8000-00805F9B34FB");
                this.socket = this.device.CreateRfcommSocketToServiceRecord(uuid);
            }

            try
            {
                await this.socket.ConnectAsync();

                return(DeviceConnectionResponse.Success);
            }
            catch (Java.IO.IOException ex)
            {
                Log.Error("BluetoothSocket.Connect()", ex.Message);
                return(DeviceConnectionResponse.Failure(
                           new DeviceConnectionException(this, "BluetoothSocket.ConnectAsync()", ex)));
            }
        }
Ejemplo n.º 2
0
        public async Task <DeviceConnectionResponse> Connect()
        {
            if (this.socket != null)
            {
                this.socket.Dispose();
            }

            try
            {
                this.socket = new StreamSocket();

                await this.socket.ConnectAsync(device.HostName, device.ServiceName);

                return(DeviceConnectionResponse.Success);
            }
            catch (Exception ex)
            {
                this.socket.Dispose();
                this.socket = null;
                return(DeviceConnectionResponse.Failure(new DeviceConnectionException(this, "StreamSocket.ConnectAsync", ex)));
            }
        }