Solved

help in COM port identification using PCMCIA card

Posted on 2008-06-17
15
673 Views
Last Modified: 2008-06-25
I have written a code in vb.net to get the guid for all the ports in the device manager, get the device id connected to each com port, enumerate the ports and see whether the vendor id and product id which i  get from the pci card matches with any of them in the com port.if so  send at commands

i am getting the guid for the ports using the class SetDiGetGuidfromClassName function. In this function I pass the class name such as "Ports" / "PCI" etc to get the guid.i tried callign this function and that is returning a  guid in this formant 0000-0000-000-00000 basically a null string.
What might be the issue?

Cheers,
YH
0
Comment
Question by:yaminihari
  • 8
  • 7
15 Comments
 
LVL 11

Expert Comment

by:William
ID: 21802994
First are you using the 1.1 or 2.0 or??  framework?

Second, the easiest way to get all the valid ports is (in 2.0)

string[] theSerialPortNames = System.IO.Ports.SerialPort.GetPortNames();

this is c# so vb(ish I think)
Dim theSerialPortNames As String() = System.IO.Ports.SerialPort.GetPortNames()

You can alos get the registry data for all available com ports in the
'HKLM\Hardware\DeviceMap\SerialComm' reg path...
0
 

Author Comment

by:yaminihari
ID: 21804883
Hi BillyDvD,
   Thanks for the reply , i guess i need to get the device Id associated with the com port. I am using .net framework 2.0.
0
 

Author Comment

by:yaminihari
ID: 21814156
is there a way to get the DEVICE ID associated with each COM ports in vb.net?
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 11

Expert Comment

by:William
ID: 21814294
I am curious as to why you NEED the device id, NO TWO COM PORTS can have the same name so.... ????
0
 

Author Comment

by:yaminihari
ID: 21819948
Hi BillyDVD,
I have a device inserted into a com port and I need to find out which com port it is present. So what I do is get the device id and compare it with the device ids of all the devices in the com port. This is the scenario. Many thanks
0
 
LVL 11

Expert Comment

by:William
ID: 21821937
DO you have multiple devices attactched to ONE com port?
0
 
LVL 11

Expert Comment

by:William
ID: 21822133
BTW: When you use WMI to retrieve the 'DEVICE ID' of a serial port...  It returns the serial port name (EX: COM3)....
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_SerialPort",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_SerialPort instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "DeviceID: " & objItem.DeviceID
Next

Open in new window

0
 

Author Comment

by:yaminihari
ID: 21822705
Hi BillyDvd, first of all many thanks for your reply.
I dont have multiple devices. It is a pcmcia card which i insert into the slot. I need to get the device id of the card or I need to get the com port to which the card is attached to. I have used Win32_pcmciacontroller class but it gives the device id of the pcmcia bus controller and not the card. I assume even the Win32_serialport class will return the device id of the com port and not the device attached to the com port. Thanks once again for your input.  
0
 
LVL 11

Expert Comment

by:William
ID: 21823266
OK - Maybe this will help in the ID(ish) you are looking for...

This returns on mine:
PNPDeviceID: HDAUDIO\FUNC_02&VEN_14F1&DEV_2BFA&SUBSYS_103C309F&REV_0900\4&4B994D5&0&0102
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_SerialPort WHERE PNPDeviceID = 'HDAUDIO\\FUNC_02&VEN_14F1&DEV_2BFA&SUBSYS_103C309F&REV_0900\\4&4B994D5&0&0102'",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_SerialPort instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
Next

Open in new window

0
 

Author Comment

by:yaminihari
ID: 21828980
Hi Billy,
I tried it but it doesnt work becoz PNPDeviceID from Win32_SerialPort gives the device id of the bus controller.I need to get the device id of the pcmcia card. That's my main task now. All the information available is giving me the device id of the pcmcia controller bus and not the card itself.
0
 
LVL 11

Expert Comment

by:William
ID: 21830924
DO you know what driver loads the card?
0
 
LVL 11

Expert Comment

by:William
ID: 21830975
I do not have any pcmcia cards loaded in my machine (I do have a slot).....
So I am only stabbing at this .....
using System;
using System.Management;
using System.Windows.Forms;
 
namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher = 
                    new ManagementObjectSearcher("root\\CIMV2", 
                    "SELECT * FROM Win32_PnPEntity"); 
 
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Win32_PnPEntity instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}

Open in new window

0
 

Author Comment

by:yaminihari
ID: 21844795
hi billy,
sorry it doesnt work. but i have a pointer, pcmcia_socket_information structure which returns the port number of the pcmcia. any idea about it?
0
 
LVL 11

Accepted Solution

by:
William earned 500 total points
ID: 21847137
OK - I finally got a hold of a PCMCIA device....
I can alot of values using the following :

You can call it like:
WMI_Helper.GetDeviceIDs ids = new WMI_Helper.GetDeviceIDs();
            foreach ( string str in ids.DeviceID( "PCMCIA" ) )
            {
                Console.WriteLine( str );
            }

using System;
using System.Management;
using System.Windows.Forms;
using System.Collections.Generic;
 
namespace WMI_Helper
{
    public class GetDeviceIDs
    {
        public List<  string > DeviceID( string Contains )
        {
            List<string> list = new List<string>();
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher( "root\\CIMV2" , "SELECT * FROM Win32_SerialPort" );
 
                foreach ( ManagementObject queryObj in searcher.Get() )
                {
                    string s = String.Format( "PNPDeviceID: {0}" , queryObj[ "PNPDeviceID" ] );
                    if ( s.Contains( Contains ) )
                        list.Add( s );
                }
 
                return list;
            }
            catch ( ManagementException e )
            {
                MessageBox.Show( "An error occurred while querying for WMI data: " + e.Message );
            }
 
            return list;
        }
    }
}

Open in new window

0
 

Author Comment

by:yaminihari
ID: 21870231
Hi Billy,
Sorry for the late response, this still will return the device id of the serial port and not the pcmcia card. I found another way round. I opened the registry and I read the com port value for the pcmcia card.  I am going to award the points for you for the effort you have taken with this issue and am sure this will be so useful for beginners like me. Many thanks, A+ for effort.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question