How to determine if a GPS device is a built-in receiver - c#

We have an C#-application for Windows which makes use of data from a USB-connected GPS receiver. In the last year or so, many users have started to complain about bad quality of the position- and velocity data.
After some investigation, we realized that many new laptops have a built-in GPS receiver, which seems to be of quite low quality, and does not have the antenna in an optimal position.
Our application automatically checks the COMx ports for a GPS receiver, and selects the first one it finds. We would like to keep it this way, but in addition we would like it to never select a built-in device.
Is there any way of finding out this information in a quite generic way? We don't know of which brands the users' laptops will be, and we don't know for sure which brands the external receivers will be.

Built-in GPS receivers are usually parts of composite WLAN/WWAN devices. Here’s how the device tree looks like when you select View / Devices by connection:
You see?
The parent of the GPS COM port is a USB composite device, that has many children, and one of those children is a network adapter. You can query that hierarchy programmatically using setup API: Get parent device And you can query device interface classes to distinguish the network adapter, check for KSCATEGORY_NETWORK and GUID_DEVINTERFACE_NET
However, this method isn’t very reliable. There’re external USB devices out there that are also GPS + WWAN. So it’s better to show the list of all GPS devices, and allow users to select the right one. And use the heuristic I’ve described above to choose the initially-selected default device.

Related

How to communicate with DJ Controller (USB hardware)

I have a DJ controller which connects to the computer via USB. It consists of a number of buttons, rotary dials (that look like potentiometers), crossfader and of course a turntable for scratching.
This controller is able to be used in popular DJ programs and works fine.
In the DJ program I am able to map the different buttons and controls on the device to software functions in the DJ program. When mapping, the names of the buttons show up in the DJ program (names such as "FX1" - not simply mapped to keyboard buttons).
I would like to create an application which is able to take input from the USB DJ controller. No fancy audio processing or anything like that, all I want to do is be able to:
Get a list of the buttons and controls available from the device
Get values from these controls instead of from the keyboard
Because the buttons, sliders etc show up in the DJ controller as named controls, this leads me to believe that this information is accessible, perhaps in a similar way to how joysticks work (though I have not actually worked with joysticks in .NET).
How does one go about communicating with such a USB device generally speaking and in particular in C#?
This all depends on what the manufacturer of the controller has made available to you, and how the device enumerates.
Assuming the device is a generic bulk device (requires a third party driver) you could potentially install your own WinUSB driver on the VID/PID for that device. Then you can interface with the device through the WinUSB API. The problem here is that you will need to know the protocol for the device - it's possible that you can get this from the manufacturer, if they are willing to let it go. The other alternative here is to sniff the bus during normal operation (using a hardware analyzer such as an Ellisys).
If the device is enumerating as an HID device then it must conform to some HID standard (such as a Mouse, Keyboard, or maybe a MIDI controller). In this case the specification would be defined already and available outside of the manufacturer. In this case you could use hidapi to open and utilize the device, the same way your DJ application would.

Query A Device Attached to USB - Windows

Well, I've looked all over the internet, and it appears that what I want to do is near impossible without writing my own driver.
I have a device attached to a USB port, and - unfortunately for this situation - it uses a USB to UART driver to emulate a serial port which streams the device output.
However, in order to validate a license for the software, I want to ensure that I know which device is attached to the USB port - not just the make and model, but (hopefully) the actual serial number. If not the serial number, at least some unique identifier.
But I'm not sure where or how to get that.
The UART Bridge has a PNPDeviceID, but that doesn't seem to change, regardless of which device is plugged into the port.
I'm working in C#, which, from what I've read, is also a limitation.
So my question is this: How can I get a unique identifier from a USB-attached device while using a UART Bridge driver in C#?
Thanks in advance.
You might try this library. There's some sample code in this MSDN question as well.
The PnpDeviceID actually is what I was looking for. It's just that the EEPROM has to be updated, which is demonstrated in one of the sample applications from Silicon Labs. The PnpDeviceID consists of the Vendor ID, Product ID, and Serial Number, all of which are customizable via the method demonstrated. The Serial Number on my particular set of devices defaults to 0001, which makes it appear that the PnpDeviceID doesn't change.
Reference here.

Selecting Camera

Is it possible to enlist all the camera's connected to the System along with their physical address?
I am not inclined to any particular language, though I prefer C#.
Thanks for help.
Since you mention C#, I'm going to assume you mean on Windows.
From Windows viewpoint, still cameras are almost completely different sorts of things from video cameras (but, interestingly enough, still cameras and scanners are almost the same).
Since you don't mention video, I'm going to also guess you mean still cameras. You normally deal with still cameras (and scanners) via Windows Image Acquisition (WIA). To list cameras, you'd normally use IStillImage::GetDeviceList. This will return a STI_DEVICE_INFORMATION structure, which includes a dwHardwareConfiguration member to tell you the type of interface used (e.g., USB) and pszPortName to identify the specific port to which the camera is attached.
If you want to trace back from that port name to something more "physical", such as the bus number and such, you should (probably) be able to use WMI_USBControllerDevice to map from the device back to the controller.
If you want to deal with video cameras, you'd use capGetDriverDescription to get a description of each video capture device that's installed. In this case, getting something closer to a "physical" address is considerably more difficult. capGetDriverDescription will give you a driver name. I suppose you can do the usual Windows "stuff" to enumerate drivers and match up names to find out something about the driver in question, but I haven't played with that to be sure (for example) which name it gives you (the internal driver name, the display name, or what).
Also note that MS has developed about a half dozen different multimedia interfaces over time, so almost any multimedia cat can be skinned at least a half dozen different ways.

What determines the order for sound devices in windows when using winmm.dll?

I am trying to use NAudio to create a multiple sound output application. We have 8 USB sound cards installed. NAudio lets me use all 8 but I can't figure out a pattern for determining which device index is which card.
The cards will be hooked up to different hardware so it is important to make sure you know which card you are using.
I have been trying to use WMI to poll for the information but I can't seem to locate any information that determines the order of the sound devices.
Update:
I forgot to include some information about this problem. The sound cards are all USB sound cards hooked up through a 12 port hub.
The order of devices is non deterministic for all versions of Windows. For Vista and above, the devices are typically ordered by the DSound GUID (more-or-less) so they're effectively random.
I'm assuming you are using WaveOut? You can call WaveOut.GetCapabilities(deviceNumber) to get hold of the name of the device, which might help you out.
This is what I have come up with so far and it works for us.
Using WMI you can get the DeviceID from Win32_SoundDevice. Then using that you can access the registery at HKLM\SYSTEM\CurrentControlSet\ENUM\'DeviceID' and get the string value named "Driver". This value contains the ClassGUID plus a number at the end.
Example: {4d36e96c-e325-11ce-bfc1-08002be10318}\0015
If you strip off that last number*(15)* for all of you sound devices and order them, that is the order that the devices are listed from NAudio with uses winmm.dll. There is also a location for these sound devices, either in the registery at the same key or from Win32_PNPEntity using the DeviceID.
In our case the location lets us determine which port of the USB hub that sound device is plugged into.
Have a look at this MSDN article. It uses DirectSound to enumerate the audio devices:
http://msdn.microsoft.com/en-us/library/bb318674(VS.85).aspx

How can I determine the speed of a USB port?

Is there an easy way to programmatically determine the speed (or version) of a USB port? I'm looking to control the speed of data sent to a usb port based its maximum bandwidth.
If you need a solution for Windows this should be a good start:
http://msdn.microsoft.com/en-us/library/ms793313.aspx
Basically you should try this:
Enumerate the USB devices and the symbolic names to their drivers
Open a handle to the USB device driver through its symbolic name via CreateFile
Perform a DeviceIoControl on the driver handle with the control code IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX. This will have you returned the structure USB_NODE_CONNECTION_INFORMATION_EX. There you have a member there called Speed of the type USB_DEVICE_SPEED.
(Close the driver handle)
This could also be interesting for you: CodeProject: Enumerate Properties of an Installed Device
To answer your question, I'm sure that there are ways of getting the information you need. I don't know the answer for windows, but Linux has files you can read within the sysfs directory structure.
Speed control is usually taken care of by the drivers and the hardware controlling the bus. Most modern USB controllers really have 2 controllers per port connected. 1 for the slower speed 12Mbps USB 1.0, and another for the higher pseed 480Mbps USB 2.0. There is a magic switch inside that connects it properly. The driver itself makes sure that everything is enumerated properly, controls the flow, etc. A higher level "user-space" application typically doesn't need to worry about these things.
Also, if you have a device that is capable of running at faster than 12Mbps, and you plug it into a 12Mbps port, it'll get dragged down to 12Mbps whether you like it or not. Is it that you want to know that is got dragged down?

Categories

Resources