コード例 #1
0
        public async Task ConnectAsync()
        {
            ConnectionState = RXConnectionState.Connecting;
            OnConnectionStateChanged?.Invoke(this, ConnectionState);
            //Host is client
            if (DeviceService != null)
            {
                try
                {
                    await DeviceService.ConnectAsync();

                    RfcommConnection     = DeviceService.RfcommConnection;
                    _ReadInputStreamTask = _ReadInputStreamTaskAsync();
                    ConnectionState      = RXConnectionState.Connected;
                    OnConnectionStateChanged?.Invoke(this, ConnectionState);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e);
                    ConnectionState = RXConnectionState.Destoryed;
                    OnConnectionStateChanged?.Invoke(this, ConnectionState);
                }
            }
            else
            {
                /*Host is Server*/
                ConnectionState      = RXConnectionState.Connected;
                _ReadInputStreamTask = _ReadInputStreamTaskAsync();
                OnConnectionStateChanged?.Invoke(this, ConnectionState);
            }
        }