/// <summary> /// Retourne la liste des ports série win32 /// </summary> public static List<CWin32SerialPort> GetListWin32SerialPort() { ConnectionOptions options = ProcessConnection.ProcessConnectionOptions(); ManagementScope connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, @"\root\CIMV2"); ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM win32_serialport "); ManagementObjectSearcher win32SerialPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery); // Liste des ports série List<CWin32SerialPort> win32SerialPortList = null; using (win32SerialPortSearcher) { foreach (ManagementObject obj in win32SerialPortSearcher.Get()) { if (win32SerialPortList == null) { win32SerialPortList = new List<CWin32SerialPort>(); } // Création du port CWin32SerialPort win32SerialPort = new CWin32SerialPort(); win32SerialPort.Name = obj["Name"].ToString(); win32SerialPort.Description = obj["Description"].ToString(); win32SerialPort.Caption = obj["Caption"].ToString(); win32SerialPort.DeviceID = obj["DeviceID"].ToString(); win32SerialPort.PNPDeviceID = obj["PNPDeviceID"].ToString(); // Ajout à la liste des ports série win32SerialPortList.Add(win32SerialPort); } } return win32SerialPortList; } // public static List<CWin32SerialPort> GetListWin32SerialPort()
/// <summary> /// Clone /// </summary> public CWin32SerialPort Clone() { CWin32SerialPort win32SerialPort = new CWin32SerialPort(Name, Description, DeviceID, Caption, PNPDeviceID); return win32SerialPort; }