void OnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { BLEPeripheral peripheral = null; foreach (BLEPeripheral blep in discoveredPeripherals) { if (blep.UUID.StringValue.Equals(e.Peripheral.ToString())) { peripheral = blep; break; } } if (peripheral == null) { peripheral = new BLEPeripheral(e.Peripheral); discoveredPeripherals.Add(peripheral); } EventHandler <BLEDiscoveredPeripheralEventArgs> handler = DiscoveredPeripheral; if (handler != null) { BLEDiscoveredPeripheralEventArgs args = new BLEDiscoveredPeripheralEventArgs(); args.AdvertisementData = new List <KeyValuePair <string, string> > (); args.Peripheral = peripheral; args.RSSI = e.RSSI.Int32Value; foreach (KeyValuePair <NSObject, NSObject> kvp in e.AdvertisementData) { args.AdvertisementData.Add(new KeyValuePair <string, string> (kvp.Key.ToString(), kvp.Value.ToString())); } handler(this, args); } }
void OnDisconnectedPeripheral(object sender, CBPeripheralErrorEventArgs e) { BLEPeripheral peripheral = null; foreach (BLEPeripheral blep in discoveredPeripherals) { if (blep.UUID.StringValue == e.Peripheral.ToString()) { peripheral = blep; break; } } EventHandler <BLEPeripheralErrorEventArgs> handler = DisconnectedFromPeripheral; if (handler != null) { BLEPeripheralErrorEventArgs args = new BLEPeripheralErrorEventArgs(); args.Peripheral = peripheral; args.Error = e.Error?.ToString(); } }
void OnConnectedPeripheral(object sender, CBPeripheralEventArgs e) { BLEPeripheral peripheral = null; foreach (BLEPeripheral blep in discoveredPeripherals) { if (blep.UUID.StringValue == e.Peripheral.ToString()) { peripheral = blep; break; } } EventHandler <BLEPeripheralEventArgs> handler = ConnectedToPeripheral; if (handler != null) { BLEPeripheralEventArgs args = new BLEPeripheralEventArgs(); args.Peripheral = peripheral; handler(this, args); } }