Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the device name connected to the serial port

Tags:

c#

serial-port

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 printer (only receives data and send nothing back) Second one : a balance (only send data and receives nothing)

How can I distinguish this two types of material?

Thanks.

like image 287
Arnaud F. Avatar asked Dec 21 '10 14:12

Arnaud F.


2 Answers

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.

like image 31
Chris Taylor Avatar answered Oct 19 '22 22:10

Chris Taylor


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());

        }
like image 94
mahendra apte Avatar answered Oct 19 '22 22:10

mahendra apte