Jump to content

Detect USB Flash Drive


EJW

Recommended Posts

I don't know how to recognize that, although I wouldn't be surprised if you can register for a .NET event for something like this. I would suggest searching Microsoft's site for that.

Another option is to poll the drive list (using the List Directory VI), but that is far from elegant as you would need to recognize that the new drive in the list is really your USB drive. I suppose you could search the new drive for a file\dir of a prespecified name..

One thing I do know is how to set up your program to be the default program to run when the drive is plugged in. See here.

Link to comment

Yes the easiest (and ugliest) solution I would suggest, is similar to what you said.

If the machine you are plugging it into is very controlled, meaning you're not constantly plugging USB drives, and installing new drives, I guess you could have it in a while loop, trying to get the file size of say F:\autorun.inf or some thing on the USB drive. It would return an error until the drive and file exists.

That would be wasting alot of resources even if the while loop only ran once a second. It would have to be event driven since it could go hours, or days before being plugged in.

Also another suggestion that you might want to look into is you could have the VI do some thing similar to "Wait Until Active" (which I don't know how to implement) Because as I'm sure you already know, when you plug in a USB drive that auto run menu opens. I don't know if LabVIEW supports it or not but you could create an event that does nothing until that auto run window is active then do stuff.

Link to comment

BTW, I don't think the polling method is that ugly.

It is relatively complicated, wasteful and it has a potential for errors (you have to have a way to recognize the drive), which is why I don't like it, but the basic act of polling once every second is two is not so bad. The computer should be able to handle it even if it goes on for days or weeks. That is essentially how Windows recognizes that you have plugged in a USB device.

Link to comment

QUOTE(EJW @ May 3 2007, 10:58 PM)

Anyone know of a way to detect when a USB flash drive has been inserted?

I was thinking of using that as a way to do automatic updates to existing programs.

Hi,

here is a sample which looks at usb devices connected. It uses .NET.

cosmin

Link to comment

I'm not trying to flame you but isn't rule number 1 of LabVIEW to have data flow from left to right? Maybe you were in a hurry, but I found it difficult to understand what was happening in your VI because information didn't flow.

Also there were no comments. What is Count? is it simply the number of rows in the array? What is Count good for? What version of LabVIEW was it made with? Why is there a random constant of "0" in the middle of the while loop which isn't wired to any thing?

Answering any of these would be greatly appriciated.

I'd also be glad to show you where you code could be improved if you'd like.

Link to comment

QUOTE(hooovahh @ May 7 2007, 04:08 PM)

I'm not trying to flame you but

Also there were no comments. What is Count? is it simply the number of rows in the array? What is Count good for? What version of LabVIEW was it made with? Why is there a random constant of "0" in the middle of the while loop which isn't wired to any thing?

Actually, I think you are flaming.

Labview code is more readible if it flows from left to right, but as ActiveX and .Net nodes tend to take up a lot of screen real estate, it is sometimes more convienient to have nodes placed topleft to rightbottom. So sometimes, data will flow from right to left. An alternative would be to hide full names, but that would decrease the quite extensive self-documentation of these nodes. And there's always MSDN.

You can always 'clean up wires' and use highlighted execution if you're in doubt. If it doesn't open up in your LV version, was made in a newer one.

Cosmin provided a quick solution to the problem, not submit something to the code repository.

Link to comment

QUOTE(hooovahh @ May 7 2007, 05:08 PM)

I'm not trying to flame you but isn't rule number 1 of LabVIEW to have data flow from left to right? Maybe you were in a hurry, but I found it difficult to understand what was happening in your VI because information didn't flow.

Also there were no comments. What is Count? is it simply the number of rows in the array? What is Count good for? What version of LabVIEW was it made with? Why is there a random constant of "0" in the middle of the while loop which isn't wired to any thing?

Answering any of these would be greatly appriciated.

I'd also be glad to show you where you code could be improved if you'd like.

Hi,

the good thing that comes with these forums is to get started in solving something that you get stuck in, not to expect someone to spend his time to fully solve your problems.

If you looked in the block diagram smartly, you could figure out that "count" shows how many usb devices exists, so testing it is usefull to see if something changed in the system (so the rest of the code can be placed in some case structure).

If you want to know more, please read msdn.

cosmin

Link to comment
  • 2 months later...

QUOTE(EJW @ May 3 2007, 03:58 PM)

Anyone know of a way to detect when a USB flash drive has been inserted?

I was thinking of using that as a way to do automatic updates to existing programs.

This is a very interesting idea. I have been fiddling with USB memory sticks lately and found that there is a program which executes when a USB memory device is plugged in. There is one in Windows XP and there is a commercial one with my digital Camera. I don't know how to write these programs, but there are examples out there. The examples I report just show the contents of the USB memory.

Please let this group know if you find out more about this!

John

Link to comment
  • 1 year later...
  • 1 month later...
  • 2 months later...

Hi EJW,i have read your post.When you inserted USB there will be a automatic updates for you.You don't need ant specific software and all.I have been using USB flash drive for years.I didn't experience any problem.

---------------------------

gomez

Edited by hooovahh
Please don't advertise your for sale domain or dating site
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.