private async void RfcommScanner_Added(object sender, Bluetooth.IBluetoothDevice e)
        {
            if (e.Address == BluetoothUtils.AddressStringToInt64("DC:53:60:DD:AE:63"))
            {
                //var serviceResult = await e.GetRfcommServicesAsync();
                await e.RfcommConnectAsync();

                //var serviceResult = await e.GetRfcommServicesForIdAsync(Constants.ServiceId);
                var serviceResult = await e.GetRfcommServicesAsync();

                IRfcommDeviceService service = null;
                if (serviceResult.Error == BluetoothError.Success && serviceResult.Services.Count > 0)
                {
                    foreach (var ser in serviceResult.Services)
                    {
                        if (ser.ServiceId == Constants.ServiceId)
                        {
                            service = ser;
                            break;
                        }
                    }
                }
                if (service == null)
                {
                    return;
                }
                var connection = new RfcommRXConnection(service, ConnectionGroup);
                OnConnectionReceived?.Invoke(this, connection);
            }
        }
Exemplo n.º 2
0
 public RfcommDeviceServicePage(IRfcommDeviceService service)
 {
     RfcommDeviceService = service;
     RXList = new ObservableCollection <string>();
     InitializeComponent();
     RXListView.ItemsSource = RXList;
     BindingContext         = RfcommDeviceService;
 }
        public RXRFCommConnection(IRfcommDeviceService remoteDeviceService, IBluetoothDevice remoteDevice, StreamSocket streamSocket)
        {
            RemoteDeviceService = remoteDeviceService;
            RemoteDevice        = remoteDevice;
            StreamSocket        = streamSocket;

            InputStream  = streamSocket.InputStream.AsStreamForRead();
            OutputStream = streamSocket.OutputStream.AsStreamForWrite();
        }
 /// <summary>
 /// 这个构造器是Client用的
 /// </summary>
 /// <param name="deviceService"></param>
 internal RfcommRXConnection(IRfcommDeviceService deviceService, IRXConnectionGroup connectionGroup)
 {
     DeviceService   = deviceService;
     ConnectionState = RXConnectionState.Created;
     ConnectionGroup = connectionGroup;
 }