Exemplo n.º 1
0
		private async void LoadBluetoothGPS()
		{
			//Ensure the bluetooth capability is enabled by opening package.appxmanifest in a text editor, 
			// and add the following to the <Capabilities> section:
			//    <m2:DeviceCapability Name="bluetooth.rfcomm">
			//      <m2:Device Id="any">
			//        <m2:Function Type="name:serialPort" />
			//      </m2:Device>
			//    </m2:DeviceCapability>

			//Get list of devices
			string serialDeviceType = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort);
			var devices = await DeviceInformation.FindAllAsync(serialDeviceType);

			string GpsDeviceName = "HOLUX GPSlim236"; //Change name to your device or build UI for user to select from list of 'devices'
													  //Select device by name
			var bluetoothDevice = devices.Where(t => t.Name == GpsDeviceName).FirstOrDefault();
			//Get service
			RfcommDeviceService rfcommService = await RfcommDeviceService.FromIdAsync(bluetoothDevice.Id);
			if (rfcommService != null)
			{
				var device = new NmeaParser.BluetoothDevice(rfcommService);
				device.MessageReceived += device_MessageReceived;
				await device.OpenAsync();
			}
		}
Exemplo n.º 2
0
        private async void LoadBluetoothGPS()
        {
            //Ensure the bluetooth capability is enabled by opening package.appxmanifest in a text editor,
            // and add the following to the <Capabilities> section:
            //    <m2:DeviceCapability Name="bluetooth.rfcomm">
            //      <m2:Device Id="any">
            //        <m2:Function Type="name:serialPort" />
            //      </m2:Device>
            //    </m2:DeviceCapability>

            //Get list of devices
            string serialDeviceType = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort);
            var    devices          = await DeviceInformation.FindAllAsync(serialDeviceType);

            string GpsDeviceName = "HOLUX GPSlim236";             //Change name to your device or build UI for user to select from list of 'devices'
            //Select device by name
            var bluetoothDevice = devices.Where(t => t.Name == GpsDeviceName).FirstOrDefault();
            //Get service
            RfcommDeviceService rfcommService = await RfcommDeviceService.FromIdAsync(bluetoothDevice.Id);

            if (rfcommService != null)
            {
                var device = new NmeaParser.BluetoothDevice(rfcommService);
                device.MessageReceived += device_MessageReceived;
                await device.OpenAsync();
            }
        }