Solved

help in COM port identification using PCMCIA card

Posted on 2008-06-17
15
683 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

635 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