Пример #1
0
 void _bluettothServerCallback_CharacteristicReadRequest(object sender, BleEventArgs e)
 {
     if (et == null)
     {
         SetupMesss(e);
     }
     e.Characteristic.SetValue(String.Format("Hello message from server."));
     _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset, e.Characteristic.GetValue());
 }
Пример #2
0
 void _bluettothServerCallback_DescriptorWriteRequest(object sender, BleEventArgs e)
 {
     try {
         e.Characteristic.SetValue(String.Format("Thanks for message"));
         string result = System.Text.Encoding.UTF8.GetString(e.Value);
         MessagingCenter.Send <BLE202.App, string>((BLE202.App)Xamarin.Forms.Application.Current, "Hi", "[Read]: " + result);
         if (e.ResponseNeeded)
         {
             _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset, e.Characteristic.GetValue());
         }
     }
     catch (Exception ex)
     {
     }
 }
Пример #3
0
 public void SetupMesss(BleEventArgs e)
 {
     try
     {
         et = e;
         MessagingCenter.Subscribe <App, string>((App)global::Xamarin.Forms.Application.Current, "GetValuex", async(sender, arg) =>
         {
             e.Characteristic.SetValue(arg.ToString());
             if (e != null)
             {
                 MessagingCenter.Send <BLE202.App, string>((BLE202.App)Xamarin.Forms.Application.Current, "Hi", "[Write]: " + arg.ToString());
             }
             _bluetoothServer.SendResponse(e.Device, e.RequestId, GattStatus.Success, e.Offset, e.Characteristic.GetValue());
             _bluetoothServer.NotifyCharacteristicChanged(e.Device, e.Characteristic, false);
         });
     } catch (Exception ex)
     {
         MessagingCenter.Send <BLE202.App, string>((BLE202.App)Xamarin.Forms.Application.Current, "Hi", ex.ToString());
     }
 }
Пример #4
0
        void _bluettothServerCallback_NotificationSent(object sender, BleEventArgs e)
        {
            MessagingCenter.Send <BLE202.App, string>((BLE202.App)Xamarin.Forms.Application.Current, "Hi", "Get Request Read From Client");

            /*
             * if (_count == 0)
             * {
             *  _sw = new Stopwatch();
             *  _sw.Start();
             * }
             *
             * if (_count < 1000)
             * {
             *  var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
             *  var random = new System.Random();
             *  var result = new string(
             *      Enumerable.Repeat(chars, 20)
             *          .Select(s => s[random.Next(s.Length)])
             *          .ToArray());
             *  _characteristic.SetValue(result);
             *  MessagingCenter.Send<BLE202.App, string>((BLE202.App)Xamarin.Forms.Application.Current, "Hi", result);
             *  _bluetoothServer.NotifyCharacteristicChanged(e.Device, _characteristic, false);
             *
             *  _count++;
             *
             * }
             * else
             * {
             *  _sw.Stop();
             *  Console.WriteLine("Sent # {0} notifcations. Total kb:{2}. Time {3}(s). Throughput {1} bytes/s", _count,
             *      _count * 20.0f / _sw.Elapsed.TotalSeconds, _count * 20 / 1000, _sw.Elapsed.TotalSeconds);
             * } */
            //   _characteristic.SetValue("hello");
            //  MessagingCenter.Send<BLE202.App, string>((BLE202.App)Xamarin.Forms.Application.Current, "Hi", "hello");
            //   _bluetoothServer.NotifyCharacteristicChanged(e.Device, _characteristic, false);
        }
Пример #5
0
 void _bluettothServerCallback_ConnectionStateChange(object sender, BleEventArgs e)
 {
     MessagingCenter.Send <BLE202.App, string>((BLE202.App)Xamarin.Forms.Application.Current, "Hi", "[" + e.NewState.ToString() + " Device]Mac:  " + e.Device.Address.ToString());
 }