Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Find a device connected to a usb-port

Hi,

I have device connected to a usb-port, that you see in the picture.
I have some code to detect the name of the device but its not working
The code doesn't detect the device.

I get an IOExecption with a message:
"Device not ready"

Who knows the answer and is willing to help me?

Peter Kiers
private void button1_Click(object sender, EventArgs e)
        {
           foreach (System.IO.DriveInfo di in System.IO.DriveInfo.GetDrives())
          {
              if (di.VolumeLabel.Equals("SmartPix", StringComparison.InvariantCultureIgnoreCase))
              {
                  MessageBox.Show("Device found");
                  if (System.IO.Directory.GetFiles(@"\REPORT\XML", "G*.xml").Length > 0)
                  {
                      MessageBox.Show("File found");
                  }
              }
         }
       }

Open in new window

Example1.jpg
Avatar of mrRany
mrRany

You are scanning all logical drives include CD-ROM, DVD-ROM etc..
In order to exclude it you can just use

using System.Linq;

Open in new window

IEnumerable<DriveInfo> drives = DriveInfo.GetDrives().Where(d => d.DriveType != DriveType.CDRom);

Open in new window

Also you can exclude other unwanted  drive types that are in DriveType list.
Avatar of Peter Kiers

ASKER

Can you give me a little example how to find the device called SmartPix.

Peter
ASKER CERTIFIED SOLUTION
Avatar of mrRany
mrRany

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx.P
Great, wish you good luck ans thank you.