private async Task <ProximityDevice> GetNfcDevice() { ProximityDevice device = null; string selectorString = ProximityDevice.GetDeviceSelector(); DeviceInformationCollection deviceInfoCollection = await DeviceInformation.FindAllAsync(selectorString, new List <string>() { "{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2" }); if (deviceInfoCollection.Count > 0) { foreach (DeviceInformation info in deviceInfoCollection) { Log("Found: " + info.Name); foreach (string prop in info.Properties.Keys) { object value = info.Properties[prop]; if (null != value) { Log(prop + ": " + value.ToString()); } } device = ProximityDevice.FromId(info.Id); } } return(device); }
public List <DeviceInfo> CreateList() { List <DeviceInfo> selectors = new List <DeviceInfo>(); // Pre-canned device class selectors selectors.Add(new DeviceInfo() { DisplayName = "All Device Interfaces (default)", DeviceClassSelector = DeviceClass.All, Selection = null }); selectors.Add(new DeviceInfo() { DisplayName = "Audio Capture", DeviceClassSelector = DeviceClass.AudioCapture, Selection = null }); selectors.Add(new DeviceInfo() { DisplayName = "Audio Render", DeviceClassSelector = DeviceClass.AudioRender, Selection = null }); selectors.Add(new DeviceInfo() { DisplayName = "Image Scanner", DeviceClassSelector = DeviceClass.ImageScanner, Selection = null }); selectors.Add(new DeviceInfo() { DisplayName = "Location", DeviceClassSelector = DeviceClass.Location, Selection = null }); selectors.Add(new DeviceInfo() { DisplayName = "Portable Storage", DeviceClassSelector = DeviceClass.PortableStorageDevice, Selection = null }); selectors.Add(new DeviceInfo() { DisplayName = "Video Capture", DeviceClassSelector = DeviceClass.VideoCapture, Selection = null }); // A few examples of selectors built dynamically by windows runtime apis. selectors.Add(new DeviceInfo() { DisplayName = "Human Interface (HID)", Selection = HidDevice.GetDeviceSelector(0, 0) }); selectors.Add(new DeviceInfo() { DisplayName = "Activity Sensor", Selection = ActivitySensor.GetDeviceSelector() }); selectors.Add(new DeviceInfo() { DisplayName = "Pedometer", Selection = Pedometer.GetDeviceSelector() }); selectors.Add(new DeviceInfo() { DisplayName = "Proximity", Selection = ProximityDevice.GetDeviceSelector() }); selectors.Add(new DeviceInfo() { DisplayName = "Proximity Sensor", Selection = ProximitySensor.GetDeviceSelector() }); return(selectors); }
private void CreateDeviceWatcher() { string selectorString = ProximityDevice.GetDeviceSelector(); DeviceWatcher watcher = DeviceInformation.CreateWatcher(selectorString); watcher.Added += Watcher_Added; watcher.Removed += Watcher_Removed; watcher.Updated += Watcher_Updated; watcher.EnumerationCompleted += Watcher_EnumerationCompleted; watcher.Start(); }
private async Task <ProximityDevice> GetNfcDevice() { ProximityDevice device = null; string selectorString = ProximityDevice.GetDeviceSelector(); DeviceInformationCollection deviceInfoCollection = await DeviceInformation.FindAllAsync(selectorString, new List <string>() { "{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2" }); if (deviceInfoCollection.Count > 0) { foreach (DeviceInformation info in deviceInfoCollection) { Log($"Found: {info.Name} "); Log($"Kind {info.Kind.ToString()} "); foreach (string prop in info.Properties.Keys) { object value = info.Properties[prop]; if (null != value) { if (value is string[]) { string output = string.Empty; string[] vals = value as string[]; foreach (var v in vals) { output += v.ToString() + ", "; } Log(prop + ": " + output); } else { Log(prop + ": " + value.ToString()); } } if ("{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2" == prop) { Log("Found NFC device"); } } device = ProximityDevice.FromId(info.Id); } } return(device); }
private async void FindDevice() { string selectorString = ProximityDevice.GetDeviceSelector(); DeviceInformationCollection deviceInfoCollection = await DeviceInformation.FindAllAsync(selectorString, null); if (deviceInfoCollection.Count == 0) { Log("No proximity devices found."); } else { foreach (DeviceInformation dev in deviceInfoCollection) { Log($"Proximity Device id {dev.Id} Kind {dev.Kind.ToString()} "); proximityDevice = ProximityDevice.FromId(dev.Id); } } }
private void StartClick(object sender, RoutedEventArgs e) { // Bắt đầu bằng cách lấy thiết bị NFC. string id = ProximityDevice.GetDeviceSelector(); proximityDevice = ProximityDevice.GetDefault(); if (proximityDevice == null) { this.OutputString("Devices not Found"); } else { // Thêm sự kiện DeviceArrived và DeviceDeparted. // Hai sự kiện được kích hoạt khi nhận được thiết bị trong vùng hạot động hoặc thiết bị rời khỏi vùng hoạt động proximityDevice.DeviceArrived += DeviceArrived; proximityDevice.DeviceDeparted += DeviceDeparted; this.OutputString("Tap to connect ready"); // Liên tục gởi gói tin, vì NFC là kết nối gần nên không cần bảo mật gì mà chỉ cần gửi gói tin đi thuần tuý // Tham số thứ nhất messageType, có dang Windows.*, với * là chuỗi tự định nghĩa. Ngoài ra còn có các format khác. this.proximityDevice.PublishMessage("Windows.demo", "My name is Tung"); } }