09-07-2010 05:03 PM
I have a device that when connected via USB, it will appear, then go away then reappear. When the device is finally ready, Windows pops up with its little balloon ready stating that its ready.
I am trying to access it but do not want to attempt until after it reappears, or when its ready. And a simple delay is not very reliable.
Is there a good way to detect if a USB device is "ready for use"?
09-08-2010 09:55 AM
Hello ngay528,
If you are doing this in CVI and you are using a VISA resource you can use the viFindRsrc command.
viFindRsrc:
Matches the value specified in Expression with all known instruments. On successful completion, the Return Count is the total number of matches and the Instrument Descriptor is the descriptor string for the first instrument that matches Expression. The Instrument Descriptor can be used to open an instrument with the viOpen operation. The Find Handle can be used in subsequent calls to the viFindNext operation to retrieve descriptor strings for the remaining instruments that were found.
This operation applies to VISA resource manager sessions only.
/*-------------------- Prototype ---------------------*/ViStatus viFindRsrc (ViSession Rsrc_Manager_Handle, ViString Expression, ViPFindList Find_Handle, ViPUInt32 Return_Count, char Instrument_Descriptor[]);
You can then set up code to wait until the resource you are looking for is ready and then open a session to it. Let me know if this helps out and have a great day!
Best Regards,
Adam G
09-08-2010 10:15 AM
A few more questions....
I am not familiar with VISA very well just yet. I don't understand how this would work with Drive Letters. My current situation is that I plug a USB Device in. It appears as Drive E. Then disappaears then reappears (possibly as Drive E or a different letter-crazy but seen it happen).
What i do know is volume name that it will come up as.
So if I can somehow figure how if the Drive is ready for access, that would be great. Main reason is that I plan to automatically parse the directories and copy files off it it.
Thanks
09-09-2010 09:33 AM
Sorry for the confusion. I thought you were trying to access a USB device instead of a drive. Using VISA will not work out for this. You are going to have to use the Windows SDK functions in order to get this to work. One suggestion is to use GetLogicalDrivesStrings. This function will return an array of all the device names. You can loop through this until you get a string that matches the drive you are looking for. Let me know if this helps out and have a great day!
Best Regards,
Adam G
09-09-2010 09:38 AM
Would you recommend a good way of "checking" to see if a device is ready?
Otherwise I would just be sure to error Check every call to that drive and retry X amount of times or for a certain time frame.
Thanks
09-10-2010 09:06 AM
I don't believe you will be getting any error codes because this will return all the logical drives on your computer, including your C drive. You can keep calling this command and parsing through it until you match the string you are looking for. Have a great day!
Best Regards,
Adam G
09-10-2010 09:10 AM
Looks like I just need the kernel32.lib and WinBase header.
the two functions i will probbaly end up using are GetLogicalDrivenames and GetvolumeInformation or some form of those.
Since each drive connected will have a specific id or identifier, I can always retry if it failed. Doing so, i will just enclose all function calls to the drive in a specific error checking function (similar to checkErr)