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
LVL 1
peterkiersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mrRanyCommented:
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.
0
peterkiersAuthor Commented:
Can you give me a little example how to find the device called SmartPix.

Peter
0
mrRanyCommented:
DriveInfo drive = DriveInfo.GetDrives().Single(d => d.DriveType == DriveType.Removable && d.VolumeLabel == "SmartPix");

            Console.WriteLine(drive.VolumeLabel ?? "Drive is not found");

            Console.ReadKey();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peterkiersAuthor Commented:
Thanx.P
0
mrRanyCommented:
Great, wish you good luck ans thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.