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.
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.
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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With