How to communicate with DJ Controller (USB hardware) - c#

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.

Related

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

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.

Interfacing with TomTom device (Display devices screen on computer)

Just a quick one, if anyone knows:
Is it possible to display a TomTom devices screen on a computer (so I can interface with it's navigation ability?)
They have an SDK, however that does not have any useful information on this question, but TomTom Home can do it - so can I? C# / C++ / Whatever.
Cheers
TomTom is running linux so you can get the raw image data from /dev/raw.
cat /dev/fb > /mnt/sdcard/screenshot.raw
on the device should do it
Then you need to transfer it to your computer (needs to be done quickly).
This should be possible to do over Bluetooth, over USB or possibly by using a Eye-Fi SD card.
I don't think it is possible to do it any other way.
Access the device by Bluetooth console

Expose my program to other programs

I'm messing with the idea of writing a small program to mirror output of a video capture device. If you buy a video capture device you can only use it with one program at a time because the device gets locked. Instead of buying a second capture card id like to write a program to accept input from my capture device and expose the output to other applications.
Capture Device----->Program---->Flash Media Encoder
I've never done this type of thing before. Is it device driver related? Can I make my program look like a capture device to other programs without digging in device driver dev?
If someone could point me in the right direction that would be great.
Can I make my program look like a capture device to other programs without digging in device driver dev?
-No, I'm afraid not. You'd need to do exactly that, write a driver or capture source of your own. You could make some interface to serve up image to multiple apps (what a great idea!) but then it would need to be standardised, and you'd need other companies or developers to use that interface. Again a great idea but you'd need to agree on the feature set - and each developer would likely want something new or different.
(If you are talking about particular/specific other programs, they might have a particular interface you can work with already..)
(I was also assuming you were talking about realtime video capture: if you're talking about photo capture etc, you could write an image file to disk, and then import into the other apps ... not as joined up or integrated as ideal though)
Hope that helps - not an ideal situation though!
I will not say it is impossible, but I will say it is impossible in C# because this will require you to write a device driver software which can emulate virtual capture devices which your other program can use and your program can capture actual capture device and mirror or split the data to virtual capture devices that your device driver will create.
Very much same to Virtual CD Rom Drives that we can create with some software, you will need windows device driver kit for that.
You can write combination of application, one device driver and you can have some sort of C# api or program to control the operation.

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?

Controlling power to PCMCIA slot/card

I'm currently working on a project that utilizes a proprietary PCMCIA radio card to communicate with some wireless devices. I currently have a background process that handles reading data to and from the card and storing it for processing, but I'd like to be able to shut down power to the card when my application is not running. I've done some investigating, and while WMI evidently does support the CIM_PCMCIAController profile in its WIN32_PCMCIAController implementation, the SetPowerState() and Reset() functions are not implemented. Does anyone know of a way (with or without WMI) to control the power state of the slot? I need to be able to programatically both power off and power on either the slot or the card.
Edit
Several people I've spoken to have suggested adding a function to the card that would facilitate this. Unfortunately modifying the card to provide this sort of functionality really isn't an option right now.
Edit 2
I've confirmed that the device does show up in the Device Manager under the "Multifunction adapters" category, though neither disabling the device nor the PCMCIA controller itself from here has any effect on the power of the card.
Presumably, the device has it's own drivers of some sort and shows-up in Device Manager.
In which case, you could disable the device by calling devcon (Command-line equivalent of Device Manager), from inside your program. This would make windows handle shutting down the device.
devcon disable. See Example #31 for an example of how to shutdown device by a specific device id.
Am I going on the right-lines, or have I misinterpreted your question?
I'm curious, but does using the "Safely remove hardware..." button turn off the power to the device, enough to satisfy your requirement?
If that works, you could programatically register and unregister the device through Microsoft's API. Here is a page that shows a couple functions that might be helpful for this scenario: http://msdn.microsoft.com/en-us/library/aa363234(VS.85).aspx

Categories

Resources