Bonjour,
j'ai cette erreur "Object reference not set to an instance of an object"
merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 var services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync( RfcommDeviceService.GetDeviceSelector( RfcommServiceId.ObexObjectPush)); if (services.Count > 0) { // Initialize the target Bluetooth BR device var service = await RfcommDeviceService.FromIdAsync(services[0].Id); bool res = await IsCompatibleVersion(service); var dialog = new MessageDialog(res.ToString()); await dialog.ShowAsync(); } // This App relies on CRC32 checking available in version 2.0 of the service. private const uint SERVICE_VERSION_ATTRIBUTE_ID = 0x0300; private const byte SERVICE_VERSION_ATTRIBUTE_TYPE = 0x0A; // UINT32 private const uint MINIMUM_SERVICE_VERSION = 200; private async System.Threading.Tasks.Task<bool> IsCompatibleVersion(RfcommDeviceService service) { var attributes = await service.GetSdpRawAttributesAsync(Windows.Devices.Bluetooth.BluetoothCacheMode.Uncached); var attribute = attributes[SERVICE_VERSION_ATTRIBUTE_ID]; var reader = DataReader.FromBuffer(attribute); // The first byte contains the attribute' s type byte attributeType = reader.ReadByte(); if (attributeType == SERVICE_VERSION_ATTRIBUTE_TYPE) { // The remainder is the data uint version = reader.ReadUInt32(); return version >= MINIMUM_SERVICE_VERSION; } return false; }
Partager