Solved

help in COM port identification using PCMCIA card

Posted on 2008-06-17
15
675 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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