Get the device name connected to the serial port

前端 未结 4 846
再見小時候
再見小時候 2021-01-01 18:36

I search how to get the device name of the material connected to the serial port.

I\'ve two different types of material that can connect on it.

First one : a

相关标签:
4条回答
  • 2021-01-01 19:08
    static void Main(string[] args)
    {
        ManagementObjectCollection ManObjReturn;
        ManagementObjectSearcher ManObjSearch;
        ManObjSearch = new ManagementObjectSearcher("Select * from **Win32_ParallelPort**");
        ManObjReturn = ManObjSearch.Get();
    
        foreach (ManagementObject ManObj in ManObjReturn)
        {
            //int s = ManObj.Properties.Count;
            //foreach (PropertyData d in ManObj.Properties)
            //{
            //    MessageBox.Show(d.Name);
            //}
            Console.WriteLine(ManObj["DeviceID"].ToString());
            Console.WriteLine(ManObj["PNPDeviceID"].ToString());
            Console.WriteLine(ManObj["Name"].ToString());
            Console.WriteLine(ManObj["Caption"].ToString());
            Console.WriteLine(ManObj["Description"].ToString());
            Console.WriteLine(ManObj["ProviderType"].ToString());
            Console.WriteLine(ManObj["Status"].ToString());
    
        }
    
    }
    

    http://www.seeques.com/20766280/the-port-name-is-illegal-or-couldnt-be-connected-to-the-device.html

    the port name is illegal how is an error message like that...fio.!

    0 讨论(0)
  • 2021-01-01 19:12

    try this:

            ManagementObjectCollection ManObjReturn;
            ManagementObjectSearcher ManObjSearch;
            ManObjSearch = new ManagementObjectSearcher("Select * from Win32_SerialPort");
            ManObjReturn = ManObjSearch.Get();
    
            foreach (ManagementObject ManObj in ManObjReturn)
            {
                //int s = ManObj.Properties.Count;
                //foreach (PropertyData d in ManObj.Properties)
                //{
                //    MessageBox.Show(d.Name);
                //}
                MessageBox.Show(ManObj["DeviceID"].ToString());
                MessageBox.Show(ManObj["PNPDeviceID"].ToString());
                   MessageBox.Show(ManObj["Name"].ToString());
                   MessageBox.Show(ManObj["Caption"].ToString());
                   MessageBox.Show(ManObj["Description"].ToString());
                   MessageBox.Show(ManObj["ProviderType"].ToString());
                   MessageBox.Show(ManObj["Status"].ToString());
    
            }
    
    0 讨论(0)
  • 2021-01-01 19:31
    Class1 UD = new Class1();
    {
    string strUserAgent = Request.UserAgent.ToLower();
            if (strUserAgent != null)
            {
                string Browser = Request.Browser.Browser;
                string a = Request.Browser.MobileDeviceManufacturer;
                string b = Request.Browser.MobileDeviceModel;
                string c = Request.Browser.Platform;
                string d = Request.Browser.Type;
                string e = Request.Browser.Version;
    
                UD.Browser = Browser;
                UD.MobileDeviceModel = b;
                UD.MobileDeviceManufacturer = a; 
                UD.Platform2 = c;
                UD.Type = d;
                UD.Version2 = e; 
    
    
    
    
                if (Request.Browser.IsMobileDevice == true || strUserAgent.Contains("iphone") ||
                         strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") ||
                         strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") ||
                         strUserAgent.Contains("palm"))
                {
                    UD.deviceType = "Request from Mobile Device";
                }
                else
                {
                    UD.deviceType = "Request from Computer";
                }
    
            }
    }
    
    0 讨论(0)
  • 2021-01-01 19:33

    There is no univeral way of identifying serial port (UART RS232) devices.

    Unless the devices have special commands that you can send to the device and have it respond with identifying information there is not much you can do.

    Typically application that rely on the serial port will have a standard setting screen that the user would use to configure the serial port the device is connected to, port configuration for things like baud rate, parity bits, stop bits and data bits. If mutiple devices can be switched on the same port, the operator would then be responsible for selecting the correct configuration for the target device before communicating with the device.

    This is the advantage of newer technologies like USB etc. where device identification is built into the standard.

    0 讨论(0)
提交回复
热议问题