Talk to an USB HID device from within GNU Octave - usb

I need to control a measurement instrument from within GNU Octave. The instrument has an USB HID interface. I just need to read or change the settings of the instrument. It's not about getting measurement data from the instrument.
What options are there to do this from within GNU Octave, and how do they work?

The simplest approach would be to use an already made Octave package (like the instrument-control package). Then you could check the documentation and read /write to and from a USB device.
The package linked above (and here again) has a USB TMC set of functions if the USB device works with this library. See the function list to find out how to use the package. As far as I am aware this package only works on Linux for USBTMC (according to the wiki).
Otherwise if you are not running Linux, or the device is not supported, I cannot specifically see any other already-written set of Octave functions for communication.
However, if you have the time it could be worth writing just a singular MEX (C/C++) function to open the communication channel and read settings from the device.
You could then make this work on Windows as well. Most of this functionality is already implemented in libraries such as signal11 (just to name one...), which that library itself is already cross-platform. Using that library inparticular makes it look like a very short MEX file to write.
I hope this helps and check out the links for further information about the topics discussed :)

Related

How to access device specific functionality in MBED?

Is there a generic way to access device specific functionality from within the MBED development stack or am I S.O.O.L and need to go to a lower level tool chain? (want to use the integrated op-amps of the STM32F303RE device)
You can just use the STM32 HAL functions like you'd normally do. Mbed OS wraps around these. Note that these functions are not guaranteed to be thread safe (unlike the Mbed HAL).

USB communication with Python (Newport Instrument)

I´m currently trying to make USB communication to the laser controler TLB 6700 (New Focus - Newport) with python.
https://www.newport.com/f/velocity-wide-&-fine-tunable-lasers
This is my first python task, and I´ve been having several troubles. So, by steps:
1) This device has its own drivers, and a comercial software to control it. However, I would like to develop my own code to perform several automation procedures.
2) The newport drivers are not NI compatible. This mean that I can not use PyVisa to recognise the device if I´m using the Newport drivers.
3) I think I can not use PyUSB too, for the same reasson. Even I´m not totally sure about that.
4) A solution that I´ve found is to use the NI-Interactive control to install a secondary NI driver for the device. Following this procedure I can recognise the device with PyUSB.
5) However, I do not understand how to activate the device and to send commands. I guess that the correct procedure is something like:
5.1: Call a library. Newport provides diferent libraries and dllwrapers. I´m asuming that the correct procedure is to use Ctypes to call the primary device dll. This will lead the possible instruction call.
5.2: Recognise the device as I´ve done with the NI driver and thorugh PyUSB.
5.3: Open the device and send command through PyUSB code.
So, here my questions:
PyVISA seems much easier to use than PyUSB. Any of you know a procedure to do the same but with PyVISA?
Any of you have done similar procedure with Newport devices, or even with the same TLB 6700 controller?
Thank you in advance,
Cheers,
It might be a bit late but just in case, I developed a python code to control a TLB 67xx. You could find it in my github.
Basically I call the dll through (UsbDllWrap) python net (import clr) and use it to set the wavelength, start a scan , etc... I do have several decorator that you could dismiss (#InOut.output for instance). You might need to adjust the path of your dll, if you do not use Anaconda for python. That is the only decent way I found to control the NewFocus laser, as it will not be possible to control them through PyVisa.
Obviously, doing so it is only possible on Windows.
I am still working on a cross platform solution that could be suitable for Linux

STM32 Embedded GUI Library porting for F4 Discovery

I'm trying to use the STM32 Embedded GUI Library with STM32F4 Discovery Board.
Has anyone already done a porting of this library on the discovery?
Otherwise, how can I try to port it and what is the "weight" in terms of work of such a porting? (I'm new in programming embedded devices)
I used Littlev Grapics Library (free, open source) on STM32 discovery. Maybe you will like it too.
http://www.gl.littlev.hu/blog/8/embedded-gui-on-stm32-discovery-board-with-littlev-graphics-library
It comes with a working project to download to STM32 Disocvery.
Maybe you want to take a look at µGFX: https://ugfx.io
It comes with a ton of optional features and built-in drivers. Your hardware setup is already supported.
You might also consider STemWin, it is already supported on STM32F4. In either case the biggest porting effort will probably be in supporting your specific display hardware.
This link will help to implement STemWin on STM32F4.. Link to blog..
It can be easily ported if the drivers for LCD and Touch are properly configured.

How can I debug a USB HID device that does not come with a driver?

I have a single button USB controller, but it did not come with any drivers (simply a Windows program that communicates with it directly for its intended purpose).
USB Fidget
Vendor ID: 0x1d34
Product ID: 0x0001
Product name: DL100A Dream Cheeky Generic Controller
So, I would like to be able to read whether or not the button is being pressed. My main development environment is Mac, but I'd like the solution to run on Windows too. So ideally a cross platform solution would be best.
I can find pieces of code for other devices by the same manufacturer but there are differences in Product ID so the code does not work and I lack understanding to change anything other than the vendor/product.
As far as I understand it I need to poll the USB device with a feature request packet?
Is there some software I can use to "watch" the USB device so I can see what is actually happening when I press the button? If not, how would I go about writing some myself?
basically on MacOs very huge amount of usb devices work through IOUserClient. This standart class provide to user mode programs ability to control device without kernel mode driver (by using usermode part of IOKit framework). To sniff for usb packets you can use USB Prober, start from this article http://developer.apple.com/library/mac/#qa/qa1370/_index.html
On windows standart way - standart USB driver + standart HID driver, no need in specific vendor driver if they not develop some additional functionality over standart. You can use any of commercial or freeware tools to sniff usb packets - like this one http://www.hhdsoftware.com/usb-monitor
I don't know of any cross platform way to handle it. This is the presentation I point people to for how to create a driver app for a random piece of HID hardware:
https://developer.apple.com/videos/wwdc/2011/?id=207
For testing / accessing HID devices, i.e.
Get Feature Report (matt's original question)
Sending Feature Reports
Sending Output Reports
Receiving Input reports
I'd suggest the "HIDAPI Test Tool" / "testgui" included in the great cross-platform HID library from signal11/hidapi.
On Windows you require an additional 3rd party package to compile the testgui application, but it was pretty easy and the GUI tool was more straightforward that other code examples and tools I saw. (I could cross-check if I am maybe allowed to publish a VS2008 compiled version of this.)
Another free option for sending output reports and receiving input reports, is our own "Docklight" tool (in evaluation mode, unlimited time, just no storing), see Docklight Scripting HID USB.

Making my own application for my USB MIDI device

I want to try and make my own application for my Novation Nocturn, which is a USB DJ controller surface. The application software interacts with it to send out MIDI messages to software like Traktor, Ableton and Cubase.
I'm aware of libusb, but that's as far as I've got. I've successfully installed it to interact with my device but stopped there.
I'm after some suitable reading material basically. USB specs, MIDI specs and such. If I'm honest the full USB 2.0 spec looks like it holds loads of stuff I don't need.
Just looking for something interesting to do now that I've finished my degree (Computer Science). My current programming knowledge is C++ and mainly C#.
Could do with some direction on how to get stuck into this task.
edit:
Update to include some info from the Device Manager on the Nocturn.
Hardware IDs:
USB\VID_1235&PID_000A&REV_0009
USB\VID_1235&PID_000A
Compatible IDs:
USB\Class_FF&SubClass_00&Prot_00
USB\Class_FF&SubClass_00
USB\Class_FF
Device Class:
MEDIA
USB MIDI is probably one abstraction layer lower than you want to deal with. I'd suggest finding a good MIDI framework and interacting with the device via MIDI instead.
For C++, Juce is probably the way to go, as you didn't mention a target platform or any other specific requirements.
If you want to go the .NET route, the easiest way to get started is with the C# MIDI Toolkit code:
http://www.codeproject.com/KB/audio-video/MIDIToolkit.aspx
In there, you'll find all the basics for opening an device, reading input, and writing output. Alternatively, NAudio has some MIDI classes, but they are somewhat incomplete.
As you develop, you'll want a reference for the MIDI spec handy.
A tool that you will find invaluable is MIDI-OX. In fact, I suggest that before you start coding, you fire up MIDI-OX and use it to sniff the messages coming from the Novation. It will give you a good idea of what the Novation sends. You can use it in conjunction with MIDI Yoke (a configurable virtual MIDI port) to insert itself between the Novation, and Ableton Live (or whatever software you normally use with your Novation) so you can see all of the messages in normal use.
Done... Kidding, but I've started on this in Python - I personally want linux support. I am teaching myself python, but I only dabble in programming.
You can see basic functionality at https://github.com/dewert/nocturn-linux-midi. The guy who reverse engineered it (i.e. the leap I wouldn't have been able to make myself) doesn't seem to be doing any more with it. His code is at https://github.com/timoahummel/nocturn-game
I am using PyPortMIDI and PyUSB, both of which I believe are wrappers for the C equivalents. I think this is all ok on Windows, but haven't tried.
What is currently on my github is crap, but it is proof-of-concept. I'm working on doing it properly now, with threading and proper configuration options.
The driver for the Nocturn makes it appear to system as a MIDI device, even though it isn't a USB MIDI device at the hardware level. The Automap software works entirely at the MIDI level, receiving MIDI instructions and sending different instructions in response - it is separate from the driver and not neccesary.
Alternatively, look at https://github.com/timoahummel/nocturn-game for an example of talking to it directly over USB from Python. You can probably port this to another language with libusb bindings.
Old thread, but I've just recently started looking into this.
I had a look at the Python application that dewert has written. Interestingly, it turns out that the data that the Nocturn emits is in fact MIDI, although it doesn't register itself as a USB MIDI device.
But looking at the actual data coming from the device, it actually emits control change messages (0xB0 controller value) for everything. Also the control commands that are sent to it are also control change messages, albeit only the data bytes, as the Nocturn seems to support MIDI running status (i.e. when sending multiple control change messages, it is not necessary to repeat the data byte).
Indeed, the looking at the magical initialization data it is actually just a bunch of control changes: it starts with 0xb0 and from there on the data comes in twos. For instance the last two bytes in the init string are 0x7f 0x00 which simply turn off the LED for the rightmost forward button. (There is something subtle happening as a result of the initialization being sent though, as the Nocturn sometimes emits some messages which appear to be some form of timeout events, and that behavior changes depending on whether the initialization string has been sent or not.)
Using MIDI-like messages makes sense, as Novation would be well aware of the MIDI protocol, so it would be easiest for them to use it for the communication even if the device is not strictly a MIDI device.
Note though that the incrementors just send the values 1 or 127, i.e. +1 or -1 step, so even with some trivial mapping software it's not really useful as it is. (Actually, if turned quickly, one can get 3 or 125 for instance, with the 125 corresponding to -3.) The only controller which sends a continuous value is the slider, which emits an 8 bit value when moved.
I suppose you'll want to know about USB classes in general and USB MIDI class in particular. The latter is the best what you can hope for in case you don't posess documentation for some proprietary protocol (whether it's used there instead).