Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. USB Device search

USB Device search

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blubbo
    wrote on last edited by
    #1

    I'm coming up with a different way than the one I previously posted with subject "usb device in use". I've enumerated the usb device, while filtering out the usb device with vendor & product id. These devices are not volume type (i.e. thumb drives, external hard drives, etc). It is the communication box that communicates with RFID. I've acquired these usb path from 2 devices from List: [0] = "\\\\?\\hid#vid_0483&pid_0003#8&374204f5&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}" [1] = "\\\\?\\hid#vid_0483&pid_0003#8&f40948&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}" From what I can see and understand that these numbers "374204f5" and "f40948" are serial numbers. The question is on how do I acquire these serial numbers using one of those USB methods? Or I would just find through string.substring method? I was looking online and saw WMI class. I couldn't figure out which Win32 class to use. Most examples online I could find are for volume drives P.S. If you want me to post the code, I would be glad to.

    D 1 Reply Last reply
    0
    • B Blubbo

      I'm coming up with a different way than the one I previously posted with subject "usb device in use". I've enumerated the usb device, while filtering out the usb device with vendor & product id. These devices are not volume type (i.e. thumb drives, external hard drives, etc). It is the communication box that communicates with RFID. I've acquired these usb path from 2 devices from List: [0] = "\\\\?\\hid#vid_0483&pid_0003#8&374204f5&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}" [1] = "\\\\?\\hid#vid_0483&pid_0003#8&f40948&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}" From what I can see and understand that these numbers "374204f5" and "f40948" are serial numbers. The question is on how do I acquire these serial numbers using one of those USB methods? Or I would just find through string.substring method? I was looking online and saw WMI class. I couldn't figure out which Win32 class to use. Most examples online I could find are for volume drives P.S. If you want me to post the code, I would be glad to.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Be careful...What you're calling a serial number CAN be the device serial number IF it's in the hardware and can be picked up by PnP. If not, a serial number is randomly generated. So, what you see here might be the actual serial number of the device, or it may not. There is no way to tell from the device instance path. Also, plugging the exact same device into a different post will assign it a different serial number if its not available. You really have to explain what your doing and why. Just by looking at this post and your last one, "usb device in use", there's no way to determine what the goal of all this is.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      B 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Be careful...What you're calling a serial number CAN be the device serial number IF it's in the hardware and can be picked up by PnP. If not, a serial number is randomly generated. So, what you see here might be the actual serial number of the device, or it may not. There is no way to tell from the device instance path. Also, plugging the exact same device into a different post will assign it a different serial number if its not available. You really have to explain what your doing and why. Just by looking at this post and your last one, "usb device in use", there's no way to determine what the goal of all this is.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        B Offline
        B Offline
        Blubbo
        wrote on last edited by
        #3

        What I was trying to do is to have my software to connect up to 4 USB Communication Box. This box would communicate with RFID tag. In some cases, the USB box would somehow loses connection and the software would detect the loss of communication to the box. Also that when the USB box is reconnected, the software would re-connect and re-communicate again. This software would ensure that the "address" would be unique from other 3 USB devices. here's my sample code

        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Text;
        using System.Windows.Forms;

        using HID_API_Library;
        using System.Security.Permissions;

        namespace USB_Device_Connect_Disconnect_Test
        {
        public partial class Form1 : Form
        {
        /// /// Windows Messages
        /// Defined in winuser.h from Windows SDK v6.1
        /// Documentation pulled from MSDN.
        /// For more look at: http://www.pinvoke.net/default.aspx/Enums/WindowsMessages.html
        ///
        public enum WM : uint
        {
        /// /// Notifies an application of a change to the hardware configuration of a device or the computer.
        ///
        WM_DEVICECHANGE = 0x0219,
        WM_PARENTNOTIFY = 0x0210,
        DBT_DEVTYP_DEVICEINTERFACE = 5,
        DBT_DEVTYP_HANDLE = 6,
        DBT_DEVICEARRIVAL = 0x8000, // system detected a new device
        DBT_DEVICEQUERYREMOVE = 0x8001, // Preparing to remove (any program can disable the removal)
        DBT_DEVICEREMOVECOMPLETE = 0x8004, // removed
        DBT_DEVTYP_VOLUME = 0x00000002, // drive type is logical volume
        DBT_DEVNODES_CHANGED = 7, // device changed
        BROADCAST_QUERY_DENY = 0x424D5144,

            }
            
            // initilized bytes had to be removed for public post.
            byte\[\] Read\_Input = new byte\[9\];
            byte\[\] DeviceFirmwareVersion = new byte\[9\];
            byte\[\] inputReport = new byte\[9\];
        
            HID\_API\[\] hid = new HID\_API\[4\];
        
            GroupBox\[\] gbDevice = new GroupBox\[4\];
            List usbDevices;
        
            public Form1()
            {
                InitializeComponent();
                MonitorUSBDevices();
            }
        
            int ReadPort(int deviceID, ref byte data)
            {
                int status = hid\[deviceID\].ExchangeInputAndOutputReports(ref Read\_Input, ref inputReport, deviceID);
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups