EJW Posted May 4, 2007 Report Share Posted May 4, 2007 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. Quote Link to comment
Yair Posted May 4, 2007 Report Share Posted May 4, 2007 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. Quote Link to comment
hooovahh Posted May 5, 2007 Report Share Posted May 5, 2007 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. Quote Link to comment
Yair Posted May 6, 2007 Report Share Posted May 6, 2007 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. Quote Link to comment
Ton Plomp Posted May 6, 2007 Report Share Posted May 6, 2007 A better polling way is a list folder with an empty path. The folder array will have a list of all the mounted volumes, if the size changes something happened to the volumes! Ton Quote Link to comment
cosmin Posted May 8, 2007 Report Share Posted May 8, 2007 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 Quote Link to comment
hooovahh Posted May 8, 2007 Report Share Posted May 8, 2007 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. Quote Link to comment
Dirk J. Posted May 8, 2007 Report Share Posted May 8, 2007 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. Quote Link to comment
cosmin Posted May 8, 2007 Report Share Posted May 8, 2007 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 Quote Link to comment
jbrohan Posted August 2, 2007 Report Share Posted August 2, 2007 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 Quote Link to comment
Clement Yap Posted September 19, 2008 Report Share Posted September 19, 2008 QUOTE (cosmin @ May 7 2007, 08:01 PM) Hi,here is a sample which looks at usb devices connected. It uses .NET. cosmin Hi Cosmin, May I have your sample in labview 7.1? Thanks Clement Quote Link to comment
goran Posted November 11, 2008 Report Share Posted November 11, 2008 QUOTE (cosmin @ May 7 2007, 01:01 PM) Hi,here is a sample which looks at usb devices connected. It uses .NET. cosmin Can anyone save this example in LW 7.1? Quote Link to comment
Val Brown Posted January 15, 2009 Report Share Posted January 15, 2009 QUOTE (cosmin @ May 7 2007, 04:01 AM) Hi,here is a sample which looks at usb devices connected. It uses .NET. cosmin If one were to use a version of this in a deployed, built EXE, what dependencies would need to be included in the build spec? Quote Link to comment
Val Brown Posted January 15, 2009 Report Share Posted January 15, 2009 QUOTE (cosmin @ May 7 2007, 04:01 AM) Hi,here is a sample which looks at usb devices connected. It uses .NET. cosmin If one were to use a version of this in a deployed, built EXE, what dependencies would need to be included in the build spec? Quote Link to comment
Val Brown Posted January 15, 2009 Report Share Posted January 15, 2009 QUOTE (Val Brown @ Jan 14 2009, 01:47 PM) If one were to use a version of this in a deployed, built EXE, what dependencies would need to be included in the build spec? I solved this another way. No need for further follow up. Quote Link to comment
Val Brown Posted January 15, 2009 Report Share Posted January 15, 2009 QUOTE (Val Brown @ Jan 14 2009, 01:47 PM) If one were to use a version of this in a deployed, built EXE, what dependencies would need to be included in the build spec? I solved this another way. No need for further follow up. Quote Link to comment
gomez1 Posted January 21, 2009 Report Share Posted January 21, 2009 (edited) 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 August 30, 2017 by hooovahh Please don't advertise your for sale domain or dating site Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.