Пример #1
0
    public void OpenDevices01()
    {
        DosDevices dosDevices       = new DosDevices();
        Regex      comPortNameRegex = new Regex(@"com\d{1,3}", RegexOptions.IgnoreCase);

        foreach (KeyValuePair <string, string> keyValuePair in dosDevices)
        {
            if (!string.IsNullOrEmpty(keyValuePair.Key) && !comPortNameRegex.IsMatch(keyValuePair.Key))
            {
                using (SerialPort com1 = new SerialPort(keyValuePair.Key))
                {
                    Debug.WriteLine($"Checking exception thrown with Key {keyValuePair.Key}");
                    Assert.ThrowsAny <Exception>(() => com1.Open());
                }
            }

            if (!string.IsNullOrEmpty(keyValuePair.Value) && !comPortNameRegex.IsMatch(keyValuePair.Key))
            {
                using (SerialPort com1 = new SerialPort(keyValuePair.Value))
                {
                    Debug.WriteLine($"Checking exception thrown with Value {keyValuePair.Value}");
                    Assert.ThrowsAny <Exception>(() => com1.Open());
                }
            }
        }
    }
Пример #2
0
 public PortName_Property()
 {
     if (IsWinXPOrHigher())
     {
         _dosDevices = new DosDevices();
     }
     else
     {
         _dosDevices = null;
     }
 }
Пример #3
0
    public static void Main()
    {
        DosDevices dosDevices = new DosDevices();

        foreach (KeyValuePair <string, string> keyValuePair in dosDevices)
        {
            Console.WriteLine("'{0}'='{1}'", keyValuePair.Key, keyValuePair.Value.Trim());
        }

        Console.WriteLine("CommonNameExists(\"LPT1\")={0}", dosDevices.CommonNameExists("LPT1"));
        Console.WriteLine("CommonNameExists(\"A:\")={0}", dosDevices.CommonNameExists("A:"));

        Console.WriteLine("CommonNameExists(\"LPT\")={0}", dosDevices.CommonNameExists("LPT"));

        string s = dosDevices["LPT1"];

        for (int i = 0; i < s.Length; ++i)
        {
            Console.WriteLine("{0}({1})", (int)s[i], s[i]);
        }
    }
Пример #4
0
    public bool OpenDevices01()
    {
        DosDevices dosDevices       = new DosDevices();
        Regex      comPortNameRegex = new Regex(@"com\d{1,3}", RegexOptions.IgnoreCase);
        bool       retValue         = true;

        foreach (KeyValuePair <string, string> keyValuePair in dosDevices)
        {
            SerialPort com1;

            if (!string.IsNullOrEmpty(keyValuePair.Key) && !comPortNameRegex.IsMatch(keyValuePair.Key))
            {
                com1 = new SerialPort(keyValuePair.Key);
                try
                {
                    com1.Open();
                    Console.WriteLine("Error <KEY> no exception thrown with {0}", keyValuePair.Key);
                    retValue = false;
                    com1.Close();
                }
                catch (Exception) { }
            }

            if (!string.IsNullOrEmpty(keyValuePair.Value) && !comPortNameRegex.IsMatch(keyValuePair.Key))
            {
                com1 = new SerialPort(keyValuePair.Value);
                try
                {
                    com1.Open();
                    Console.WriteLine("Error <VALUE> no exception thrown with {0}", keyValuePair.Value);
                    retValue = false;
                    com1.Close();
                }
                catch (Exception) { }
            }
        }

        return(retValue);
    }
Пример #5
0
 public PortName_Property()
 {
     _dosDevices = new DosDevices();
 }