Solved

help in COM port identification using PCMCIA card

Posted on 2008-06-17
15
664 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now