On Windows (XP-7), is there a reliable way of programatically differentiating between USB floppy drives and USB flash drives in C++?
At the moment, I'm using WMI to get updates when new Win32_LogicalDisk instances are detected, and then using the DriveType attribute of the LogicalDisk object to figure out a basic type. This works quite well, except that floppy drives and USB flash drives are both of DriveType DRIVE_REMOVABLE, so to differentiate between those (floppy vs. flash), I'm using the IOCTL_STORAGE_GET_HOTPLUG_INFO interface to figure out if the device is hotpluggable, and was working on the principal that that meant it was a flash drive and not a floppy. Again, I think this works quite well (if a little inefficient, using both the WDK API and WMI to get info ) in the case of internal floppy drives, but unfortunately USB Floppy drives are also hotpluggable a lot of the time, so there is no clear way to differentiate between flash and USB floppy drives, that I can see. I know there are properties that may work, like checking if its mapped to the reserved drives A: or B (edit: only relevant if the machine definitely has a floppy drive - see MS-KB: How to change drive letter assignments in Windows XP), or looking at the description, but I'd really like something a bit more reliable.
Sorry about the long explanation, but just wanted to be clear! Thanks
Did you try Win32_LogicalDisk.MediaType? It has specific enumerations for floppy disks. Make sure you try it when there's no disk in the drive.
On the USB level, there is no way to differentiate between a conventional Disk on Key and a USB-Floppy. Which means windows itself, cannot tell reliably what is what.
There are a few hints that you can gather:
Floppies should:
a. Have mass-storage protocol CBI/CB
b. SCSI UFI
BUT, in the world of USB devices, everyone does whatever they want. The only test is: "Does it work on windows". And Windows just checks the size, if its a USB device with removable-media set and with conventional floppy sizes, it will consider it to be a floppy.
Can't say about "real" floppy, but with the USB attached, there is no definite way.
You can use the Size attribute (USB > 1.4MB), it's not like there is any chance of meeting 1.4MB flash drive any time soon.
The obvious property to check would be IOCTL_DISK_GET_DRIVE_GEOMETRY. This gets you (amongst other things) a MEDIA_TYPE. Anything but RemovableMedia and FixedMedia is a floppy.
Related
I am looking for a piece of software, or assistance with where to start for coding, that will let you select a USB device and convert its output signals (when buttons are pressed on the device) into keystrokes or configurable macros.
In more detail, I have this remote control (more accurately, a USB handset/phone) that sends USB signals depending on which button is pressed and the software I currently use converts those signals into keystrokes or macros. The software I currently use however is extremely limited, non-configurable and obsolete. The software which I retrieved from the CD that the device came in is simply named 'USBPhone 5 in 1' however there is no mention of this anywhere on the internet.
The device is unfortunately unbranded and also has very little visibility on the internet so I cannot see if there's any updated software or even any way to edit it.
Any help is greatly appreciated!
I think you need to start by getting basic understanding of the USB standard and device classes. Then you need to find out if your device implements a specific device class or some proprietary interfaces. Then you will either need to use a driver for the device class or implement a proprietary driver.
While USB is abbreviation from Universal Serial Bus, it is not transferring some random analogue data but well defined digital packets. The standard defines Audio Class for audio devices, Video class for video devices etc. Most devices implement one or more of those classes. For keyboards and mouse it defines HID class, which is most likely what your device implements. You can find HID device class related specifications here. It is not the most simple one to begin with, but it should work when you just plug the device to your PC and open e.g. notepad and start writing. USB device class codes are listed here.
In order to find out what device class your device implements, you need to read it's descriptors. In Windows one of the easier ways is to use usbview. You can read more about USB decriptors from here.
You do not mention what is your USB host (Windows or Linux PC, Mac or something else), so I am not going to go into actual USB driver implementation, but hopefully I was able to give you some information on what could be needed. In any case, if the device has some proprietary implementation, you will either need to have specification for it, or reverse engineer it by monitoring the USB packets. There are lots of expensive hardware solutions on the market for analyzing the USB traffic, but there are also some free SW solutions that might be good enough for your purpose. Quick Googling brought up this.
You can try joyToKey, this software do exactly what you want but with gamedpad. I don't know if it will work well with your USB controller.
http://joytokey.net/en/
How can i programmatically eject USB Device even if it is in use?
Scenarios:
USB device attached to the system.
We get WM_DEVICECHANGE message by "RegisterDeviceNotification" through which we can handle events like DBT_DEVICEARRIVAL, DBT_DEVICEQUERYREMOVE etc.
Now if the device is in use, if we want to eject it from explorer, it prompts as "Problem Ejecting USB Mass Storage Device "This device is currently in use. Close any programs or windows that might be using the device, and then try again."
Question: 1: How can we eject USB without any prompt while it is in use?
Question: 2: How can we get notification when the user press eject from explorer for USB device ?
Thanks in advance :)
Well, you can't mechanically eject it. So what does it mean to software-eject it? It means that Windows will prevent any further handles to be created for files or directories. As a result, it's safe to remove the USB stick afterwards
Now what does it mean that the USB stick is in use? That just means there are open handles. It doesn't make a difference whether you prevent any further handles from being created. Removing a USB stick while there's a handle open means that you risk corrupting the content on the USB stick.
Therefore, it's not a matter of wanting to ejecting the USB stick while in use. The question simply makes no sense at all.
Note that Windows already tells you what you should in fact do: Close any programs or windows that might be using the device, and then try again.
Question two similarly does not make a lot of sense either. When disk F: is gone, why should you care about the details? After all, if you had reasons to care (e.g. open file), Windows would have blocked that operation.
I have looked at DADiskCopyDescription and enumerating IOUSBDevice from IOKit and neither provide me with the serial number of the USB hard drive. The latter provides a USB Serial number which is not equivalent to its hard drive serial number. How do I get that (in c/c++, NOT via the shell)?
What you are basically asking is "How do I directly communicate with a hard drive over USB?"
The answer is: It depends on the USB controller. Not all controllers support your request.
The following conditions must exist:
The USB bridge must support ATA pass-through (if ATA)
SCSI must be supported on the host OS
The OS must provide a SCSI pass-through API (Yes on Windows and Linux, No on MacOS X)
Another factor arises: Some controllers support drive manufacturer-independent passthroughs, but some support different commands based on the hard drive they are controlling. This also depends on whether the attached drive is PATA, SATA/SAS, or SCSI.
Examples of controllers that support at least one of the above include Sunplus SPIF215/6, SPIF225/6; JMicron JM20329, JM20335-39; and Cypress CY7C68300B/C (AT2LP), CY7C68310 (ISD-300LP).
Wish I had happier news for you.
I feel somewhat noob yet with this of getting the Information of Hardware of the CPU, so i come with this request: Hard Drive, CD/DVD/Bluray reader, Floppy and if it's possible USB.
I've been looking on MSDN GetDriveType but seems i'm bad at searching or i don't understand it. Any idea?
I'm not sure what you didn't understand about the documentation you linked to...
The sole argument accepted by the function is the root directory of the drive you want to get information about (including a trailing backslash). The function returns a value indicating which type of drive that is. A chart is shown that gives the possible return values and what each of them mean.
For example:
GetDriveType(_T("C:\\")) // returns DRIVE_FIXED if C:\ is my hard drive
GetDriveType(_T("A:\\")) // returns DRIVE_REMOVABLE if A:\ is my floppy drive
GetDriveType(_T("D:\\")) // returns DRIVE_CDROM if D:\ is a CD-ROM drive
GetDriveType(_T("N:\\")) // returns DRIVE_REMOTE if N:\ is a network drive
It also says that if you want to determine whether a drive is a USB-type drive, you need to call the SetupDiGetDeviceRegistryProperty function and specify the SPDRP_REMOVAL_POLICY property.
If you want to determine that a device is USB device, you can open its handle and send IOCTL queries using DeviceIoControl() to get bus type a device is connected to.
EnumUsbDrivesLetters - the post is in Russian but it contains C++ source code, so the matter could be understood easily.
Cheers, Andriy
The only all-in-one API I know of for Windows with that information is WMI, but it's not terribly simple to use. On the other hand, many programs communicate with devices directly, using pass-through control codes, or I/O control codes like SMART_RCV_DRIVE_DATA.
(I don't know how Speccy works, but I'm guessing it uses a combination of these methods to get the system info needed.)
I want to develop code to transmit data from system to PIC through USB.
Can anybody give good link regarding data transmission through USB.
because i am new to this.
NOTE: Very simple is code is enough to me.
Thanks in Advance
The PIC16F877 does not have a USB peripheral built in. I assume that the product that you are building is a "USB Device" and that the "system" that you are referring to will provide the USB host functionality. If this is the case then you will have to add a USB interface chip to your hardware to provide async serial to USB connectivity. Suitable devices are made by TI (TUSB series) or FTDI. You then connect one of these to the PIC internal USART and pretend that you are transferring the data over a simple serial port. If you are using a pc then the connected device will appear as a standard COMn: port.
I totally agree with the FTDI route, however if you're not looking for a UART tunnel over USB then you have to get a bit more in-depth.
You'll have to write the USB routines yourself or find libraries/projects for your processor. What you will definitely have to have is a fast clock - 12MHz is necessary More is better because on small uC's like these you'll spend most of your time just handling the basics of USB - signaling and so forth. You'll also need a fair bit of memory because the USB code takes up around 1.5K I think. Then you need room afterwards for your own code.
I've seen the V-USB (http://www.obdev.at/products/vusb/index.html). It's for AVR not PIC, but it says it provides all of the USB functionality you'll need and even provides vendor and product IDs for you to use (non-commercial I believe). There's also a PIC project for USB that doesn't run on the same hardware as yours here: http://www.alanmacek.com/usb/
To make the driver you'll have to use libusb - here's a link for the win32 version: http://libusb-win32.sourceforge.net/
It's surprisingly more simple than I had expected, but I just looked at example code and not actually made anything. Good luck!
As your task will involve Windows Device Driver development, I do recommend to downlaod and install the WDK and look through the contained sample USB drivers.
This might get you some hints about the complexity of the topic. Device driver development is not the easiest thing to start with.
Maybe you can start with UART communication (RS232).
check http://www.beyondlogic.org/usbnutshell/pic16f876.gif will surely help u
also
ttp://www.beyondlogic.org/usbnutshell/usb7.htm , type h in front of 2nd link.