Solved

help in COM port identification using PCMCIA card

Posted on 2008-06-17
15
670 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WPF - Tooltips for ComboBox items 5 70
Advice in Xamarin 21 79
Run a batch file when a Crystal Report is opened 5 27
get column names from table in vb.net 8 28
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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

770 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