예제 #1
0
        private void RefreshCSerialPorts_Click(object sender, RoutedEventArgs e)
        {
            var refreshedPorts = OutputSerialDeviceHandler.GetPorts();

            SerialPorts.Clear();
            foreach (var port in refreshedPorts)
            {
                SerialPorts.Add(port);
            }
        }
예제 #2
0
        private async Task Initialize()
        {
            var serialPortSelector = Windows.Devices.SerialCommunication.SerialDevice.GetDeviceSelector();
            var devices            = await DeviceInformation.FindAllAsync(serialPortSelector);

            foreach (var item in devices)
            {
                SerialPorts.Add(new SerialPortInfo(item.Id, item.Name));
                Debug.WriteLine("SerialPorts Added Id = [" + item.Id + "], name = [" + item.Name + "]");
            }
        }
예제 #3
0
 public ComStatusViewModel(MainViewModel parent, MophAppProxy mophApp)
 {
     _parent             = parent;
     _mophApp            = mophApp;
     _mophApp.LogOutput += OnLogOutput;
     SelectedSerialPort  = "None";
     SerialPorts.Add(SelectedSerialPort);
     foreach (var port in SerialPort.GetPortNames())
     {
         SerialPorts.Add(port);
     }
 }
예제 #4
0
 private void DeviceAdded(object sender, DeviceChangeEventArgs e)
 {
     if ((e.Type == INTV.Core.Model.Device.ConnectionType.Serial) && DeviceChange.IsDeviceChangeFromSystem(e.State))
     {
         var acceptPort = IsNotExclusivePort(Connection.CreatePseudoConnection(e.Name, ConnectionType.Serial));
         if (acceptPort && !SerialPorts.Any(p => p.PortName == e.Name))
         {
             SerialPorts.Add(new SerialPortViewModel(e.Name));
         }
         INTV.Shared.ComponentModel.CommandManager.InvalidateRequerySuggested();
     }
     RaisePropertyChanged("IsPortValid");
 }
예제 #5
0
        public async Task RefreshSerialPortsAsync()
        {
            var activePorts = SerialPorts.Where(p => p.IsActive).Select(p => p.PortID).ToList();

            SerialPorts.Clear();
#if NETFX_CORE
            var serialPortSelector = Windows.Devices.SerialCommunication.SerialDevice.GetDeviceSelector();
            var devices            = await DeviceInformation.FindAllAsync(serialPortSelector);

            foreach (var item in devices)
            {
                bool isActive = activePorts.Contains(item.Id);
                SerialPorts.Add(new SerialPortInfo(item.Id, item.Name, isActive));
                if (isActive)
                {
                    activePorts.Remove(item.Id);
                }
            }
#else //.NET
            foreach (var item in System.IO.Ports.SerialPort.GetPortNames())
            {
                bool isActive = activePorts.Contains(item);
                SerialPorts.Add(new SerialPortInfo(item, item, isActive));
                if (isActive)
                {
                    activePorts.Remove(item.Id);
                }
            }
#endif
#if DEBUG
            // SerialPorts.Add(new SerialPortInfo("//COM-TEST/1", "Test Port 1"));
            // SerialPorts.Add(new SerialPortInfo("//COM-TEST/2", "Test Port 2"));
            // SerialPorts.Add(new SerialPortInfo("//COM-TEST/3", "Test Port 3"));
            // SerialPorts.Add(new SerialPortInfo("//COM-TEST/4", "Test Port 4"));
#endif

            // Remove controllers on ports that were active but lost
            foreach (var item in activePorts)
            {
                Watcher.Instance.RemoveController(item);
            }
        }
예제 #6
0
        public async Task Initialize()
        {
#if NETFX_CORE
            var userPath = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
#else
            var userPath = "";
#endif
            ZWOptions.Instance.Initialize();

            // Add any app specific options here...

            // ordinarily, just write "Detail" level messages to the log
            //m_options.AddOptionInt("SaveLogLevel", (int)ZWLogLevel.Detail);

            // save recent messages with "Debug" level messages to be dumped if an error occurs
            //m_options.AddOptionInt("QueueLogLevel", (int)ZWLogLevel.Debug);

            // only "dump" Debug  to the log emessages when an error-level message is logged
            //m_options.AddOptionInt("DumpTriggerLevel", (int)ZWLogLevel.Error);

            // Lock the options
            ZWOptions.Instance.Lock();

            // Create the OpenZWave Manager
            ZWManager.Instance.Initialize();
            ZWManager.Instance.OnNotification += OnNodeNotification;

#if NETFX_CORE
            var serialPortSelector = Windows.Devices.SerialCommunication.SerialDevice.GetDeviceSelector();
            var devices            = await DeviceInformation.FindAllAsync(serialPortSelector);

            foreach (var item in devices)
            {
                SerialPorts.Add(new SerialPortInfo(item));
            }
#else
            foreach (var item in System.IO.Ports.SerialPort.GetPortNames())
            {
                SerialPorts.Add(new SerialPortInfo(item));
            }
#endif
        }
    public async Task RefreshPorts()
    {
        var token = _cancellationSource.Token;

        IsRefreshBusy = true;
        await Task.Delay(750, token).ConfigureAwait(true);

        var lastSelectedDeviceId = SelectedSerialPortDeviceId;

        SerialPorts.Clear();
        try
        {
            var scope    = new ManagementScope("\\\\.\\ROOT\\cimv2");
            var observer = new ManagementOperationObserver();
            using var searcher = new ManagementObjectSearcher(scope, new SelectQuery("Win32_PnPEntity"));

            observer.ObjectReady += (_, e) =>
            {
                var portInfo = SerialPortInfo.FromManagementObject(e.NewObject as ManagementObject);
                if (portInfo == null)
                {
                    return;
                }

                SerialPorts.Add(portInfo);
            };

            var taskCompletion = new TaskCompletionSource();
            observer.Completed += (_, _) => taskCompletion.TrySetResult();

            searcher.Get(observer);
            using (token.Register(() => taskCompletion.TrySetCanceled()))
                await taskCompletion.Task.WaitAsync(token).ConfigureAwait(true);
        }
        catch { }

        SelectSerialPortByDeviceId(lastSelectedDeviceId);
        await Task.Delay(250, token).ConfigureAwait(true);

        IsRefreshBusy = false;
    }
        private async Task Initialize()
        {
#if NETFX_CORE
            var serialPortSelector = Windows.Devices.SerialCommunication.SerialDevice.GetDeviceSelector();
            var devices            = await DeviceInformation.FindAllAsync(serialPortSelector);

            foreach (var item in devices)
            {
                SerialPorts.Add(new SerialPortInfo(item.Id, item.Name));
            }
#else //.NET
            foreach (var item in System.IO.Ports.SerialPort.GetPortNames())
            {
                SerialPorts.Add(new SerialPortInfo(item, item));
            }
#endif
#if DEBUG
            // SerialPorts.Add(new SerialPortInfo("//COM-TEST/1", "Test Port 1"));
            // SerialPorts.Add(new SerialPortInfo("//COM-TEST/2", "Test Port 2"));
            // SerialPorts.Add(new SerialPortInfo("//COM-TEST/3", "Test Port 3"));
            // SerialPorts.Add(new SerialPortInfo("//COM-TEST/4", "Test Port 4"));
#endif
        }
예제 #9
0
 private void ButtonConnector_OnNewPortNames(List <string> names)
 {
     if (names.Count >= SerialPorts.Count)
     {
         for (int i = 0; i < names.Count; ++i)
         {
             if (i >= SerialPorts.Count)
             {
                 SerialPorts.Add(names[i]);
             }
             else if (SerialPorts[i] != names[i])
             {
                 SerialPorts[i] = names[i];
             }
         }
     }
     else
     {
         for (int i = names.Count; i < SerialPorts.Count; ++i)
         {
             SerialPorts.RemoveAt(i);
         }
     }
 }
예제 #10
0
        /* Methode zum Auflisten der seriellen Ports des Systems */
        public static SerialPorts EnumSerialPorts()
        {
            // SerialPorts-Instanz für die Rückgabe erzeugen
            SerialPorts ports = new SerialPorts();

            // WMI-Auflistung der Objekte der Win32_SerialPort erzeugen
            ManagementClass            mc  = new ManagementClass("Win32_SerialPort");
            ManagementObjectCollection moc = mc.GetInstances();

            // Die einzelnen Objekte durchgehen
            foreach (ManagementBaseObject mbo in moc)
            {
                // SerialPort-Instanz erzeugen und initialisieren
                SerialPort port = new SerialPort();
                try{ port.DeviceId = (string)mbo["DeviceId"]; }
                catch {}
                try{ port.MaxBaudRate = (uint)mbo["MaxBaudRate"]; }
                catch {}
                try{ port.Supports16BitMode = (bool)mbo["Supports16BitMode"]; }
                catch {}
                try{ port.SupportsDTRDSR = (bool)mbo["SupportsDTRDSR"]; }
                catch {}
                try
                {
                    port.SupportsElapsedTimeouts =
                        (bool)mbo["SupportsElapsedTimeouts"];
                }
                catch {}
                try{ port.SupportsIntTimeouts = (bool)mbo["SupportsIntTimeouts"]; }
                catch {}
                try{ port.SupportsParityCheck = (bool)mbo["SupportsParityCheck"]; }
                catch {}
                try{ port.SupportsRLSD = (bool)mbo["SupportsRLSD"]; }
                catch {}
                try{ port.SupportsRTSCTS = (bool)mbo["SupportsRTSCTS"]; }
                catch {}
                try
                {
                    port.SupportsSpecialCharacters =
                        (bool)mbo["SupportsSpecialCharacters"];
                }
                catch {}
                try{ port.SupportsXOnXOff = (bool)mbo["SupportsXOnXOff"]; }
                catch {}
                try{ port.SupportsXOnXOffSet = (bool)mbo["SupportsXOnXOffSet"]; }
                catch {}
                try{ port.StatusInfo = (SerialPortStatusInfo)mbo["StatusInfo"]; }
                catch {}
                // Fähigkeiten aus dem Capabilities-Array auslesen
                try
                {
                    uint[] caps = (uint[])mbo["Capabilities"];
                    for (int i = 0; i < caps.Length; i++)
                    {
                        switch (caps[i])
                        {
                        case 1:                                    // Other
                            port.Capabilities.Other = true;
                            break;

                        case 2:                                    // Unknown
                            port.Capabilities.Unknown = true;
                            break;

                        case 3:                                    // XT/AT Compatible
                            port.Capabilities.CompatibleXTAT = true;
                            break;

                        case 4:                                    // 16450 Compatible
                            port.Capabilities.Compatible16450 = true;
                            break;

                        case 5:                                    // 16550 Compatible
                            port.Capabilities.Compatible16550 = true;
                            break;

                        case 6:                                    // 16550A Compatible
                            port.Capabilities.Compatible16550A = true;
                            break;

                        case 160:                                  // 8251 Compatible
                            port.Capabilities.Compatible8251 = true;
                            break;

                        case 161:                                  // 8251FIFO Compatible
                            port.Capabilities.Compatible8251FIFO = true;
                            break;
                        }
                    }
                }
                catch {}

                // SerialPort-Instanz an die Auflistung anfügen
                ports.Add(port);
            }

            // Speicher des WMI-Objekts freigeben um den Arbeitsspeicher möglichst
            // schnell zu entlasten
            moc.Dispose();
            mc.Dispose();

            // Ergebnis zurückgeben
            return(ports);
        }