示例#1
0
        public static Dictionary <string, string> GetComList()
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            RegistryKey keyCom = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");

            if (keyCom != null)
            {
                string[] sSubKeys = keyCom.GetValueNames();
                foreach (string sName in sSubKeys)
                {
                    string sValue = (string)keyCom.GetValue(sName);
                    try {
                        bool b = SerialPortTran.IsTheDevice(sValue);
                        if (b)
                        {
                            result.Add(sValue, sName);
                        }
                    }
                    catch (Exception ex)
                    {
                        _tracing.Error(ex, "failed to GetComList ." + sValue);
                    }
                }
            }
            return(result);
        }
示例#2
0
        public static string GetOneCom()
        {
            if (SerialPortTran.IsTheDevice(FirstCom))
            {
                return(FirstCom);
            }

            {
                string[] sValues = SerialPort.GetPortNames(); // keyCom.GetValueNames();
                foreach (string sValue in sValues)
                {
                    if (sValue != FirstCom)
                    {
                        try
                        {
                            bool b = SerialPortTran.IsTheDevice(sValue);
                            if (b)
                            {
                                FirstCom = sValue;
                                return(sValue);
                            }
                        }
                        catch (Exception ex) {
                            _tracing.Error(ex, "failed to try connect and send test ." + sValue);
                        }
                    }
                }
            }
            return("");
        }
示例#3
0
        private static Dictionary <string, string> test2()
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            string[] spname = SerialPort.GetPortNames();



            if (spname.Length > 0)
            {
                foreach (string spName in spname)
                {
                    result.Add(spName, spName);//得到所有串口号
                    try
                    {
                        bool b = SerialPortTran.IsTheDevice(spName);
                    }
                    catch { }
                }
            }
            return(result);
        }