Exemplo n.º 1
0
        private BluetoothService CreateService()
        {
            BluetoothService service = null;

            try
            {
                // check if Bluetooth-Stick is available
                if (BluetoothRadio.IsSupported)
                {
                    // Device visible for others
                    // RadioMode setting not supported as long as the
                    // WinCE image doesn't include the BthUtil.dll
                    //BluetoothRadio.PrimaryRadio.Mode =
                    //     BluetoothRadioMode.Discoverable;

                    // set device Name
                    BluetoothRadio.PrimaryRadio.Name = "AbflussRobot";
                    // desired service
                    Guid serviceId = BluetoothServiceList.Robot06;
                    //Guid serviceId = new Guid("{FB4B43E4-0328-4056-82A5-7E03BE347082}");

                    // start new service
                    service = new BluetoothService();
                    service.CreateService(serviceId);
                    Console.WriteLine("Service " + serviceId.ToString() + " started.");
                }
                else
                {
                    Console.WriteLine("No Bluetooth-Stick is available");
                    throw new BluetoothNotStartedException();
                    return null;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return service;
        }