/// <summary>
        /// Connect to the currently selected service
        /// </summary>
        public async void ConnectToSelectedDevice()
        {
            Debug.WriteLine("ConnectToSelectedDevice: Entering");
            StopEnumeration();
            Views.Busy.SetBusy(true, "Connecting to " + SelectedDevice.Name);

            Debug.WriteLine("ConnectToSelectedDevice: Trying to connect to " + SelectedDevice.Name);

            if (selectedDevice.IsConnected == true)
            {
                Debug.WriteLine("ConnectToSelectedDevice: Going to Device Service Page");
                Views.Busy.SetBusy(false);
                //GotoDeviceServicesPage();
                NavigationService.Navigate(typeof(Views.CharacteristicPage));
                Debug.WriteLine("ConnectToSelectedDevice: Exiting");
                return;
            }


            if (await SelectedDevice.Connect() == false)
            {
                Debug.WriteLine("ConnectToSelectedDevice: Something went wrong getting the BluetoothLEDevice");
                Views.Busy.SetBusy(false);
                SelectedDevice = null;
                NavigationService.Navigate(typeof(Views.Discover));
                return;
            }

            Debug.WriteLine("ConnectToSelectedDevice: Going to Device Service Page");
            Views.Busy.SetBusy(false);
            GotoDeviceServicesPage();
            Debug.WriteLine("ConnectToSelectedDevice: Exiting");
        }
Ejemplo n.º 2
0
        public async Task RefreshDevices(bool connect = true, bool afterStartUp = false)
        {
            Devices = Config.Devices;
            var customIpAddresses = Devices.Where(d => d.IsCustom).Select(d => d.IpAddress);

            var pnpDevices = await Utils.GetPnpDevices(Config.DeviceSearchKey);

            var autoDevices     = pnpDevices.Where(p => !customIpAddresses.Contains(p.IpAddress)).Select(d => new LgDevice(d.Name, d.IpAddress, d.MacAddress, false)).ToList();
            var autoIpAddresses = pnpDevices.Select(d => d.IpAddress);

            Devices.RemoveAll(d => !d.IsCustom && !autoIpAddresses.Contains(d.IpAddress));

            var newAutoDevices = autoDevices.Where(ad => ad.IpAddress != null && !Devices.Any(d => d.IpAddress != null && d.IpAddress.Equals(ad.IpAddress)));

            Devices.AddRange(newAutoDevices);

            if (Devices.Any())
            {
                var preferredDevice = Devices.FirstOrDefault(x => x.MacAddress != null && x.MacAddress.Equals(Config.PreferredMacAddress)) ?? Devices[0];

                SelectedDevice = preferredDevice;
            }
            else
            {
                SelectedDevice = null;
            }

            if (afterStartUp && SelectedDevice == null && Config.PowerOnAfterStartup && !string.IsNullOrEmpty(Config.PreferredMacAddress))
            {
                Logger.Debug("No device has been found, trying to wake it first...");

                var tempDevice = new LgDevice("Test", string.Empty, Config.PreferredMacAddress);
                tempDevice.Wake();

                await Task.Delay(4000);
                await RefreshDevices();

                return;
            }

            foreach (var device in Devices)
            {
                device.PowerStateChangedEvent += LgDevice_PowerStateChangedEvent;
            }

            if (connect && SelectedDevice != null)
            {
                if (_allowPowerOn)
                {
                    WakeAfterStartupOrResume();
                }
                else
                {
                    var _ = SelectedDevice.Connect();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 设备枚举通知,判断可连接设备。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void Context_DeviceEnumEvent(GattSampleContext sender, BLTEEnumEventArgs args)
        {
            if (args.Device.Name.Contains(FilterName))
            {
                if (args.Notify == BLTEEnumEvent.Add)
                {
                    if (SelectedDevice == null)
                    {
                        SelectedDevice = args.Device;
                        Context.StopEnumeration();
                        await SelectedDevice.Connect();

                        GetCharacteristics();
                        OnCodeyConnected();
                    }
                }
                else
                {
                    SelectedDevice = null;
                }
            }
        }
Ejemplo n.º 4
0
        private void DeviceConnectCommand_Execute()
        {
            if (IsConnected)
            {
                try
                {
                    Settings.Instance.Device?.Disconnect();
                    UpdateDevicesInfoCommand.Execute();
                    IsConnected = false;
                }
                catch
                {
                    IsConnected = false;
                    Settings.Instance.Device = null;
                    MessageBox.Show((string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#DeviceHardFaultError"), (string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#ErrorMsgBoxTitle"), MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                if (SelectedDevice == null)
                {
                    MessageBox.Show((string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#InvalidSelectionError"), (string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#ErrorMsgBoxTitle"), MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                try
                {
                    SelectedDevice.Connect();
                    Settings.Instance.Device = SelectedDevice;
                    IsConnected = true;
                }
                catch
                {
                    IsConnected = false;
                    Settings.Instance.Device = null;
                    MessageBox.Show((string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#ConnectionFaultError"), (string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#ErrorMsgBoxTitle"), MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Ejemplo n.º 5
0
        private void OnConnectDeviceCommandExecute(object obj)
        {
            SelectedDevice.Connect();
            ConnectedDevice = SelectedDevice;

            //var functionalCategories = SelectedDevice.FunctionalCategories();
            //foreach (var functionalCategory in functionalCategories)
            //{
            //    var functionalObjects = SelectedDevice.FunctionalObjects(functionalCategory);
            //}

            var fuid = ConnectedDevice.FunctionalUniqueId;
            var root = ConnectedDevice.GetRootDirectory();

            var images = ConnectedDevice.GetContentLocations(ContentType.Image);
            var dirs   = ConnectedDevice.GetDirectories(ConnectedDevice.GetRootDirectory().FullName);

            //var test = ConnectedDevice.GetFiles(@"\\SD-Karte von Transcend\DCIM\Camera");

            if (dirs.Length == 0)
            {
                return;
            }

            var thread = new Thread(
                () =>
            {
                var camPath     = @"\\SD-Karte von Transcend\DCIM\Camera";
                var directories = ConnectedDevice.GetDirectories(camPath);
                var files       = ConnectedDevice.GetFiles(camPath);

                for (int i = 0; i < files.Length; i++)
                {
                    var s        = files[i];
                    var fileName = Path.GetFileName(s);
                    var filePath = Path.Combine(camPath, s);
                    var fi       = ConnectedDevice.GetFileInfo(filePath);

                    try
                    {
                        using (var stream = new MemoryStream())
                        {
                            ConnectedDevice.DownloadFile(s, stream);
                            using (var fs = new FileStream($"C:\\Dev\\#Test\\DownloadedFromG4\\{fileName}", FileMode.Create))
                            {
                                stream.Seek(0, SeekOrigin.Begin);
                                stream.WriteTo(fs);
                            }
                        }
                    }
                    catch (System.Exception e)
                    {
                        throw;
                    }
                }
            });

            thread.Start();


            foreach (var enumerateFileSystemInfo in root.EnumerateFileSystemInfos())
            {
                foreach (var fileSystemEntry in ConnectedDevice.GetFileSystemEntries(enumerateFileSystemInfo.FullName))
                {
                    var path = Path.Combine(enumerateFileSystemInfo.FullName, fileSystemEntry);
                    var fi   = ConnectedDevice.GetFileInfo(path);

                    if (fi.FullName.Contains("DCIM"))
                    {
                        foreach (var dir in fi.Directory.EnumerateDirectories())
                        {
                            if (dir.FullName.Contains("DCIM"))
                            {
                                foreach (var enumerateDirectory in dir.EnumerateDirectories())
                                {
                                    if (enumerateDirectory.FullName.Contains("Camera"))
                                    {
                                        var files = enumerateDirectory.EnumerateFiles();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }