Ejemplo n.º 1
0
        async Task <MeadowDeviceExecutionTarget> InitalizeMeadow(Connection connection)
        {
            MeadowDeviceExecutionTarget target = null;

            await Task <MeadowDeviceExecutionTarget> .Run(() =>
            {
                var meadowSerialDevice = new MeadowSerialDevice(true);
                if (MeadowDeviceManager.CurrentDevice == null || (MeadowDeviceManager.CurrentDevice?.connection.Removed ?? true))
                {
                    MeadowDeviceManager.CurrentDevice = meadowSerialDevice;
                }

                lock (_lockObject)
                {
                    target = new MeadowDeviceExecutionTarget(meadowSerialDevice, connection);
                    if (target != null)
                    {
                        Console.WriteLine($"DeploymentTargetsManagerLinux Added: {target}");
                        Targets.Add(target);
                        target.SerialNumberSet += Target_SerialNumberSet;
                        DeviceListChanged?.Invoke(target);
                    }
                }
            });

            return(target);
        }
Ejemplo n.º 2
0
        public void SetDeviceList()
        {
            var devices = DeviceList.Local;

            SensorList = devices.GetHidDevices().ToList().FindAll(device => device.VendorID == VendorId);
            DeviceListChanged?.Invoke();
        }
Ejemplo n.º 3
0
 void RemoveExpiredTargets()
 {
     lock (_lockObject)
     {
         var expiredTargets = Targets.FindAll(x => x.meadowSerialDevice.connection.Removed && x.meadowSerialDevice.connection.TimeRemoved.AddSeconds(SecondsToRemove) < DateTime.UtcNow);
         foreach (var target in expiredTargets)
         {
             //Check if meadow is NOT in boot/dfu mode
             if (!Meadow.CLI.Internals.Udev.Udev.GetSerialNumbers("0483", "df11", "usb").Contains(target.SerialNumber))
             {
                 // Remove Pad from Monodevelop
                 Gtk.Application.Invoke(delegate
                 {
                     foreach (var pad in MonoDevelop.Ide.IdeApp.Workbench.Pads.FindAll(x => x?.Content is MeadowPad && ((MeadowPad)x.Content).Target == target))
                     {
                         target.meadowPad.Window.Visible = false;
                         MonoDevelop.Ide.IdeApp.Workbench.Pads.Remove(pad);
                     }
                 });
                 Targets.Remove(target);
             }
         }
         if (expiredTargets.Count > 0)
         {
             DeviceListChanged?.Invoke(null);
         }
     }
 }
Ejemplo n.º 4
0
        private void OnDeviceListChanged(IntPtr enumerator, IntPtr userData)
        {
            if (enumerator != _enumeratorPtr)
            {
                return;
            }

            DeviceListChanged?.Invoke(this, null);
        }
        private async Task UpdateTargetsList(CancellationToken ct)
        {
            var serialPorts = MeadowDeviceManager.FindSerialDevices();

            foreach (var port in serialPorts)
            {
                if (ct.IsCancellationRequested)
                {
                    break;
                }

                if (Targets.Any(t => t.meadowSerialDevice.connection?.USB?.DevicePort == port))
                {
                    continue;
                }

                var timeout = Task <MeadowDevice> .Delay(1000);

                var meadowTask = MeadowDeviceManager.GetMeadowForSerialPort(port);

                await Task.WhenAny(timeout, meadowTask);

                var meadow = meadowTask.Result;

                if (meadow != null)
                {
                    //we should really just have the execution target own an instance of MeadowDevice
                    Targets.Add(new MeadowDeviceExecutionTarget(meadow));
                    //meadow.CloseConnection();
                    DeviceListChanged?.Invoke(null);
                    meadow.StatusChange += StatusDisplay;
                }
            }

            var removeList = new List <MeadowDeviceExecutionTarget>();

            foreach (var t in Targets)
            {
                if (serialPorts.Any(p => p == t.meadowSerialDevice.connection?.USB?.DevicePort) == false)
                {
                    removeList.Add(t);
                }
            }

            foreach (var r in removeList)
            {
                r.meadowSerialDevice.StatusChange -= StatusDisplay;
                Targets.Remove(r);
                DeviceListChanged?.Invoke(null);
            }
        }
Ejemplo n.º 6
0
 IntPtr notificationHandle = IntPtr.Zero;     // Дескриптор подписки.
 /// <summary>
 /// Процедура обработки оконных сообщений.
 /// </summary>
 /// <param name="m">Структура, описывающая сообщения.</param>
 protected override void WndProc(ref Message m)
 {
     base.WndProc(ref m);
     if (m.Msg == DeviceNotificator.WmDevicechange) // сообщение - изменился состав устройств.
     {
         EventArgs e = new EventArgs();
         if ((int)m.WParam == DeviceNotificator.DbtDevicearrival) // добавилось новое?
         {
             DeviceAdded?.Invoke(this, e);
             DeviceListChanged?.Invoke(this, e);
         }
         else if ((int)m.WParam == DeviceNotificator.DbtDeviceremovecomplete) // удалили старое?
         {
             DeviceRemoved?.Invoke(this, e);
             DeviceListChanged?.Invoke(this, e);
         }
     }
 }
Ejemplo n.º 7
0
        private static void UpdateTargetsList(List <string> serialPorts, CancellationToken ct)
        {
            Debug.WriteLine("Update targets list");
            //var serialPorts = MeadowDeviceManager.FindSerialDevices();
            //use the local hack version that leverages ioreg

            foreach (var port in serialPorts)
            {
                if (ct.IsCancellationRequested)
                {
                    break;
                }

                if (Targets.Any(t => t.Id == port))
                {
                    continue;
                }

                Targets?.Add(new MeadowDeviceExecutionTarget(port));
                DeviceListChanged?.Invoke(null);
            }

            var removeList = new List <MeadowDeviceExecutionTarget>();

            foreach (var t in Targets)
            {
                if (serialPorts.Any(p => p == t.Id) == false)
                {
                    removeList.Add(t);
                }
            }

            foreach (var r in removeList)
            {
                Targets?.Remove(r);
                DeviceListChanged?.Invoke(null);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create respective devices and (re)populate Devices array.
        /// </summary>
        protected virtual void SubscribeToDevices()
        {
            var oldDevices = (TDevice[])Devices?.Clone() ?? new TDevice[0];

            // The following function doesn't work properly in Windows XP, returning installed mouses only.
            RawDevices = Device.GetDevices()
                         .Where(d => d.DeviceType == DevType)
                         .OrderBy(d => d, new DeviceComparer())
                         .ToList();
            // So let's not rely on it if we're running on XP.
            if (RawDevices.Count > 0 || !Environment.OSVersion.IsWinVistaOrHigher())
            {
                WrappedDevices.Clear();
                int ii = 0; // input index
                int io = 0; // output index
                if (SelectMerged)
                {
                    WrappedDevices.Add(new DeviceWrap <TDevice>
                    {
                        Device   = CreateMergedDevice(0),
                        Name     = "Merged",
                        IsMerged = true
                    });
                    io++;
                }
                foreach (var info in RawDevices)
                {
                    if (SelectedDevices.Any(p => p(info, ii)))
                    {
                        WrappedDevices.Add(new DeviceWrap <TDevice>
                        {
                            Device = CreateDevice(info, io),
                            Info   = info,
                            Name   = info.DeviceName,
                            IsRaw  = true
                        });
                        io++;
                    }
                    ii++;
                }
                Devices     = WrappedDevices.Select(d => d.Device).ToArray();
                DeviceNames = WrappedDevices.Select(d => d.Name).ToArray();
            }
            else
            {
                WrappedDevices.Clear();
                WrappedDevices.Add(new DeviceWrap <TDevice>
                {
                    Device  = CreateDummy(),
                    Name    = "Dummy",
                    IsDummy = true
                });
                Devices     = new [] { WrappedDevices[0].Device };
                DeviceNames = new[] { WrappedDevices[0].Name };
            }

            DeviceListChanged?.Invoke(this, new DeviceListChangedEventArgs <TDevice>
            {
                OldDevices = oldDevices,
                NewDevices = Devices
            });
        }
Ejemplo n.º 9
0
 private void ScanDevMgr_DeviceListChanged(object sender, EventArgs e)
 {
     RefreshDeviceList();
     DeviceListChanged?.Invoke(sender, e);
 }
Ejemplo n.º 10
0
 public DeviceModel()
 {
     _enumerator = new DeviceEnumerator(DeviceType.Any);
     _enumerator.DeviceListChanged += (sender, args) => { DeviceListChanged?.Invoke(this, null); };
 }
 public void CheckInDevice(IPAddress targetIP, DeviceInfo targetInfo)
 {
     deviceDictionary[targetIP] = targetInfo;
     Logging.Debug($"IP check in: {targetIP} ({targetInfo.DeviceName})");
     DeviceListChanged?.Invoke(this, new EventArgs());
 }